7. Hubot is simple
npm install -g generator-hubot
yo hubot
Coffeescript or JavaScript for coding
8. Hubot composition
Adapter -> which chat to use
Brain -> Store short and long term information
Listen and Reacts -> partecipate to discussions
9. How it is composed
15:04 $ ls l
total 36
drwxrwxrx 2 walter walter 4096 mar 15 17:47 bin
rwrwr 1 walter walter 232 mar 15 17:47 externalscripts.json
rwrwr 1 walter walter 13 mar 15 18:05 hubotscripts.json
drwxrwxrx 17 walter walter 4096 mar 15 17:49 node_modules
rwrr 1 walter walter 695 mar 15 17:49 package.json
rwrr 1 walter walter 26 mar 15 17:48 Procfile
rwrr 1 walter walter 7820 mar 15 17:47 README.md
drwxrwxrx 2 walter walter 4096 mar 15 20:31 scripts
10. Attach your scripts "hubot-
scripts.json"
[
"test"
]
It is related to a "scripts/test.coffee" file
11. The anatomy of a script
module.exports = (robot) >
# your code here
20. We can read any data from our
monitors and send them into
the chat room
React to Alarms
AWS CloudWatch Alarms => AWS SNS (HTTP) => Chat room
21. Hubot can react on HTTP calls
Capture events outside chat rooms
module.exports = (robot) >
robot.router.post '/hubot/chatsecrets/:room', (req, res) >
room = req.params.room
data = JSON.parse req.body.payload
secret = data.secret
robot.messageRoom room, "I have a secret: #{secret}"
res.send 'OK'
22. Hubot can make HTTP requests
Thanks to Scoped-HTTP-Client you can make any HTTP request
robot.http("https://myrestendpoint.tld/resource").get() (err, res, body) >
# your code here
For screen-scraping sessions you can use "cheerio" that it has a
jQuery like selectors and we interact directly with web pages.
23. Do not put your secret keys
into scripts
you can pass variables to your hubot using environment variables
aws_key = process.env.HUBOT_AWS_KEY
aws_secret = process.env.HUBOT_AWS_SECRET
module.exports = (robot) >
robot.respond /add (+d) server(s)?/i, (msg) >
# use aws_key and aws_secret in order to add more resources to your cluster
24. Say hello and goodbye to our
team mates
module.exports = (robot) >
robot.enter (msg) >
msg.send "Welcome!!!!"
robot.leave (msg) >
msg.send "Have a nice day!!"
Enter/Leave messages