Twilio在电话号码间循环,直到接听为止
我感兴趣的是循环浏览一系列号码,拨每个号码直到有一个接上。如果我们到达列表的末尾,从开始处重新开始,N次 我的脚本如下所示:Twilio在电话号码间循环,直到接听为止,twilio,twilio-api,Twilio,Twilio Api,我感兴趣的是循环浏览一系列号码,拨每个号码直到有一个接上。如果我们到达列表的末尾,从开始处重新开始,N次 我的脚本如下所示: <Response> <Dial action="hangup.php" timeout="5"> <Number url="greet.php"> 123-456-7890 </Number> </Dial> <Dial ac
<Response>
<Dial action="hangup.php" timeout="5">
<Number url="greet.php">
123-456-7890
</Number>
</Dial>
<Dial action="hangup.php" timeout="5">
<Number url="greet.php">
223-456-7890
</Number>
</Dial>
</Response>
123-456-7890
223-456-7890
有没有办法将响应循环N次,或者解决方案是在响应块中对拨号元素进行N次硬编码?您可以尝试使用。但要小心使用它,以确保不会以无限循环结束(任何循环都是如此)
我还没有在下面的NodeJS中测试过这段代码,但我很快就把它写下来,让您了解如何潜在地使用
来实现您的需求
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());
}
);
const maxRetries=10;
app.get('/loopOnThisTwiml',
功能(输入请求、输出请求)
{
var counter=i_Req.query.loopCounter;
如果(!计数器)
{
计数器=0;
}
其他的
{
计数器=计数器+1;
}
var ivrTwimlResp=新的twilio.TwimlResponse();
var thisTwimlUrl=“/looponhistwiml?loopCounter=“+计数器;
拨号({callerId:'+1xxxxxx',操作:“hangup.php”,方法:“GET”,超时:“5”},
函数()
{
这个.number('+11234567890',{url:“/greet.php”,方法:“GET”});
}
)
.dial({callerId:'+1xxxxxx',操作:“hangup.php”,方法:“GET”,超时:“5”},
函数()
{
这个.number('+12234567890',{url:“/greet.php”,方法:“GET”});
}
);
if(计数器<最大重试次数)
{
重定向({method:'GET'},thisTwimlUrl);
}
o_Res.set('Content-Type','text/xml');
o_Res.send(ivrTwimlResp.toString());
}
);
上面的代码生成问题中提到的TwiML,并将“
添加到同一TwiML中,直到到达计数器(maxRetries);maxRetries定义为全局常量
旁注:当你想连续拨号并且优先选择一个号码而不是另一个号码时,你问题中的TwiML是好的。如果您想同时拨打多个号码并让任何人接听电话,您也可以查看。您可以尝试使用。但要小心使用它,以确保不会以无限循环结束(任何循环都是如此)
我还没有在下面的NodeJS中测试过这段代码,但我很快就把它写下来,让您了解如何潜在地使用
来实现您的需求
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());
}
);
const maxRetries=10;
app.get('/loopOnThisTwiml',
功能(输入请求、输出请求)
{
var counter=i_Req.query.loopCounter;
如果(!计数器)
{
计数器=0;
}
其他的
{
计数器=计数器+1;
}
var ivrTwimlResp=新的twilio.TwimlResponse();
var thisTwimlUrl=“/looponhistwiml?loopCounter=“+计数器;
拨号({callerId:'+1xxxxxx',操作:“hangup.php”,方法:“GET”,超时:“5”},
函数()
{
这个.number('+11234567890',{url:“/greet.php”,方法:“GET”});
}
)
.dial({callerId:'+1xxxxxx',操作:“hangup.php”,方法:“GET”,超时:“5”},
函数()
{
这个.number('+12234567890',{url:“/greet.php”,方法:“GET”});
}
);
if(计数器<最大重试次数)
{
重定向({method:'GET'},thisTwimlUrl);
}
o_Res.set('Content-Type','text/xml');
o_Res.send(ivrTwimlResp.toString());
}
);
上面的代码生成问题中提到的TwiML,并将“
添加到同一TwiML中,直到到达计数器(maxRetries);maxRetries定义为全局常量
旁注:当你想连续拨号并且优先选择一个号码而不是另一个号码时,你问题中的TwiML是好的。如果您想同时拨打多个号码,让任何人接听电话,您也可以看看。有趣的方法。我想这唯一的缺点是每个周期之间都会有一些延迟,因为必须发出一个新的HTTP请求。我想这唯一的缺点是每个周期之间都会有一些延迟,因为必须发出一个新的HTTP请求。