Skip to content

Instantly share code, notes, and snippets.

@philnash
Created November 4, 2015 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philnash/9c198b1d3bbc5fa0bd30 to your computer and use it in GitHub Desktop.
Save philnash/9c198b1d3bbc5fa0bd30 to your computer and use it in GitHub Desktop.
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/');
{
"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