如果 twilio 呼叫状态为无应答,如何让它路由到另一个号码?


if (OkToCall)
{
if (CallCount == 0)
{
voiceResponse.Say(sayMessage);
voiceResponse.Dial(number: number1, timeout: 24, action: new Uri("/OnCall/?Location=" + Location + "&CallCount=1", UriKind.Relative));
}
else if (CallCount == 1)
{
sayMessage = "We're sorry. There was no answer. You are now being redirected to the on call manager. One moment. ";
voiceResponse.Say(sayMessage);
voiceResponse.Dial(number: number2, timeout: 24, action: new Uri("/OnCall/?Location=" + Location + "&CallCount=2", UriKind.Relative));
}
else
{
sayMessage = "We're sorry. We were unable to connect your call. Please try again later.";
voiceResponse.Say(sayMessage);
voiceResponse.Hangup();
}
}
else
{
sayMessage = "We're sorry. An error occured while redirecting your call. Please try again later.";
voiceResponse.Say(sayMessage);
voiceResponse.Hangup();
}

上述过程效果很好,除非被叫方在被叫方之前挂断,则呼叫者将被路由到下一个人。我想检查呼叫状态以查看是否需要路由。我该怎么做?

一般逻辑在此 Twilio 函数中介绍。

实施语音信箱

/**
*  Voicemail Action URL
* 
*  This Function is used in as the action URL in a Dial. If the call isn't answered or the line is busy, 
*  the call is forwarded to a specified Voicemail URL.
*/
exports.handler = function(context, event, callback) {
// set-up the variables 
// generate the TwiML to tell Twilio how to forward this call
let twiml = new Twilio.twiml.VoiceResponse();
if (event.DialCallStatus === "completed") {
twiml.hangup();
}
else {
twiml.redirect('<URL-TO-VOICEMAIL-TWIML>');
}
// return the TwiML
callback(null, twiml);
};

最新更新