2016-09-17 75 views
1

我在使用Twilio Node.js库转接呼叫时遇到了一些麻烦。有此库的小文件,并使用“拨号”的唯一例子是电话会议:Twilio Node.js API - 使用“拨号”转接呼叫时遇到问题

.dial({ 
      action:'http://example.com/something.php' 
     }, function(node) { 
      node.conference('waitingRoom', { 
      beep:'false' 
     }); 
    }); 

利用这一点,我已经能够使用产生类似XML作为Dial Documentation如下:

.dial('number', { 
        action: 'http://url' 
        hangupOnStar: true 
       }, (err, respData) => { 
        console.log(err); 
        console.log(respData); 
       }) 

这会导致该呼叫被立即转发到action网址。

我使用他们的文档,Example 3: Dial to a phone number from Twilio Client,这会产生以下XML的第三个例子也试过:

<Response> 
    <Dial hangupOnStar="true" callerId="number"> 
     <Number>number to call</Number> 
    </Dial> 
</Response> 

通过下面的代码:

resp.dial({ 
        hangupOnStar: true, 
        callerId: 'number' 
       }, (node) => { 
        node.number('number') 
       }) 

这些数字我测试与有效的数字,我也尝试了不同的格式。任何想法如何得到这个工作?任何帮助表示赞赏。

回答

0

要转发呼叫,流程可能是这样的

  1. 设置语音网址为您的Twilio号到端点,让TwiML响应回来时,这Twilio号码接收呼叫。
  2. 在此端点中,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号码接收呼叫现在,它将网络挂接为“/ forwardToMyMobile”您的NodeJS服务器应用程序,并指示Twilio做到这一点提到转移呼叫。