Skip to content

Instantly share code, notes, and snippets.

@RobSpectre
Created April 20, 2014 01:38
Show Gist options
  • Select an option

  • Save RobSpectre/11102660 to your computer and use it in GitHub Desktop.

Select an option

Save RobSpectre/11102660 to your computer and use it in GitHub Desktop.
var http = require('http'),
twilio = require('twilio');
http.createServer(function (req, res) {
//Create TwiML response
var twiml = new twilio.TwimlResponse();
twiml.record();
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/');
//require the Twilio module and create a REST client
var client = require('twilio')('ACCOUNT_SID', 'AUTH_TOKEN');
//Place a phone call, and respond with TwiML instructions from the given URL
client.makeCall({
to:'+16515556677', // Number you want to call first
from: '+14506667788', // Number you want to call second
url: 'http://[INSERT URL TO SERVER ABOVE]', // This will connect over the public Internet to the server above.
ifMachine: true
}, function(err, responseData) {
//executed when the call has been initiated.
console.log(responseData.from); // outputs "+14506667788"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment