Want to stay on top? Ruby Weekly is a once-weekly e-mail newsletter covering the latest Ruby and Rails news.
     Feed Icon

Twibot: A Ruby Microframework for Building Twitter Bots

By Peter Cooper / March 16, 2009

twitter.pngTwibot is a Sinatra-esque "micro framework" for building Twitter bots (somewhat like Isaac is for IRC).

If you're not familiar with Twitter, it's a lifestreaming-meets-microblogging type service with a few million users who constantly post about what they're doing or experiencing (I find it's very much an acquired taste and makes little positive sense to anyone until they've used it a while, alas - a bit like beer or driving stick shift). If you want to learn more, Wikipedia has a good summary.

As well as individuals, there are a lot of automated services on Twitter, pumping out content from feeds, responding to people automatically, monitoring what people are saying, and so forth, and Twibot provides a great mechanism for you to more easily develop such services yourself.

Even though Twibot is installable as a gem, it relies on an edge version of Susan Potter's twitter4r, which you will need to grab from its Github repository. Once installed, however, Twibot will let you write stuff like this:

require 'twibot'

# Receive messages, and tweet them publicly
message do |message, params|
  post_tweet message
end

# Respond to @replies if they come from the right crowd
reply :from => [:cjno, :irbno] do |message, params|
  post_tweet "@#{message.sender.screen_name} I agree"
end

# Listen in and log public tweets
tweet do |message, params|
  MyApp.log_tweet(message)
end

Do you use Twitter? If so, you can follow Ruby Inside at @RubyInside.

Other Posts to Enjoy

Twitter Mentions