Introducing Chatterbot, a ruby library for producing bots.


Setting up a Bot

Make a Twitter Account

First thing you'll need to do is create an account for your bot on Twitter. That's the easy part.

Install Chatterbot

gem install chatterbot should do the trick.

Run the Generator

Chatterbot comes with a script named chatterbot-register which will handle two tasks – it will authorize your bot with Twitter and it will generate a skeleton script, which you use to implement your actual bot.

Write your bot

Chatterbot has a very simple DSL inspired by Sinatra and Twibot, an earlier Twitter bot framework. Here's an example, based on @dr_rumack, an actual bot running on Twitter:

    require 'chatterbot/dsl'
    search("'surely you must be joking'") do |tweet|
      reply "@#{tweet_user(tweet)} I am serious, and don't call me Shirley!", tweet

Or, you can create a bot object yourself, extend it if needed, and use it like so:

   bot ="'surely you must be joking'") do |tweet|
     bot.reply "@#{tweet_user(tweet)} I am serious, and don't call me Shirley!", tweet

That's it!

Bots in Action

You can check out the bots I've written on my Twitter Bot page, and there's a bunch of relevant stuff tagged as 'twitter' on muffinlabs.

A Note About Being an Asshole

I am a big fan of the WTFPL - Do What The Fuck You Want To Public License. I decided to release chatterbot under the WTFPL, but with one alteration. I really don't want people to use this code for evil. Spamming people on Twitter is not okay. However, this code could definitely be used to aid spamming. So, I've invented the WTFDBAL. It's pretty simple – do whatever you want with the code, but don't be an asshole:

Is that enforceable? I assume not. But if you even have to ask the question, then you're probably doing something wrong.

Got questions? Did I document something poorly? Contact me here or on Github and I'll see what I can do about that.