Skip to content

Instantly share code, notes, and snippets.

@beck
Last active January 23, 2016 16:04
Show Gist options
  • Save beck/f7577db0461981619bc2 to your computer and use it in GitHub Desktop.
Save beck/f7577db0461981619bc2 to your computer and use it in GitHub Desktop.
Bobo's getting started

Bobo

bobo's face

A novice guide to programming Bobo, our loveable cucumber (possibly pickled) slackbot.

Basic Shit

  • bobo is a hubot
  • bobo scripts are written in javascript
  • most hubot scripts are written in CoffeeScript (coffee is a little language that compiles into js)
  • scripts are run on the server (not the browser) via Node.js
  • bobo's source code is kept in git
  • bobo is hosted on heroku (a cloud service)

This should make sense:

My original hubot script was written in js and then I rewrote it in coffee.
I've commited all code to the git repo and pushed the changes to heroku.

If it does not, go learn ya'self.

General Developer Tools

  • install a decent text editor - https://atom.io/
  • make sure you have git installed
    • open up your console
    • run: git --version
  • make sure you have node installed
    • run in console: node --version
  • setup heroku

Setting up bobo

  • log into heroku

    $ heroku login
    
  • checkout the source

    $ heroku git:clone -a bobobot bobo
    
  • verify checkout, run bobo:

    $ cd bobo
    $ bin/bobo
    ...(lots of output)...
    [hit enter a few times]
    bobo>
    
  • talk to bobo:

    bobo> bobo echo I am a good robot
    bobo> I am a good robot
    

    type exit or hit control+c to exit

Write your first hubot script

  1. create file scripts/iloveyou.coffee

  2. define a new hubot command, in iloveyou.coffee write:

module.exports = (robot) ->
  robot.respond /i love you/i, (res) ->
    res.send "I love you too"
  1. test out the script:
$ bin/bobo
[hit enter]
bobo> bobo i love you
bobo> I love you too
exit
  1. these changes looks good, so lets commit them to the repository:
$ git status
Untracked files:
  scripts/iloveyou.coffee
$ git add scripts/iloveyou.coffee
$ git commit -m "Add 'i love you' command"
  1. add a bit of functionality to the script. Lets make bobo sad. Update the regular expression to match both "love" and "hate". Update iloveyou to be:

    module.exports = (robot) ->
      robot.respond /i (love|hate) you/i, (res) ->
        emotion = res.match[1]
        if emotion is "hate"
          res.send "My heart. It hurts. :("
          return
        res.send "I love you too"
  2. test the results:

$ bin/bobo
bobo> bobo i love you
bobo> I love you too
bobo i hate you
bobo> My heart. It hurts. :(

Excellent.

  1. Commit the changes:
$ git diff
[see changes in iloveyou.coffee]
$ git add scripts/iloveyou.coffee
$ git commit -m "Update iloveyou script to accept hate"
  1. Push the changes back to heroku. This will update the slackbot and make the new command accessible in slack. Run:
git push
... lots of output...

Jump into slack. There will be a moment when bobo is offline (it is restarting). Private message bobo.

When sending private messages to bobo, commands do not need to be prefixed with "bobo" (as is the case when running locally or using #general).

Tell him "i love you". Tell him "i hate you". Bobo should send the same responses seen locally.

If so, WOO! First bobo script.

What next?

Halp!

If/when you get stuck, helpful docs:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment