hubot: a look inside our robot friend
DESCRIPTION
An overview of Hubot, describing setup and writing scripts.TRANSCRIPT
![Page 1: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/1.jpg)
![Page 2: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/2.jpg)
HUBOTA LOOK INSIDE OUR ROBOT FRIEND
![Page 3: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/3.jpg)
1. Setting Up Hubot2. Coffeescript Primer3. Hubot Overview4. APIs
![Page 4: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/4.jpg)
![Page 5: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/5.jpg)
(disclaimer: this assumes OSX. commands shouldtranslate easily to windows and linux.)
![Page 6: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/6.jpg)
PREREQUISITESInstall Node
brew install node
Install and run Redisadd /usr/local/share/npm/bin to your path
Install Hubotnpm install -g coffee-script
npm install -g hubot
An account is suggested.Heroku
![Page 7: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/7.jpg)
FIND A NICE HOMEcd to directory of choice
run hubot -c airbot to generate a boilerplatecd airbot
chmod +x bin/hubot
![Page 8: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/8.jpg)
HELLO WORLDrun bin/hubot
type hubot ping and hit enter
![Page 9: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/9.jpg)
A BRIEF DIVERSION INTOCOFFEESCRIPT
![Page 10: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/10.jpg)
introMessage = (user) -> if user?.name? and user?.hobby? "hello, I am #{response.name}, " + "a #{response.hobby}ist." else message = "Please tell me more about yourself."
message
me = name: "Jack" hobby: "Hubot curation"
console.log introMessage(me)
#hello, I am Jack, a Hubot curationist
![Page 11: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/11.jpg)
HUBOT STRUCTUREProcfile (Heroku startup script)README.mdbin/ (contains hubot executable)external-scripts.json (list of packages from npm)hubot-scripts.json (list of packages from hubot-scripts)package.json (node package managermetainformation)scripts/ (custom hubot script directory)
![Page 12: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/12.jpg)
A HUBOT SCRIPTEXAMPLE
CREATE AND EDITSCRIPTS/GOODBYE.COFFEE
![Page 13: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/13.jpg)
goodbyes = [ "Bye, {name}.", "Later, {name}.", "Take care, {name}."]
goodbye = (name) -> index = parseInt(Math.random() * goodbyes.length) message = goodbyes[index] message.replace(/{name}/, name);
module.exports = (robot) -> robot.hear /(bye|later),?\s(.*)/i, (msg) -> if robot.name.toLowerCase() == msg.match[2].toLowerCase() byeMessage = goodbye(msg.message.user.name) msg.send(byeMessage)
![Page 14: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/14.jpg)
![Page 15: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/15.jpg)
run bin/hubot againsay goodbye Hubotsay later, Hubot
![Page 16: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/16.jpg)
HUBOT-SCRIPTSGITHUB.COM/GITHUB/HUBOT-SCRIPTS
hubot will automatically download and keep up-to-dateany hubot-scripts you add
![Page 17: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/17.jpg)
copy the dependencies from the hubot-script into yourpackage.json
from :clark.coffee# Description:# None## Dependencies:# "clark": "0.0.5"## Configuration:# None## Commands:# hubot clark <data> - build sparklines out of data## Author:# ajacksified
![Page 18: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/18.jpg)
edit hubot-scripts.jsonadd "clark.coffee"
run bin/hubotsay hubot clark 1 2 3 4 5
![Page 19: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/19.jpg)
![Page 20: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/20.jpg)
HUBOT PERSISTANCEsimple storage through hubot.brain
overloaded by redis-brain, mongo-brain, etc.(you can find these in hubot-scripts or write your own)
![Page 21: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/21.jpg)
You can save any arbitrary data in the brain.# you may want to wait until the brain has been initialized# and there is a database connectionrobot.brain.on 'loaded', -> robot.brain.lastAccessed = new Date() robot.brain.seagulls = 12 robot.brain.flowers = { pansies: true, daffodils: false }
# hubot brain runs on events robot.brain.emit 'save'
![Page 22: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/22.jpg)
HUBOT HTTP LISTENERCREATE AND EDIT
SCRIPTS/SAY.COFFEE
![Page 23: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/23.jpg)
querystring = require('querystring')
module.exports = (robot) -> robot.router.get "/hubot/say", (req, res) -> query = querystring.parse(req._parsedUrl.query) message = query.message
user = {} user.room = query.room if query.room
robot.send(user, message) res.end "said #{message}"
![Page 24: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/24.jpg)
edit package.json to include"querystring": ">= 0.1.0" in the dependencies
run npm installrun bin/hubot
visit localhost:8080/say?message=hello
![Page 25: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/25.jpg)
DEPLOYMENT99 times out of 100, you'll probably just deploy to Heroku
hubot -c creates a Heroku Procfile for yourun Heroku create
deploy with git push heroku masterstart with heroku ps:scale web=1
(you'll only have to run ps:scale this the first time)
![Page 26: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/26.jpg)
CHAT ADAPTERSHubot ships with a Campfire adapter. You can get more
from hubot-scripts.Assuming Heroku deployment, run
Heroku config:addHUBOT_CAMPFIRE_TOKEN=secretHUBOT_CAMPFIRE_ROOMS=123,456HUBOT_CAMPFIRE_ACCOUNT="hubot"
![Page 27: Hubot: a look inside our robot friend](https://reader033.vdocuments.site/reader033/viewer/2022052901/55660c52d8b42aa6628b5193/html5/thumbnails/27.jpg)