2016-09-17 73 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做到這一點提到轉移呼叫。