Created
November 22, 2014 03:07
-
-
Save jsloyer/e56833631e879da3fdc3 to your computer and use it in GitHub Desktop.
twilio response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.post('/sms', function (request, response) { | |
var body = request.body.Body, | |
twitterHandles = [], | |
twitterId1, | |
twitterId2; | |
console.log("Twitter handles before replacing and splitting", body); | |
body = body.replace(/\@/g, "").replace(/and/g, ""); | |
twitterHandles = body.split(/[ ,]+/); | |
console.log("Twitter handles after splitting", twitterHandles); | |
twitterId1 = twitterHandles[0].trim(); | |
twitterId2 = twitterHandles[1].trim(); | |
analyzePeeps(twitterId1, twitterId2, function (error, inCommon, valuesUser1, valuesUser2) { | |
var smsResponse = ""; | |
if (error) { | |
console.log(error); | |
smsResponse = "<Response><Sms>Something went wrong, please try again</Sms></Response>"; | |
} | |
else { | |
smsResponse = "<Response><Sms>" + twitterId1 + " and " + twitterId2 + | |
" share " + inCommon + " out of the top 5 personality traits</Sms></Response>"; | |
} | |
response.send(smsResponse); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment