Created
November 4, 2015 21:15
-
-
Save philnash/9c198b1d3bbc5fa0bd30 to your computer and use it in GitHub Desktop.
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
var http = require('http'); | |
var twilio = require('twilio'); | |
var qs = require('querystring'); | |
http.createServer(function (req, res) { | |
var body = ''; | |
req.setEncoding('utf8'); | |
req.on('data', function(data) { | |
body += data; | |
}); | |
req.on('end', function() { | |
var data = qs.parse(body); | |
var jsonString = JSON.stringify(data); | |
var jsonDataObject = JSON.parse(jsonString); | |
// log the received message | |
console.log(jsonDataObject.Body); | |
var twiml = new twilio.TwimlResponse(); | |
twiml.message("Hello world"); | |
res.writeHead(200, {'Content-Type': 'text/xml'}); | |
res.end(twiml.toString()); | |
}); | |
}).listen(1337, '127.0.0.1'); | |
console.log('TwiML servin\' server running at http://127.0.0.1:1337/'); |
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
{ | |
"name": "stackoverflowtest", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"querystring": "^0.2.0", | |
"twilio": "^2.5.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment