Skip to content

Instantly share code, notes, and snippets.

@stijlist
Last active August 29, 2015 14:02
Show Gist options
  • Save stijlist/aa8630069c8604e7520b to your computer and use it in GitHub Desktop.
Save stijlist/aa8630069c8604e7520b 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
api_key: process.env.SMS_LOOKUP_KEY
robot.http("https://tmcyf.org/lookup_number")
.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