Your first HipChat bot
Posted by Chris | 0 CommentsA few weeks ago I stumbled upon a promising new startup while searching for a hosted group chat solution.
Besides being feature-rich and easy to use, HipChat allows you to write your own client by exposing an XMPP entry-point.
If you have never heard of XMPP it is a common chat protocol used by services such as Google Talk and Facebook Chat.
wobot
wobot is my attempt at abstracting the XMPP protocol in Node.js and offering a simple API to write your own bot.

Installing wobot
To get started you will need a few things:
- Node.js (http://nodejs.org/#download)
- npm (http://npmjs.org)
Additionally, wobot depends on the node-xmpp module which requires the following:
- libexpat1-dev:
apt-get install libexpat1-dev - libicu-dev:
apt-get install libicu-dev
Once you have installed the build dependencies, install wobot in your working directory using npm:
mkdir ~/mybot
cd ~/mybot
npm install wobot
Configurations
Once wobot is installed you will need to add a new member to your HipChat group and login as that member.
Under "My Account" > "XMPP/Jabber Info" you will find the following:

Instantiate the wobot.Bot class as follows:
var wobot = require('wobot');
var bot = new wobot.Bot({
jid: '1234_12345@chat.hipchat.com/bot',
password: 'yourpassword',
name: 'XMPP Bot'
});
bot.connect();
After running the above script, you should see your bot in HipChat's Lobby.
Auto-joining on connect
Once the bot is connected you will likely want it to join one or many channels. This can be done as follows:
bot.on('connect', function() {
this.join('1234_bot_testing@conf.hipchat.com');
});
Reacting to a message
Whenever a message is sent to a channel your bot is in, the message event will be emitted.
Here is a simple example of a echo bot:
bot.on('message', function(channel, from, msg) {
if (from === this.name) return false;
this.message(channel, '@' + from + ' you just said: ' + msg);
});

Conclusion
The goal of this article was to briefly introduce wobot.
There are many more examples and detailed documentation on GitHub.
-Christian Joudrey