How to Create a Custom Hubot on Heroku

Install Hubot & Redis

Don't waste your time. I've integrated my Hubot with Slack and uploaded him to Heroku so he can be always running. If you want to do the same great. If not you should probably look else where.

# Install Dependencies
npm install -g hubot coffee-script yo generator-hubot  
mkdir -p /path/to/hubot  
cd /path/to/hubot  
yo hubot  
npm install hubot-slack --save

# Test locally
HUBOT_SLACK_TOKEN=xoxb-xoxb-19746566118-5XM4xERiI6YERiI6YSpiaJGW ./bin/hubot --adapter slack

# Create redis "brain" for Hubot
heroku create yourapp  
heroku addons:create rediscloud:30

# Configure Heroku environment variables
heroku config:add HEROKU_URL=  
heroku config:add HUBOT_SLACK_TOKEN=xoxb-19746566118-5XM4xERiI6YERiI6YSpiaJGW

# Make sure you git init your project and commit it

# Deploy to heroku
git push heroku master


Useful Heroku Commands

# Check if environment variable is set
heroku config:get [VAR_NAME]

# List releases
heroku releases

# Rollback to a specific release
heroku rollback [vX]

# Stop your heroku app
heroku ps:scale web=0

# Start your heroku app
heroku ps:scale web=1

Programming Your Hubot

Here are some examples of common Hubot methods. Play around with them to add your own functionality. Keep in mind that Hubot is written in coffeescript.

# Check out scripts/ for current scripts and examples

# Fires when any text matches regex
robot.hear /regex/, (res) ->

# Fires when text matches and is prefixed with robots name "trumpig make me a sandwich"
robot.respond /make me a sandwich/ (res) ->

# Use to send text to entire group
res.send "Some text"

# Used to @mention a specific user in response text

# Randomize response for an array
res.send res.random ['Hi', 'Hello', 'Hola']

# Set / Get values from "Redis Brain"
groupSodas = robot.brain.get('totalSoda')  
robot.brain.set 'totalSodas', groupSodas+1

# Making HTTP calls
    .header('Accept', 'application/json')
    .get() (err, res, body) ->
      if err
        res.send "Encountered an error :( #{err}"
      # your code here, knowing it was successful

In Closing

About my Hubot

I named my Hubot "samjak" after Samuel Jackson. He listens for key words and spits out funny Samuel Jackson quotes based on those words.

You'll be able to configure a custom name for your Hubot after you run the yo hubot command. There are many useful Hubot plugins on NPM such as Google Analytics & App Annie integration, so go check them out.

My Hubot (samjak) is open source and you can fork him if you'd like