简体   繁体   中英

Twilio node - Browser to phone StatusCallback events

I am trying to get back StatusCallback events when I dial from my browser to phone call.

When user clicks on dial in browser I am sending the following response to twilio:

  const dial = twiml.dial({
    callerId: Meteor.settings.private.twilio.TWILIO_CALLER_ID,
    answerOnBridge: true,
    record: "record-from-answer-dual",
    StatusCallbackEvent: ["initiated", "ringing", "answered", "completed"],
    StatusCallback,
    recordingStatusCallback: recordURLCallback,
  });
  dial.number(toNumber);

I have registered webhook both in twilio console and also sending via command but i'm not receiving 'ringing', 'answered' events from twilio

   WebApp.connectHandlers.use("/twilio-status-callback", function( req, res, next ) {
     console.log('***status url callback***');
     var body = "";
     req.on('data', Meteor.bindEnvironment(function (data) {
       body += data;
     }));
     req.on('end', Meteor.bindEnvironment(function () {
      body = qs.parse(body)
      console.log(body);

      res.end();
    }));
  });

I am only receiving completed event, how to get other statuses to so that I can show ringing UI when it is ringing and hangup button when answered?

Twilio developer evangelist here.

In your example code you don't include an option for StatusCallback so there is no webhook for Twilio to call, only a recordingStatusCallback . Also, the Node library actually translates the keys from lower-camel-case, so the keys should be statusCallback . Try updating the code to something like this and let me know how it goes:

const dial = twiml.dial({
  callerId: Meteor.settings.private.twilio.TWILIO_CALLER_ID,
  answerOnBridge: true,
  record: "record-from-answer-dual",
  statusCallbackEvent: ["initiated", "ringing", "answered", "completed"],
  statusCallback: statusURLCallback,
  recordingStatusCallback: recordURLCallback,
});
dial.number(toNumber);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM