Scott Walsh is a software developer living in London.

Hubot: an open source chat bot

23 Apr 2014

At GitHub they have a concept they call chatops. This is the idea that all tooling should be driven by conversations in chatrooms.

Everybody interacts with tools through a chatroom and because everyone has been in a chatroom before, everyone knows how to use the tools or has the opportunity to learn by watching other people use them. By having what is essentially a shared command line and a shared space for people to work you promote collaboration and learning by example.

Another benefit of using a chatroom is that you can see the full history of conversation which means you have an excellent audit trail of everything that has been said and done all in one place with no extra effort. You can imagine this being incredibly useful in an emergency as you see nagios alerts going off, and everyone is able to see the steps taken in response to the problem. This leads overall to increased awareness and visibility of what everyone is working on, and how they're doing it.

Can you say the same about your current infrastructure? Important information about the goings-on of your system may be scattered over multiple physical machines and in multiple places on those machines, from configuration files in source control, to database queries, to xml files, to who can even remember where else.

Enter Hubot. Hubot is an open source chat bot created and used by GitHub that sits in your chatroom, listens for commands and executes them.

Hubot is written in CoffeeScript and built on node.js, and it stores data in it's robot 'brain' in redis. It's open source, free of charge and because of it's pluggable architecture it's easy to build into your current infrastructure.

It has the concept of adapters which allow us to connect Hubot to a chat protocol so we can interact with it.

These are written in CoffeeScript but you probably won't have to bother writing one because there's an adapter already available for most popular chat protocols (irc, xmpp, Skype, hipchat, Gtalk, iMessage, QQ, AIM and many more). Hubot comes with a couple of adapters out of the box; a shell adapter I've been using for local debugging and one for campfire, which they use at GitHub.

Most importantly you can extend Hubot’s functionality by adding scripts. Each script is executed by a command in chat and allows parameters to be passed to it. A good place to start once you've got Hubot up and running is by using the help script which returns a list of commands, you can filter it's results by specifying a third parameter:

hubot help search

Hubot scripts are also written in CoffeeScript, though you can write them in vanilla JavaScript if you're that way inclined. There are plenty of open source scripts out there already (there are two official script repositories, one at GitHub and the other hosted on heroku) and these can be used for guidance when writing your own.

Anyone can create one of these modules and load it into Hubot. There are a few guidelines in the documentation and also a half decent book that should help you with debugging or to create basic scripts - whether that's letting you know that your build failed or ordering pizza with a single command.

You can probably think of a few other places Hubot could improve your day-to-day workflow. Especially as you can use this anywhere you have access to a instant messaging client; in the office, in a meeting room, on your mobile phone, or on a plane.

There are scripts for graylog, graphite, nagios, fogbugz, git and many other popular tools. An authorisation script allows you to restrict commands to certain users, or roles. There are useful scripts to tell you the weather, public transport status, and give you reminders. And there are fun scripts to show you pictures of pugs.

All in all, I think there's a lot of value in having all of this information in one place, especially one which is a natural part of your workflow.

If you've ever asked questions like, "Has that service been deployed yet?" or, "Has anyone turned off the nagios alerts?" or, "Is the release complete?" or, "What version of this software is deployed to our testing environment?" you'll be able to see the benefit in having all of this information in one place - inside a single chat window.

Take a look at the hubot scripts I created to interact with some of the tools and propriety web services I use regularly.