Skip to content

Instantly share code, notes, and snippets.

@stijlist
Created May 30, 2014 08:18
Show Gist options
  • Save stijlist/912c1e07fe580529bb26 to your computer and use it in GitHub Desktop.
Save stijlist/912c1e07fe580529bb26 to your computer and use it in GitHub Desktop.
# Description:
# Looks up the phone number for a given name in the YF.
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# lookup <whoever>'s number - tyreke says "<whoever>'s number is 8675309"
#
# Author:
# stijlist
module.exports = (robot) ->
robot.hear /lookup (\w+) (\w+)'s number/, (msg) ->
fname = msg.match[1]
lname = msg.match[2]
data = JSON.stringify
fname: fname
lname: lname
robot.http("https://tmcyf.org/sms-lookup")
.header('Accept', 'application/json')
.post(data) (err, res, body) ->
if err
msg.send "Encountered an error: #{err}"
return
if res.statusCode isnt 200
msg.send "Request didn't come back HTTP 200 :( @ivanvarghese @bgm"
return
maybeNumber = JSON.parse(body).number
msg.send "Maybe #{fname} #{lname}'s number is #{maybeNumber}?"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment