Date post: | 15-Jul-2015 |
Category: |
Technology |
Upload: | corley-srl |
View: | 272 times |
Download: | 1 times |
Hubot compositionAdapter -> which chat to useBrain -> Store short and long term informationListen and Reacts -> partecipate to discussions
How it is composed15:04 $ ls ltotal 36drwxrwxrx 2 walter walter 4096 mar 15 17:47 binrwrwr 1 walter walter 232 mar 15 17:47 externalscripts.jsonrwrwr 1 walter walter 13 mar 15 18:05 hubotscripts.jsondrwxrwxrx 17 walter walter 4096 mar 15 17:49 node_modulesrwrr 1 walter walter 695 mar 15 17:49 package.jsonrwrr 1 walter walter 26 mar 15 17:48 Procfilerwrr 1 walter walter 7820 mar 15 17:47 README.mddrwxrwxrx 2 walter walter 4096 mar 15 20:31 scripts
Hearing/Sendwdalmut: guys, do we have problems in production?hubot: http://somewhere.tld/cpu/average.png
Hearing/Send (hubot side)robot.hear /regularexpression/i, (msg) > # get the actual status and send it msg.send "the image url" # the chat will append the real image
Responing/Replywdalmut: hey @hubot can you draw the actual load status?hubot: http://somewhere.tld/cpu/average.png
Responing/Reply (hubot side)robot.respond /regularexpression/i, (msg) > # get the actual status and send it msg.reply "the image url" # the chat will append the real image
We can read any data from ourmonitors and send them into
the chat roomReact to Alarms
AWS CloudWatch Alarms => AWS SNS (HTTP) => Chat room
Hubot can react on HTTP callsCapture 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'
Hubot can make HTTP requestsThanks to Scoped-HTTP-Client you can make any HTTP requestrobot.http("https://myrestendpoint.tld/resource").get() (err, res, body) > # your code here
For screen-scraping sessions you can use "cheerio" that it has ajQuery like selectors and we interact directly with web pages.
Do not put your secret keysinto scripts
you can pass variables to your hubot using environment variablesaws_key = process.env.HUBOT_AWS_KEYaws_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
Say hello and goodbye to ourteam mates
module.exports = (robot) >
robot.enter (msg) > msg.send "Welcome!!!!"
robot.leave (msg) > msg.send "Have a nice day!!"
Enter/Leave messages
On commit notifies thatsomething happens
# src/scripts/githubcommits.coffeemodule.exports = (robot) > robot.router.post "/hubot/ghcommits", (req, res) > robot.emit "commit", { user : {}, #hubot user object repo : 'https://github.com/github/hubot', hash : '2e1951c089bd865839328592ff673d2f08153643' }
Other scripts can receiveevents
# src/scripts/heroku.coffeemodule.exports = (robot) > robot.on "commit", (commit) > robot.send commit.user, "Will now deploy #{commit.hash} from #{commit.repo}!" #deploy code goes here