Hubots

more than meets the eye

whoami

I am an operational tool and infrastructure developer at Yieldbot who is lazy by nature.

I don't even wait till I do something twice before scripting it

man ChatOps | more

It's not all about the bots!

ChatOps brings common operational tasks and the conversations surrounding them into a single shared view

Conversation-driven development and operations

  • Github Releases
  • Asana Tasks
  • IFTTT
  • Jenkins Builds

Be careful of the Decepticons!

  • Should everyone in the channel access the bot?
  • Should the bot play God?
  • Mobile devices?

Tools

Slack

Web based chat client capable of supporting large teams and serval different types of integrations including multiple bots

Hubot

  • developed at Github
  • written in Node.js
  • scripts can be written in js or cs
  • large open source community constantly submitting new scripts

Heroku

  • cloud application platform
  • 100+ service add-ons
  • easily scalable

Node.Js

  • JavaScript runtime
  • event-driven
  • non-blocking I/O model

Ship It

  1. setup Slack
  2. setup dev environment
  3. setup Heroku
  4. launch it
  5. code / debug it

Roll Out

Setup Slack

  • create a slack account
  • create a channel
  • setup integration

Setup Development Environment


vagrant up
vagrant ssh
curl https://raw.githubusercontent.com/creationix/nvm/v0.16.1/install.sh | sh
nvm install 0.12.7
npm install -g hubot coffee-script yo generator-hubot
              

Create A Bot


mkdir ~/bot
cd ~/bot
yo hubot
npm install hubot-slack --save
              

Setup Heroku


sudo wget -O- https://toolbelt.heroku.com/install-ubuntu.sh | sh
git init && git add --all && git commit -m 'initial commit'
heroku create optimus-prime
heroku addons:create redistogo:nano --app optimus-prime
npm install hubot-heroku-keepalive --save
heroku config:set HUBOT_HEROKU_KEEPALIVE_URL=https://optimus-prime.herokuapp.com --app optimus-prime
heroku config:set HEROKU_URL=https://optimus-prime.herokuapp.com --app optimus-prime
heroku config:set HUBOT_SLACK_TOKEN=xoxb-11995843430-XPP92BkpOEUrmsGxgEeXLy7L --app optimus-prime
            

Pencils Down Class


git push heroku master
heroku ps:scale web=1
            

But I Wanted Fortress Maximus

.hear && .respond


module.exports = (robot) ->
  robot.hear /roll out/i, (res) ->
    # Optimus will respond to any string containing 'roll out'   

  robot.respond /Autobots, transform and roll out/i, (res) ->
    # You need to directly call Optimus
    

.send || .reply || .emote


module.exports = (robot) ->
  robot.hear /roll out/i, (res) ->
  res.reply "Who gave you the leadership matrix"

robot.respond /Autobots, transform and roll out/i, (res) ->
  res.send "Let's kick some Decepticon butt"

robot.hear /Predacons, merge to become Predaking/i, (res) ->
  res.emote "[Predacons transform into Predaking]"
      

capturing data


robot.respond /arise (.*)/i, (res) ->
  autobot = res.match[1]
  if autobot is " Rodimus Prime"
    res.reply "I knew you had potential"
  else
    res.send "One day, an Autobot shall rise from our ranks, 
    and use the power of the Matrix to light our darkest hour."
      

external api calls


  data = JSON.stringify({
    autobot_city: 'transform'
  })
  robot.http("https://rc-springer")
    .header('Content-Type', 'application/json')
    .post(data) (err, res, body) ->
      

local testing and debugging

Run locally `bin/hubot`

Debug remote bot locally `heroku logs`

Additional Resources

Images

  • https://www.tumblr.com/search/autobot%20gif
  • http://giphy.com/gifs/out-roll-autobots-BZaGpT3O0EMiA
  • http://statici.behindthevoiceactors.com/behindthevoiceactors/_img/chars/char_5207.jpg
  • http://usercontent2.hubimg.com/6183365_f520.jpg
  • http://usercontent2.hubimg.com/6183365_f520.jpg
  • http://vignette3.wikia.nocookie.net/transformers/images/0/0e/Lolpuberty.jpg/revision/latest?cb=20070116055254

Questions?