Setting up Hubot with a gTalk account for fun
This article should be called like something like “Be happy: put a robot in your life”, deep down in order to represent better what I will explain here I’ve changed the title to a more technical point of view.
Since I’ve started to work in Openhost I always thought that for creating a good product our developers (and me between them) should have a great atmosphere, in order to do that I would rather have a pleasant workflow than a strict one. So I’m a firmly believer of Gamification of work. We were using Jenkins for doing Continuous integration and quickly integrated the Jenkins Continuous Integration Game, a tool which allowed us to create contests for improving our code base without even thinking about it, just thinking on getting a high rate in the contests. But, this is something to another post.
As we are continuously telecommuting, we use groupware chats as our main way of communication. This week I came across to something called Hubot, it’s some sort of chat bot with incredible scriptable capabilities. In a brief description, it is a program that can connect to your groupware chat and it can accept orders, run them in the server and get some response to them in return.
Installation
The installation of Hubot is quite simple. As Hubot is based in node.js, you have to install it in your system. After that you can create your custom bot from the prebuilt template.
sudo apt-get install nodejs
git clone git://github.com/github/hubot.git && cd hubot
hubot --create ../your-bot-folder
cd ../your-bot-folder/ && npm install
You can start playing with hubot by running the next command and send it orders:
$ ./bin/hubot
[...]
Hubot > hubot help
Connecting Hubot to Gtalk chatrooms
By default Hubot has no support to use a Gtalk account, but you can install a custom adapter to do it by adding the proper dependency to the packages.json file:
"dependencies": {
[...]
"hubot-xmpp": ">= 0.0.1",
[...]
},
You might ask why am I using the XMPP adapter when I can just use the hubot-gtalk adapter. The reason is because I didn’t find a way to connect hubot to a groupware chat by using the gtalk adapter. Given that XMPP and Gtalk are the same, but XMPP is more generic, you can connect to your Gtalk account by using this adapter with a little more configuration.
Talking about configurations, Hubot uses environment variables to get its configurations. So if you want hubot to use a Gtalk connection you must export those variables by filling the gaps of the next example right before running your bot:
export HUBOT_XMPP_USERNAME="your.account@gmailcom"
export HUBOT_XMPP_PASSWORD="your-gtalk-password"
export HUBOT_XMPP_ROOMS="[email protected]"
export HUBOT_XMPP_HOST="talk.google.com"
export HUBOT_XMPP_PORT="5222"```
After that you can start the Hubot bot by issuing the next command:
```./bin/hubot -a xmpp -n bender
Extending Hubot
As I said before, Hubot has a quite good extendability by what’s called scripts. Scripts are commonly written in CoffeScript, a hipervitaminate subset language that complies to JavaScript, and there a lot of scripts already available in the Net™. They do a lot of things, from answering questions like Bender, from Futurama, to echoing quotes from Star Wars, Homer Simpsons, or it can do something more useful like translating strings by using Google Translate, linking to Google Hangouts, shorting links with bit.ly, and something a little more serious like interacting with the Jira or Jenkins APIs. Check the links from below to find all of them:
Here is our bender bot
Future findings
I’m trying to find a cheap node.js hosting for running this bot. I’ll try to explain soon what my findings are.