How to use the twilio.TwimlResponse function in twilio

To help you get started, we’ve selected a few twilio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TwilioDevEd / api-snippets / client / response-twiml-client / response-twiml-client.2.x.js View on Github external
app.post('/voice', function (req, res) {
    // Create TwiML response
    var twiml = new twilio.TwimlResponse();
    
    if(req.body.To) {
      twiml.dial({ callerId: '+15017250604'}, function() {
        // wrap the phone number or client name in the appropriate TwiML verb
        // by checking if the number given has only digits and format symbols
        if (/^[\d\+\-\(\) ]+$/.test(req.body.To)) {
          this.number(req.body.To);
        } else {
          this.client(req.body.To);
        }
      });
    } else {
      twiml.say("Thanks for calling!");
    }

    res.set('Content-Type', 'text/xml');
github TwilioDevEd / api-snippets / guides / voice / respond-incoming-calls-guide / respond-with-parameters / example.2.x.js View on Github external
app.post('/voice', (request, response) => {
  // Get information about the incoming call, like the city associated
  // with the phone number (if Twilio can discover it)
  let city = request.body.FromCity;

  // Use the Twilio Node.js SDK to build an XML response
  let twiml = new twilio.TwimlResponse();
  twiml.say(`Never gonna give you up ${city}.`, { 
    voice: 'alice' 
  });
  twiml.play('https://demo.twilio.com/docs/classic.mp3');

  // Render the response as XML in reply to the webhook request
  response.type('text/xml');
  response.send(twiml.toString());
});
github aws-samples / lambda-refarch-webapp / lambda-functions / receive-vote / app.js View on Github external
}, function(err, data) {
      if (err) {
        console.log(err);
        context.fail(err);
      } else {
        var resp = new twilio.TwimlResponse();
        resp.message("Thank you for casting a vote for " + votedFor);
        context.done(null, [resp.toString()]);
        console.log("Vote received for %s", votedFor);
      }
    });
  } else {
github TwilioDevEd / api-snippets / rest / voice / generate-twiml-play / example-1.js View on Github external
http.createServer(function (req, res) {
    //Create TwiML response
    var twiml = new twilio.TwimlResponse();
    twiml.say("Hello. It's me.");
    twiml.play("http://howtodocs.s3.amazonaws.com/ahoyhoy.mp3");

    res.writeHead(200, {'Content-Type': 'text/xml'});
    res.end(twiml.toString());

}).listen(1337, '127.0.0.1');
github TwilioDevEd / api-snippets / rest / voice / generate-twiml-play / example-1.2.x.js View on Github external
http.createServer(function (req, res) {
    //Create TwiML response
    var twiml = new twilio.TwimlResponse();
    twiml.say("Hello. It's me.");
    twiml.play("http://howtodocs.s3.amazonaws.com/ahoyhoy.mp3");

    res.writeHead(200, {'Content-Type': 'text/xml'});
    res.end(twiml.toString());

}).listen(1337, '127.0.0.1');
github IBM-Cloud / doctor-watson / routes / calls.js View on Github external
router.post('/holding', twilio.webhook(twilio_auth_token), function (req, res) {
  log.info(req.body.CallSid + '-> calls/holding')
  log.debug(req.body)

  var twiml = new twilio.TwimlResponse()
  twiml.pause({length: 5})
    .say("I'm still thinking")
    .redirect('/calls/holding')

  res.send(twiml)
})
github TwilioDevEd / api-snippets / rest / voice / generate-twiml-gather-input / twiml-gather-record.2.x.js View on Github external
var redirectWelcome = function () {
    var twiml = new twilio.TwimlResponse();
    twiml.say("Returning to the main menu", {voice: "alice", language: "en-GB"});
    twiml.redirect("/voice");
    return twiml;
};
github ethanresnick / twilio-ivr / build / lib / modules / staticFiles / index.js View on Github external
            ((urlFor) => (new twilio_1.TwimlResponse()).play({ loop: 1000 }, urlFor(path.normalize(staticFilesMountPath + '/' + holdMusicFileUri), { absolute: true })));
        if (!holdMusicFileUri) {
github mplacona / twilio-pa / app.js View on Github external
app.post('/call', function(req, res) {
  var number = req.query.number;
  var eventName = req.query.eventName;
  var resp = new twilio.TwimlResponse();
  resp.say('Your meeting ' + eventName + ' is starting.', {
    voice: 'alice',
    language: 'en-gb'
  }).dial(number);

  res.writeHead(200, {
    'Content-Type': 'text/xml'
  });
  res.end(resp.toString());
});