This is the first out of three posts where I will explain how we hooked up Hubot to Github’s API. The goal of this is to get notified in Slack when your pull request becomes unmergeable.

A Springest Hackday idea

At Springest we hold regular hackdays. The purpose of these days is to learn, have fun together and work on something that is related to Springest, but isn’t part of our daily work-routine. It can be anything from hanging a swing in the office to building the company’s internal Facebook app called Sputr.

Starting the day, we all share our ideas during stand-up and we get to work. Either solo or in a team.

‘Get slack notifications when a pull request becomes unmergeable’ was one of the ideas on our hackday-list that I thought was interesting to work on.

In this post, I’ll explain how to run Hubot locally in Slack, so you can test-drive your code.

So what is Hubot, anyway?

Hubot is a chat bot by Github. It is open source and written in CoffeeScript and Node.js. You can automate processes with Hubot through scripts, or just add some flavor to your team’s culture. At Springest, our bot is called ‘Ingrid’. She notifies us about all sorts of things that happen on the Springest website and we can tell her to do stuff for us, like deploying, share support ticket info or give someone karma. All by messaging in Slack.

Slack is a messaging app for teams. Messaging is categorized in channels that everyone is free to follow or not. It enables us to easily communicate with each other.

To install Hubot, you need to follow these instructions:

Node.js and npm

Open your console and check if you have installed node.js and npm:

  $ node -v
  # should output node.js version
  $ npm -v
  # should output npm version

Node.js is a server-side JavaScript environment and npm is a package manager for node programs.

If nothing exists, install node.js by downloading it here. This will also install npm.

Make sure you have the latest version of npm installed, by running:

  $ npm install npm -g

If you have never installed hubot before, you need to install its generator. Otherwise you can skip this step.

  $ npm install -g yo generator-hubot

Let’s run it!

Now that you have the generator, add a directory for your bot and create it. I asked my six-year-old son what name he would give a robot, if he would have one. He said ‘Stone’ because robots are hard like stone. So I called it Stone for this example, no questions asked.

Create your bot (just hit ‘enter’ for all questions) :

  $ mkdir stone
  $ cd stone
  $ yo hubot

  ? Owner irisbune <>
  ? Bot name stone
  ? Description A simple helpful robot for your Company
  ? Bot adapter campfire
     create bin/hubot
     create bin/hubot.cmd
     create Procfile
     create external-scripts.json
     create hubot-scripts.json
     create .gitignore
     create package.json
     create scripts/
     create .editorconfig
   _____              /                             \
   \    \             |   Self-replication process   |
   |    |    _____    |          complete...         |
   |__\\|   /_____\   \     Good luck with that.    /
     |//+  |[^_/\_]|   /----------------------------
    |   | _|___@@__|__
    +===+/  ///     \_\
     | |_\ /// HUBOT/\\
     |___/\//      /  \\
           \      /   +---+
            \____/    |   |
             | //|    +===+
              \//      |xx|

  loadDep:mime-db → request ▄ ╢████████████

Check if it is alive and kicking by running:

  $ bin/hubot

If all went well, you should now be able to chat with your bot in the console. Type ‘your-bot-name the rules’ and see if you get a reply.

Move from console to Slack

Create an account on Slack if you do not have one yet. I’ve created my own personal channel, to test this bot before implementing the code in Ingrid, our company bot. Once you have your own channel set up, go to https:// yourslackchannel and click on the green button, ‘Add Configuration’.

Add your bot’s username and hit ‘Add Hubot Configuration’.

Keep this page open, because you need to copy the environment variable in order to run your bot in Slack.

Slack adapter

Now that you’ve configured your bot in Slack, and got your token, you have to install the Slack adapter and your bot is setup to run locally:

  $ npm install hubot-slack --save

Open Slack on your computer and restart your bot with Slack’s environment variable, followed by a call to hubot’s scripts, plus the adapter flag:

  $ HUBOT_SLACK_TOKEN=your-hubot-api-token ./bin/hubot --adapter slack

Invite your bot to your #random Slack channel (/invite @botname) and test it out by typing @botname pug me

Congratulations! You are now ready to hook up Github’s pull request events.