Over a million developers have joined DZone.

Installing And Running Hubot - A Bot for Automation and Fun!

DZone 's Guide to

Installing And Running Hubot - A Bot for Automation and Fun!

· DevOps Zone ·
Free Resource

In this post we are going to learn how to install hubot and make it work over XMPP protocol (using an openfire server).  We'll also see how it can help us in our daily work.

GitHub, Inc., wrote the first version of Hubot to automate our company chat room. Hubot knew how to deploy the site, automate a lot of tasks, and be a source of fun in the company.  -- Github

Hubot is a robot which belongs to your chat infrastructure as one more user that you can talk to. Hubot can help you automate a lot of tasks, like deploying a site, managing your Pomodoro, or managing an issue tracking system. Hubot is written in CoffeScript on Node.js, so keep in mind that Hubot can be extended with CoffeScript easily.  In fact, the real fun happens when you add your own scripts.

This post is written using Ubuntu, so if you are using any other OS, you only have to modify the way components are installed.

First of all (I assume you have a JVM installed), you must install npm and node.js. For this I have used apt-get.
sudo apt-get install nodejs npm
Next you'l install Hubot dependencies by running the next apt-get command.
apt-get install build-essential libssl-dev git-core redis-server libexpat1-dev
Then we need to install CoffeScript. So we can run the next command:
npm install -g coffee-script
And finally we are going to install Hubot in /opt directory. Obviously, it could be any other one.
cd /opt
git clone git://github.com/github/hubot.git && cd hubot
npm install
Hubot is installed! To see if it works, simply run it from the installation directory:
alex@grumpy:/opt/hubot$ ./bin/hubot
and Hubot shell will start. This shell is really useful for testing purposes but not for production environments.
Hubot> hubot ping
Hubot> PONG
This will produce a Pong message.

Now it is time to install Openfire server so we can communicate with Hubot using the XMPP protocol instead of shell. Of course you could choose any other XMPP server, but for now I'm using Openfire.

To install it, download it from openfire's site, and extract it to /opt directory.
tar -xzvf openfire_<version>.tar.gz
mv openfire /opt
Now it is time to configure the Openfire server. We are going to use an embedded database but of course you can configure an external database such as MySQL or Oracle.

A web-based wizard driven setup and configuration tool is built in Openfire, so let's start Openfire server for the first time and configure typical parameters like administrator username, server name, ...
$OPENFIRE_HOME/bin/openfire start
and access to http://localhost:9090.

Then log in as an admin and then create the first two users, developer and hubot. So go to  Users/Groups -> Create New User, and fill in the required information for both users.

Next, you'll create a room where all users that want to interact with Hubot will join. So go to  Group Chat -> Create New Room and create a new room. In our case we are going to call it hubot.

and finally we must disable TLS security, there is an issue between Openfire TLS version and node.js XMPP module so if you are using Openfire, you should disable it.

The next step is to check that the developer user has access to the hubot chatroom and check that the account is correctly configured.  We can open our XMPP client (in our case Spark) but it should work with any other one and then verify that we can connect.

If you are using Spark, log in with the developer account and in the Actions menu you will find the Join Conference room option. Now choose the previously created room ( hubot) and confirm that you have configured the XMPP part correctly. 

Now it is time for Hubot. First of all we are going to create a bot called my-bot:
alex@grumpy:/opt/hubot$ ./bin/hubot -c ./my-bot
Then enter the my-bot directory and open package.json and add the next dependencies which will configure the adapter so Hubot can use the XMPP protocol for communication:
"dependencies": {
    "hubot": "2.3.2",
    "hubot-scripts": ">= 2.1.0",
    "optparse": "1.0.3",
    "node-xmpp": "0.3.2",
    "hubot-xmpp": "0.1.0",
    "htmlparser": "1.7.6",
    "soupselect": "0.2.0",
    "underscore": "1.3.3",
    "underscore.string": "2.2.0rc"
Then before starting Hubot, you must install the XMPP adapter. Run npm install from the hubot directory, and an XMPP extension will be installed into hubot.
alex@grumpy:/opt/hubot/my-bot$ npm install
And now we are ready to start using Hubot and Openfire.

We are going to start by adding environment variables to configure the XMPP adapter.
export HUBOT_XMPP_USERNAME=hubot@grumpy
export HUBOT_XMPP_PASSWORD=<password>
export HUBOT_XMPP_ROOMS=hubot
Note that a username should accompany yourr server name which in my case is  grumpy. And finally it is time to start Hubot.
alex@grumpy:/opt/hubot/my-bot$ ./bin/hubot --adapter xmpp
You will see your new friend in Spark (if you have already added hubot as a friend).

And after you check that we can go to hubot-scripts to download and install the useful ones depending on our environment.

In this video you can see a screencast of Hubot In Action with some scripts that I use.

I hope you like Hubot!


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}