Skip to content

Instantly share code, notes, and snippets.

@dtolb
Created March 2, 2016 14:38
Show Gist options
  • Save dtolb/721a690791373fc63d9b to your computer and use it in GitHub Desktop.
Save dtolb/721a690791373fc63d9b to your computer and use it in GitHub Desktop.
Express Message Handler
app.get('/msgcallback', function(req, res) {
var response = {
to: req.query.from,
from: req.query.to,
text: getPhrase()
};
var text = req.query.text.toLowerCase();
switch(text) {
case 'i luv u':
response.media = [getPhoto()];
break;
case 'hugs':
response.media = [getBear()];
break;
case 'kisses':
response.media = [getCandy()];
break;
case 'bandwidth':
response.media = ['https://s3.amazonaws.com/bwdemos/vday/bw.jpg'];
break;
default:
break;
}
Message.createAsync(response)
.then(function (result) {
//console.log(result);
})
.catch(function (e) {
console.log(e);
});
res.sendStatus(201); //Immediately respond to request
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment