代码之家  ›  专栏  ›  技术社区  ›  sigil

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

  •  0
  • sigil  · 技术社区  · 8 年前

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

    //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 回复  |  直到 8 年前
        1
  •  1
  •   philnash    8 年前

    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);
    });
    

    如果有帮助,请告诉我。

    推荐文章