Your Own Twitter Bot
This page provides you with everything you need to effortlessly build and release a new Twitter bot to the world.
After this quick intro, I provide you with links to background articles on the Twitter bot framework, including one presentation of it.
Features
As of version 0.1.2, the micro-blog bot framework can operate on Twitter and any Twitter compatible micro-blogging service, such s Identi.ca. It handles what’s likely going to be common amongst bots on any such service:
- automated reciprocal following (friending, defriending)
- a common basic command set (about, help, shutdown),
- easily extensible command set and processing,
- processing of received messages,
- threading of replies.
The bot framework is implemented in Ruby.
Quick Intro
Step 1: Get the most up-to-date Twitter bot framework.
Go to the repository. Download the most recent version as a tarball. Unpack the tarball somewhere you want to develop your Twitter compatible bot in.
From here on, in the text body, I refer to it as mb-chatbot since that is what you actually get: a general micro-blogging services compatible chatbot framework. That includes Identi.ca and others, not only Twitter itself.
Step 2: Get the latest gems the Twitter bot framework is built atop.
Get twitter, get echoe.
$ sudo gem install twitter echoe
If you are on Debian, you would need the ruby-dev package also.
If it’s v0.4.1 of the twitter gem you get — it’s flawed. The mb-chatbot’s README file has a short & sharp howto to fix those flaws. As it’s probably irrelevant for any more recent version of the twitter gem we skip that here.
Step 3: Get an account for your bot at Twitter or Identi.ca
I suggest to try the bot framework on Identi.ca rather than on Twitter itself as there are restrictions built in to Twitter that look pretty eager to blacklist your IP once you cause too much traffic in a noticable short time. That will make the framework look like being at fault, though it is not. Identi.ca, on the other hand, to my knowledge, currently does not have any such restrictions.
To get the account, visit Twitter or Identi.ca (or anything compatible) and sign up for it. Do so like you’d do if you would be a usual human user. There may be CAPTCHAs involved, hence it is necessary you do it manually.
Step 4: Ready your bot
You do so by filling in the login data to a yaml file. Copy config/credentials/twitterbot.yaml to config/credentials/my-bot.yaml. Insert the login data to the appropriate username/password fields, and select the service to use, Twitter or Identi.ca. — The README file provides quality information on how to ready your bot for any other compatible micro-blogging service.
Step 5: Launch the demo bot
$ ruby micro_blog_bot.rb
Step 6: Build your own flavour of bot
To do so, open a new file, template it with
main_dir = File.join(File.dirname(__FILE__), '') require (main_dir + 'micro_blog_bot') class MyBot < MicroBlogBot ... end
Essentially, you are now ready to reuse what MicroBlogBot already provides and overwrite it where you’d need alternative functionality. Mainly this will be the answer_message method to be overwritten, or the @bot_commands hash to be extended.
Background articles on the Twitter bot framework
These are some other postings on the micro-blog bot framework I released to my blog:
Any hope for artists/writers who can do a little coding (HTML/CSS, JavaScript, AIML) and a lot of natural-language scriptwriting? Anything as easy to use as Pandorabots?
Websafe Studio
March 17, 2009
Hi,
I take this comment of you and your previous one as two facets of the same story. For that, here’s my bundled answer:
Natural language like chat bots are a storey above what the mb-chatbot framework is for. Personally, I have no ambitions to implement any logic for the framework that is beyond handling of incoming requests (“tweets”) and reply to them. — Handling in a technical manner, not by any ways of content.
But, of course, the source of the mb-chatbot framework is free (LGPL), so you or anyone else who likes is free to pick it up and develop whatever specialized chat bot atop of it he or she wants and likes to implement.
dagobart
March 23, 2009
Just so you know, it looks like 0.1.2 is broken out of the box when using a recent version of the Twitter gem. When I installed it using Twitter version 0.6.12, there were a number of interfaces that were broken. I have some patches to fix things, and I’m happy to help…
Dave
David Sifry
July 20, 2009
David, you’re welcome to help and throw in the patches you have.
dagobart
July 24, 2009
Hey, cool! Wusste gar nicht, dass du sowas kannst. Hätten schon ein paar nerdige Gespräche vom Zaun brechen können. Nach meiner Klausur werde ich das Ganze mal ausprobieren. Grüße
pao
August 2, 2009
pao, sure. David put a lot effort into bringing the bot to the next level, and I am currently working to refactor the messaging system. Actually, I am working on a silent bot by that…
See you at Marcel’s party.
dagobart
August 2, 2009