Skip to content Skip to sidebar Skip to footer

Twilio Send A Voice Message If User Doesn't Answer, In An Outbound Call

I am new to using twilio. I am using twilio to make calls from browser to phone. In the browser side I am using twiml Device to connect to the call. Twilio.Device.connect({ phoneNu

Solution 1:

This should be possible using a combination of Twilio's Answering Machine Detection service and the <Play> TwiML verb.

Here is a code sample of making an outbound call with answering machine detection.

const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.calls
  .create({
     machineDetection: 'Enable',
     url: 'https://handler.twilio.com/twiml/EHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
     to: '+1562300000',
     from: '+18180000000'
   })
 .then(call =>console.log(call.sid))
 .done();

With AMD enabled on your call, Twilio will post the result of the call to the webhook you specify. That webhook will receive an AnsweredBy parameter that will indicate events like machine_start or machine_end_beep.

The controller that receives the webhook should respond by using the <Play> TwiML verb to "press" the correct button. Here is a code sample of what that might look like (this code is untested):

constVoiceResponse = require('twilio').twiml.VoiceResponse;

app.post('/answering-machine-handler', function (req, res) {
  const response = newVoiceResponse();

  if (req.params.AnsweredBy === 'machine_start') {
    response.play({
        digits: 'wwww3'
    });
  } else {
    // Handle other cases here.
  }

  res.send(response);
})

console.log(response.toString());

Post a Comment for "Twilio Send A Voice Message If User Doesn't Answer, In An Outbound Call"