Skip to content

Instantly share code, notes, and snippets.

@jsloyer
Created November 22, 2014 03:07
Show Gist options
  • Save jsloyer/e56833631e879da3fdc3 to your computer and use it in GitHub Desktop.
Save jsloyer/e56833631e879da3fdc3 to your computer and use it in GitHub Desktop.
twilio response
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