我在使用 Twilio Node.js 库让“Dial”转接调用时遇到一些问题。该库的文档很少,使用“Dial”的唯一示例是电话 session :
.dial({
action:'http://example.com/something.php'
}, function(node) {
node.conference('waitingRoom', {
beep:'false'
});
});
使用它,我已经能够生成与 Dial Documentation 中类似的 XML。使用以下内容:
.dial('number', {
action: 'http://url'
hangupOnStar: true
}, (err, respData) => {
console.log(err);
console.log(respData);
})
这会导致调用立即转发到操作
url。
我还尝试使用其文档中的第三个示例,示例 3:从 Twilio 客户端拨号到电话号码
,它会生成以下 XML:
<Response>
<Dial hangupOnStar="true" callerId="number">
<Number>number to call</Number>
</Dial>
</Response>
通过以下代码:
resp.dial({
hangupOnStar: true,
callerId: 'number'
}, (node) => {
node.number('number')
})
我正在测试的这些数字是有效的数字,而且我也尝试了不同的格式。有什么想法如何让它发挥作用吗?如有任何帮助,我们将不胜感激。
最佳答案
要转接调用,流程可能类似于
- 将您的 Twilio 号码的语音 URL 设置为端点,以便在该 Twilio 号码收到调用时返回 TwiML 响应。
- 在此端点中,TwiML 响应应
<Dial>
<Number>
您要将调用转接至的位置。这将桥接来电,即将其转发到您想要的号码。
我在下面提到了一个可以在
中执行此操作的示例代码app.get("/forwardToMyMobile",function(i_Req,o_Res)
{
var ivrTwilRes = new twilio.TwimlResponse();
var numberToForwardCallTo=i_Req.query.toNumber;
/*In case you want to pass this number as querystring ,
else if its a fixed number you can just hardcode it */
ivrTwilRes.dial({callerId:'+44xxxxxxxx'},
function()
{
this.number(numberToForwardCallTo);
}
)
.record();
o_Res.set('Content-Type','text/xml');
o_Res.send(ivrTwilRes.toString());
});
当您的 Twilio 号码现在收到调用时,它将 Webhook 到您的 Nodejs 服务器应用程序上的“/forwardToMyMobile”并指示 Twilio 转接调用。
关于javascript - Twilio Node.js API - 使用 'Dial' 转发调用时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39551654/