0

I'm trying to implement a Twilio function to (1) forward calls to my personal phone, (2) send a "heads up" SMS just before, and (3) say a whisper prior to connecting. I've been able to set up Twilio to do any 2 of the previous 3 things but never the 3 at the same time!

exports.handler = function(context, event, callback) {
  // Get an initialized Twilio API client
  const client = context.getTwilioClient();

  twilioClient.messages.create({
        to: 'PERSONAL_PHONE',
        from: 'TWILIO_PHONE',
        body: 'Incoming!!!'
    }).then(function() {
        const twiml = new Twilio.twiml.VoiceResponse();
        twiml.dial.number({ url: WHISPER_URL }, 'PERSONAL_PHONE');
        callback(null, twiml);
    });

};

When implementing this, it sends the SMS but the call never connects (and the calling party hears an error message).

Would really appreciate a lesson here :)

Thank you!

Sebastian Rivas
  • 1,700
  • 2
  • 13
  • 15

1 Answers1

0

Btw, I found a solution:

exports.handler = function(context, event, callback) {
  // Get an initialized Twilio API client
  const client = context.getTwilioClient();

  twilioClient.messages.create({
        to: 'NUMBER',
        from: 'TWILIO_PHONE',
        body: 'Incoming!!!'
    }).then(function() {
        const twiml = new Twilio.twiml.VoiceResponse();
        const dialobj = twiml.dial();
        dialobj.number({url:'WHISPER_URL'},'NUMBER');
        callback(null, twiml);
        });

};
Sebastian Rivas
  • 1,700
  • 2
  • 13
  • 15
  • Glad you found a solution here! The issue was that you didn't call the `dial` function in the first iteration. You could rewrite this solution as `twiml.dial().number({ url: WHISPER_URL }, 'PERSONAL_PHONE');` as long as you include the parentheses on the `dial` function. – philnash Feb 27 '19 at 01:24