Deploying Hubot to Slack with anynines

a9s Hubot SlackIf your team uses Slack or any other chat for communication, you probably heard about Hubot by now. If you haven’t, well, Hubot is an amazing bot developed by Github to be a butler that sits in your chat and listens to the commands.
Github is famous for their idea of ChatOps, where a lot of things happen through their company Campfire chat, so they wrote Hubot to suit their needs. Need something translated? Ask Hubot. Need an app deployed, but you really suck at command line?
Get your developers to configure hubot-deploy. Team keeps forgetting about standups? There’s a Hubot script with a standup reminder. Whatever you need, there’s probably a Hubot script for that. If not, Hubot is extendable using CoffeeScript (a flavour of JavaScript), it’s very easy to write your own tools.

In this post, I will show you how to deploy your own hubot (with Slack adapter, as we use Slack for our team) to anynines.

1. Install Hubot

First thing you need to do is install and set up Hubot locally. Assuming you have Node.js environment already installed (if you don’t, Node.js has a bunch of tutorials on that – like: https://nodejs.org/en/download/package-manager/), all you need to do is run:

$ npm install -g yo generator-hubot

This will install Yeoman, the scaffolding tool, as well as Yeoman generator for setting up Hubots. If that went smoothly (on some io.js & new Node.js versions, you might run into warnings about yo version, but as long as it’s not an error, you can safely ignore them), set up your new Hubot using

$ mkdir my-hubot
$ cd my-hubot
$ yo hubot

This will run a setup environment for Hubot. Make sure you are more creative while naming your bot than I was and you don’t name it
hubot or you’ll run into dependency issue with Node telling you you’re mad if you want to install Hubot as a Hubot dependency. Which kinda makes sense, I guess.

After the setup process succeeded, install your Slack adapter:

$ npm install hubot-slack —save

To check if your Hubot works correctly, run it locally:

$ bin/hubot

Works? Great! Now it’s time to set up Slack!

2. Set up Slack

To make Hubot run on Slack, you need to give it a token. To get your personal token, go to Slack apps page, search for Hubot and add a new Hubot to your Slack team. Inside the configuration pane, you should find something like this:

HUBOT_SLACK_TOKEN=<...>

This is your Hubot Slack token that you need to set up in your anynines manifest to make sure your Hubot can talk to your Slack.

3. Deploy

To deploy your Hubot to an anynines instance, you need to do a bunch of simple steps. First of all, make sure you’re in the right organization and space, by typing in:

$ cf target

Once you made sure, it’s time to create your manifest.yml
file. Here’s an example file that you can use:

---
applications:
- name: my_hubot
  memory: 512M
  instances: 1
  buildpack: https://github.com/heroku/heroku-buildpack-nodejs.git
  command: bin/hubot -a slack
  host: my-hubot
  domain: de.a9sapp.eu
  path: .
  services:
   - redis-my_hubot
  env:
   HUBOT_SLACK_TOKEN: <…>

As you can see, Hubot uses Redis for its “brain”, where it keeps all the important information. To set up your Redis on anynines, check out cf marketplace for the list of available services. Once you did that, set up an instance using:

$ cf create-service redis redis-my_hubot

After you’re done, make sure to put your HUBOT_SLACK_TOKEN in your manifest file and you should be good to go. Push your Hubot to anynines using

$ cf push

Voila! If everything worked, you should see Hubot connect to your Slack team when the deploy is done.

Have fun and happy hacking!

Leave a Reply

Your email address will not be published.

*