hmmm… (life, programming and everything)

I’M Assistant

with one comment

For a long time, I was trying to avoid the temptation to start my old/left out project. Recently, something led me to bring my old project back from grave. First of all, what is this I’M Assistant ? Well, it all started off with adding Twitter@Twitter.com to my gtalk friends list. For those who don’t know what it is here is a gist. You startoff with adding it to your gtalk list as you add any other friend of yours. Technically its a bot that accepts some commands from you and processes it. So you can do simple stuff like posting a new tweet at twitter, following a person, getting tweet updates from your friends and a few other commands. I got terribly inspired by that.. and I started writing my own bot that does some simple tasks. It worked right away. Thanks to python/xmpppy which made things easy. Then I started to develop a simple framework so that it can be extended by anyone.

Having said all this.. how does one create a new bot and include it into the existing framework. Actually it is simple. All the hard job of creating a connection, getting the message are all done by the framework. The framework works like this.

  • A config file contains the gmail id/password on which this bot will listen.
  • The config file will also contain the list of active bots (more on this)
  • Running the startup.py starts the application and listens for incoming messages

With this setup up and running, lets take a very simple example. Assume we have a bot that acts like an echo command. You give the bot a message it will give it back to you. Since there has to be a way to tell as to which bot the message should go, I decided to include this as the first word in the incoming message. So, when the message “echo hello world” (quotes for clarity) comes to the BotManager (the class that manages all the active bots) it strips off the first word (‘echo’) and finds out the bot that is responsible for handling this message. On finding one, it takes the rest of the message and sends it to the concerned bot. The way the bot processes the message is left to the person who created the bot. Along with the message, the bot is also notified as who the sender is and is also given a handle to send the response to the sender. Once the bot has finished processing, it sends the response back to the sender.

Now, all you have to do for creating new bots is to inherit a base class called ‘Bot’ and implement a method called ‘process’. Rest all is taken care by the framework. Once the bot is written, you can add that to the active bots list by giving an nickname for the bot along with its fully qualified python name in the config.ini file. This nickname is used for matching by the ‘BotManager’ for identifying which message should go to which bot.

I wrote a java version too. But it is inactive for now. Last night, I revived my python code, dusted it and then restarted by writing a twitter bot. I wrote a simple bot using python-twitter and it worked like charm. The first thing I did was to push it into my existing git repositories in gitorious. You can see the mainline branch here.

Feel free to clone a repository and start creating bots. I intend to create more bots.

More updates coming..

:-)

Written by karthik3186

June 20, 2008 at 12:26 am

One Response

Subscribe to comments with RSS.

  1. This looks cool. Great work in thinking meta and creating a framework.

    W

    June 20, 2008 at 7:09 pm


Leave a Reply