Skip to content

Instantly share code, notes, and snippets.

@nein37
Created February 19, 2016 03:52
Show Gist options
  • Save nein37/2a7650d4bfaa00f77240 to your computer and use it in GitHub Desktop.
Save nein37/2a7650d4bfaa00f77240 to your computer and use it in GitHub Desktop.
module.exports = (robot) ->
robot.respond /ifttt ([^ ]+) ([^ ]+)$/i, (res) ->
eventType = res.match[1]
val1 = res.match[2]
handleIftttMaker(res, eventType, val1, null, null)
robot.respond /ifttt ([^ ]+) ([^ ]+) ([^ ]+)$/i, (res) ->
eventType = res.match[1]
val1 = res.match[2]
val2 = res.match[3]
handleIftttMaker(res, eventType, val1, val2, null)
robot.respond /ifttt ([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+)$/i, (res) ->
eventType = res.match[1]
val1 = res.match[2]
val2 = res.match[3]
val3 = res.match[4]
handleIftttMaker(res, eventType, val1, val2, val3)
handleIftttMaker = (msg, eventType, val1, val2, val3) ->
iftttMakerKey = process.env.HUBOT_IFTTT_MAKER
url = "https://maker.ifttt.com/trigger/#{eventType}/with/key/#{iftttMakerKey}"
body = JSON.stringify({
value1: val1
value2: val2
value3: val3
})
msg.http(url)
.header('Content-Type', 'application/json')
.post(body) (err, res, body) ->
if err
msg.send "sorry, request failed.."
else
msg.send "request ok : #{body}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment