Twilio循环播放号码直到呼叫被接听

时间:2016-10-07 18:27:50

标签: twilio twilio-api

我有兴趣骑自行车通过一个号码列表,拨打每个号码直到一个号码。如果我们到达列表的末尾,则从头开始,N次。

我的脚本如下所示:

char packedValues[128];
...
// receive packedValues
...
int encodedValues[1024] = {0};
for (i=0; i<1024; i++) {
    encodedValues[i] = ((packedValues[i/8] & (1 << (i % 8))) != 0);
}

是否有任何方法可以将响应循环N次,或者只是在响应块中对拨号元素进行N次硬编码的解决方案?

1 个答案:

答案 0 :(得分:2)

您可以尝试使用"<Redirect>"。但要谨慎使用它,以确保你不会陷入无限循环(就像任何循环一样)

我还没有在下面测试过这个代码(在NodeJS中),但很快就把它放下来让你了解<Redirect>如何可能用于实现你的需求

const maxRetries = 10;

app.get('/loopOnThisTwiml',
 function(i_Req,o_Res)
   {

      var counter = i_Req.query.loopCounter ;
      if(!counter)
         {
             counter = 0 ;
         }
      else
         {
            counter = counter+1;
          } 

       var ivrTwimlResp = new twilio.TwimlResponse();
       var thisTwimlUrl = "/loopOnThisTwiml?loopCounter=" + counter ; 

       ivrTwilRes.dial({callerId:'+1xxxxxxxxx',action:"hangup.php",method:"GET",timeout:"5"},
             function()
                 {
                      this.number('+11234567890',{url:"/greet.php",method:"GET"});
                 }
            )
            .dial({callerId:'+1xxxxxxxxx',action:"hangup.php",method:"GET",timeout:"5"},
                      function()
                          {
                               this.number('+12234567890',{url:"/greet.php",method:"GET"});
                          }
                     );   

       if(counter < maxRetries)
       {
          ivrTwilRes.redirect( { method : 'GET' } , thisTwimlUrl );
       }

       o_Res.set('Content-Type','text/xml');
       o_Res.send(ivrTwimlResp.toString());
   }
);

上面的代码生成问题中提到的TwiML,并将"<Redirect>"添加到同一个TwiML,直到您到达计数器(maxRetries); maxRetries定义为全局常量。

附注:当您想要连续拨打并优先考虑一个号码而不是另一个号码时,您问题中的TwiML是好的。如果您想同时拨打多个号码并让任何人拨打电话,您还可以查看Simulring

相关问题