如何在呼叫过程中将Twilio呼叫转发到不同的URL?(使用节点)



我想要Twilio/Node的以下功能:

  1. 我的服务器收到来电,呼叫在我们的自定义客户端上响起;在呼叫过程中的某个时刻(理想情况下可以在接听之前或接听之后工作(,或者如果客户端上没有人接听,则呼叫会转移到另一台服务器(我的CRM提供商(上的webhook,以便CRM可以处理它。或者
  2. 与上面相同,但是传入呼叫将传入呼叫请求发布到我的服务器&我的CRM网络挂钩来电;但我认为这可能不可能,不确定

我可以在服务器上毫无问题地接收Twilio呼叫,也可以在CRM中毫无问题地收到Twilio电话。然而,当我在自定义服务器/客户端上第一次收到呼叫后,试图将其转发到CRM时,它似乎总是毫无疑问地断开连接。请帮忙!

我用来更新呼叫的代码如下。如果将调用直接发送到CRM webhook,则url正常工作。CallSid来自我的自定义客户端,来自来电

client.calls(req.body.CallSid)
.update({method: 'POST', url: 'https://crm.crmprovider.com/ctiapi/xml/cticall/twilio?authtoken=abc'})

感谢您的帮助!

我想我找到了正确的方法。应该使用";动作";用";拨号;然后检查";拨号状态";在动作端点中,并酌情处理各种状态。样本代码:

// On server, receive call. This is the url Twilio is 
// set to post webhook to when call comes in
app.post('/incomingCall', (req, res) => {
const twiml = new VoiceResponse();
// Dial client first; after, call /callAction
// I believe this will call /callAction if call is unanswered for 10 seconds or after a completed call or if there's no client open
const dial = twiml.dial({timeout:10, action: '/callAction'});
const client = 'whateverClientName'
dial.client(client)
res.type('text/xml')
res.send(twiml.toString())
})
app.post('/callAction',(req,res)=>{
const twiml = new VoiceResponse();
// Can set below if for other things like if call not completed, answered, or cancelled
// In this example we say if call's not completed, route call to 3rd party site's webhook to further deal with the ongoing call
if(req.body.DialCallStatus!=='completed'){
twiml.redirect({method: 'POST'},'https://thirdpartywebhook.com/abc')}
else {twiml.hangup()}
res.type('text/xml')
res.send(twiml.toString()) 
})

我没有发现Twilio文档在这方面非常简单,所以希望这能帮助未来的人!

最新更新