尝试使用呼叫()。更新以转移到会议室时出现11205错误

时间:2018-01-22 23:30:51

标签: node.js express heroku twilio

我正在尝试将入站呼叫者转移到会议室:

//this is the endpoint for the voice webhook
app.post('/voice',(req,res)=>{
    sid=req.body.CallSid;
    conferenceName="test conference room";
    params={'conferenceName':conferenceName};
    url='https://appname.herokuapp.com/addToConference?conferenceName=test';
    console.log('now updating inbound call sid '+sid);
    client.calls(sid).update({
        url:url,
        method:'GET'
    });

});

//this is the endpoint for adding a caller to a conference
app.get('/addToConference',(req,res)=>{
    var conferenceName=req.query.conferenceName;
    const response=new VoiceResponse();
    response.say("Now connecting you to conference "+conferenceName);
    dial=response.dial();
    dial.conference(conferenceName);
    responseTwiml=response.toString();
    console.log("responseTwiml: "+responseTwiml);
    res.send(responseTwiml);
});

控制台日志记录显示已达到.update()来电:

now updating inbound call sid 9j92f892309

但是Twilio调试器显示11205错误,其中url为https://appname.herokuapp.com/voice/。控制台日志未显示Now connecting you to conference test,因此我猜测未到达/addToConference端点。 Heroku错误日志显示Request timeout错误。

如何到达终端并将入站呼叫者丢弃到电话会议中?如果重要,我希望应用程序然后呼叫其他人,与他们交互,然后将该呼叫接收者转移到呼入呼叫者正在等待的会议。

1 个答案:

答案 0 :(得分:1)

Twilio开发者传道者在这里。

这里有几个问题。首先,11205 error是因为呼叫到/voice端点的超时。这里的问题是你永远不会从res函数返回任何东西。您可以通过在该函数末尾调用res.send('')来修复该问题。

...然而

根本不需要进行重定向。您可以使用初始webhook响应将呼叫者丢入会议并拨打另一方。您可以使用以下代码执行此操作:

app.post('/voice',(req,res)=>{
    conferenceName="test conference room";
    url='https://appname.herokuapp.com/addToConference?conferenceName=' + conferenceName;
    client.calls.create({
        from: YOUR_TWILIO_NUMBER,
        to: THE_OTHER_PERSON,
        url: url
    });
    const response=new VoiceResponse();
    response.say("Now connecting you to conference "+conferenceName);
    dial=response.dial();
    dial.conference(conferenceName);
    responseTwiml=response.toString();
    res.set('Content-Type': 'text/xml');
    res.send(responseTwiml);
});

为此你仍然需要/addToConference端点,它只是将另一个呼叫者添加到会议中,如下所示:

app.get('/addToConference',(req,res)=>{
    var conferenceName=req.query.conferenceName;
    const response=new VoiceResponse();
    response.say("Now connecting you to conference "+conferenceName);
    dial=response.dial();
    dial.conference(conferenceName);
    responseTwiml=response.toString();
    console.log("responseTwiml: "+responseTwiml);
    res.send(responseTwiml);
});

您也可以首先按照您想要的方式重定向来电,但不是modifying the call with the REST API,而是使用TwiML <Redirect>动词。这看起来像这样:

app.post('/voice',(req,res)=>{
    conferenceName="test conference room";
    url='https://appname.herokuapp.com/addToConference?conferenceName=' + conferenceName;
    client.calls.create({
        from: YOUR_TWILIO_NUMBER,
        to: THE_OTHER_PERSON,
        url: url
    });
    const response=new VoiceResponse();
    response.redirect(url);
    responseTwiml=response.toString();
    res.set('Content-Type': 'text/xml');
    res.send(responseTwiml);
});

让我知道这是否有帮助。