« PHP Weekly Webcomic hosting survey »

hippybot - Hipchat bot written in Python

1v$ date
1v$ Tue Sep 13 15:17:08 GMT 2011

I recently had a reason to try out Hipchat, being a bit of a "chat enthusiast" (I was an IRC network admin for about 7 years and have a been developer on a few web chat and IM systems) I found Hipchat to be one of the nicest (that I've used) of the recent stream of "IRC for the web" products out there (for example 37 Signal's Campfire).

Normally this would have been the end of my quick perusal, until the next time I had reason to the use the service, but I noticed they had not only an API, but also Jabber/XMPP exposure for creating bots. Now my interest was piqued.
Looking at the existing third-party bots out there I found you had your choice of languages…as long as that choice was Ruby or Javascript. ;-)

Now I'm not averse to developing in either, but they're not my preferred languages by far (okay Javascript has a soft spot in my heart but I still haven't made the jump to server-side JS dev).

So with that I present hippybot
(Hipchat Python Bot, geddit?)
Not to be confused with Hippy, a PHP library for the Hipchat API.

I wrote hippybot using the excellent python-jabberbot, a library that utilises the equally brilliant xmpppy to allow the creation of bots in an easy to understand and pythonic way (e.g. inherit from base class, set some connection strings, override event methods if need be, use decorators to extend commands the bot responds to).

How is this different from a regular Jabber bot? I've written some Hipchat-specific customisations into the bot:

  • The connection config assumes Hipchat's XMPP server, and various details such as the username and channel names have Hipchat specific [pre/suf]fixes added to them automatically.
  • The bot "understands" at-sign mentions (e.g. those popularised by Twitter and supported by Hipchat for directing messages to specific people within rooms, as well as triggering notifications), and commands added by plugins can leverage this.

I've added a simple plugin API to the bot, which consists of either creating a function in a module with a decorator, or a class in a module with as many decorated methods (each a different command to trigger the bot) as you like, and the ability to create aliases for commands and define whether a command is triggered by an at-sign mention or not (e.g. @hippybot do something!).

In the next release I plan to add a simple wrapper to Hipchat's API (already in master), better at-sign mention handling, and some more core plugins.

Feel free to check it out and for an example of the sorts of things you can do with a bot like this just check out some of the things Github's hubot does.


blog comments powered by Disqus