Upgrade to Pro — share decks privately, control downloads, hide ads and more …

HUBOT img me woman laughing alone with salad

HUBOT img me woman laughing alone with salad

Having your very own robot butler is finally possible! HUBOT from GitHub is an easy to setup and highly extensible automation assistant for your everyday needs. Use HUBOT to order food, grab directions, deploy code, and even open the door! Sure, he may take over the world someday, but in the meantime we might as well have some fun.

7064ad438246a02809c85bcd92cb5f3f?s=128

Jonathan Hoyt
PRO

April 20, 2012
Tweet

Transcript

  1. HUBOT img me woman laughing alone with salad

  2. developer and support

  3. Hoyt @jonmagic http://theprogrammingbutler . com https://github . com/jonmagic

  4. Internal Logic External Services Robot Butler

  5. Robot Butler

  6. None
  7. hubot puggle bomb

  8. hubot graph me -2d fs

  9. git push

  10. http://hubot-script-catalog.herokuapp.com hubot-script-catalog

  11. hubot-scripts http://github.com/github/hubot-scripts/pulls

  12. module.exports = (robot) -> robot.respond /good morning/i, (msg) -> msg.send

    "Good morning to you." jonmagic> hubot good morning hubot> Good morning to you. Respond & Send
  13. Regular Expressions

  14. module.exports = (robot) -> robot.hear /gasoline/i, (msg) -> msg.reply "Here

    we call it petrol." jonmagic> Jon, did you get gasoline yet? hubot> Hoyt: Here we call it petrol. Hear & Reply
  15. Internal Logic

  16. module.exports = (robot) -> robot.respond /good morning/i, (msg) -> msg.send

    "Good morning to you." common.js module specification
  17. # Public: Loads a file in path # # path

    - A String path on the filesystem. # file - A String filename in path on the filesystem. # # Returns nothing. loadFile: (path, file) -> ext = Path.extname file full = Path.join path, Path.basename(file, ext) if ext is '.coffee' or ext is '.js' try require(full) @ @parseHelp "#{path}/#{file}" catch err @logger.error "#{err}" src/robot.coffee
  18. Options = path: "." name: "Hubot" create: false adapter: "shell"

    alias: false enableHttpd: true ... robot = Hubot.loadBot options... ... robot.run ~/hubot-demo $ ./bin/hubot --name Jeeves ./bin/hubot
  19. exports.loadBot = (adapterPath...) -> robot = require './src/robot' new robot

    adapterPath, adapterName... index.coffee
  20. class Robot hear: (regex, callback) -> ... respond: (regex, callback)

    -> ... send: (user, strings...) -> ... reply: (user, strings...) -> ... http: (url) -> ... src/robot.coffee
  21. hear: (regex, callback) -> @listeners.push new TextListener(@, regex, callback) class

    TextListener extends Listener constructor: (@robot, @regex, @callback) -> @matcher = (message) => if message instanceof Robot.TextMessage message.match @regex class Listener call: (message) -> if match = @matcher message @callback new @robot.Response(@robot, message, match) true else false src/robot.coffee
  22. respond: (regex, callback) -> re = regex.toString().split("/") re.shift() # remove

    empty first item modifiers = re.pop() # pop off modifiers ... pattern = re.join("/") # combine the pattern back again if @alias alias = @alias.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") newRegex = new RegExp("^(?:#{alias}[:,]?|#{@name}[:,]?) ... ", mod...) else newRegex = new RegExp("^#{@name}[:,]?\\s*(?:#{pattern})", mod...) @logger.debug newRegex.toString() @listeners.push new TextListener(@, newRegex, callback) src/robot.coffee
  23. send: (strings...) -> @robot.adapter.send @message.user, strings... send: (user, strings...) ->

    if strings.length > 0 @bot.Room(user.room).speak strings.shift(), (err, data) => @robot.logger.error "Campfire error: #{err}" if err? @send user, strings... src/robot.coffee src/adapters/campfire.coffee
  24. reply: (strings...) -> @robot.adapter.reply @message.user, strings... reply: (user, strings...) ->

    @send user, strings.map((str) -> "#{user.name}: #{str}")... src/robot.coffee src/adapters/campfire.coffee
  25. http: (url) -> @httpClient.create(url) class ScopedClient constructor: (url, options) ->

    @options = @buildOptions url, options exports.create = (url, options) -> new ScopedClient url, options src/robot.coffee node-scoped-http-client https://github.com/technoweenie/node-scoped-http-client
  26. None
  27. Image Search

  28. Maps & Geo

  29. Definitions

  30. Messaging

  31. Meme Generators

  32. dnsimple.com

  33. GitHub Issues

  34. module.exports = (robot) -> robot.respond /(image|img)( me)? (.*)/i, (msg) ->

    imageMe msg, msg.match[3], (url) -> msg.send url imageMe = (msg, query, cb) -> msg.http('http://ajax.googleapis.com/ajax/...') .query(v: "1.0", rsz: '8', q: query) .get() (err, res, body) -> images = JSON.parse(body) images = images.responseData.results if images.length > 0 image = msg.random images cb "#{image.unescapedUrl}#.png" google-images.coffee
  35. module.exports = (robot) -> robot.hear /check domain (.*)/i, (msg) ->

    domain = escape(msg.match[1]) user = process.env.DNSIMPLE_USERNAME pass = process.env.DNSIMPLE_PASSWORD auth = 'Basic ' + new Buffer(user + ':' + pass).toString('base64'); msg.http("https://dnsimple.com/domains/#{domain}/check") .headers(Authorization: auth, Accept: 'application/json') .get() (err, res, body) -> switch res.statusCode when 200 msg.send "Sorry, #{domain} is not available." when 404 msg.send "Cybersquat that shit!" when 401 msg.send "You need to authenticate by ..." dnsimple.coffee
  36. module.exports = (robot) -> robot.respond /salesforce query (.*)$/i, (msg) ->

    query = msg.match[1] msg.http(auth_url).post() (err, res, body) -> oath_token = JSON.parse(body).access_token query = encodeURIComponent(query) msg.http(query_url + query) .headers(Authorization: "OAuth #{oath_token}") .get() (err, res, body) -> if err msg.send "Salesforce says: #{err}" return salesforce.coffee
  37. Takeout (take-away)

  38. Note: http://www.kayak.com/terms-of-use Airfares?

  39. http://github.com/jonmagic/fareme Middleware

  40. https://gist.github.com/215b0989b23e3b01fe6f Finally the Script

  41. hubot fare me ord to den may 15 to may

    20
  42. No API? Build one.

  43. BeagleBone

  44. sys = require('sys') exec = require('child_process').exec; express = require 'express'

    app = module.exports = express.createServer() app.get "/door", (req, res) -> # unlock the door exec "echo 38 > /sys/class/gpio/export" exec "echo out > /sys/class/gpio/gpio38/direction" exec "echo 1 > /sys/class/gpio/gpio38/value" sleep 2000 # lock the door and cleanup exec "echo 1 > /sys/class/gpio/gpio38/value" exec "echo 38 > /sys/class/gpio/unexport" res.send "Unlocked the door for you :)" Unlocking a door becomes easy
  45. Robot Butler - do our bidding Internal Logic - easy

    to grok External Services - change the world Other Resources - http://hubot-factory.herokuapp.com - https://github.com/tombell/learnhubotthehardway
  46. @jonmagic http://theprogrammingbutler . com https://github . com/jonmagic HUBOT img me

    woman laughing alone with salad