简体   繁体   English

在Twilio中创建循环

[英]Create Round Robin in Twilio

I've searched here and in many forums. 我已经在这里和许多论坛中搜索过。 Here's what I'm trying to do. 这就是我想要做的。

I'm trying to create a system on php/mysql so a twilio phone number on a page will round robin through a list of phone numbers. 我正在尝试在php / mysql上创建一个系统,因此页面上的twilio电话号码将循环浏览电话号码列表。

The numbers a specific twilio number relates to is this: 一个特定的twilio号码涉及的号码是这样的:

555-1212 555-1212

555-3434 555-3434

555-5656 555-5656

555-7878 555-7878

So it would be something like this: 所以会是这样的:

twilio number called XX time : which number is dialed twilio号码称为XX时间:拨打哪个号码

1 : 555-1212 1:555-1212

2 : 555-3434 2:555-3434

3 : 555-5656 3:555-5656

4 : 555-7878 4:555-7878

5 : 555-1212 5:555-1212

6 : 555-3434 6:555-3434

etc. 等等

Any advice or pointing me in the correct direction, i would truly appreciate it. 任何建议或正确的方向,我将不胜感激。 I'm not sure how to or where to turn to help get this done. 我不确定如何或在哪里寻求帮助。

Twilio evangelist here. Twilio的传播者在这里。

I'd suggest checking out the Call Screening HowTo which shows you how to build almost exactly what your describing in PHP. 我建议您检查一下“ 呼叫筛选方法” ,该方法向您展示了如何完全构建您在PHP中的描述。

I believe the only change you would have to make to the sample code is to this line of code: 我相信您对示例代码所做的唯一更改就是对以下代码行的更改:

$number_index = isset($_REQUEST['number_index']) ? $_REQUEST['number_index'] : "0";

This line checks to see if a parameter named number_index is present and if not sets it to zero. 此行检查是否存在名为number_index的参数,如果不存在则将其设置为零。

What you will need to change is to add a second check to see if the number_index is also equal to the last of the array and if it is, set the value to zero so the loop continues. 您需要更改的是添加第二项检查,以查看number_index是否也等于数组的最后一个,如果是,则将值设置为零,以便循环继续进行。

$number_index = isset($_REQUEST['number_index']) ? $_REQUEST['number_index'] : "0";
if ($number_index >= count($number)) $number_index = 0;

If course doing this will create an infinite loop, so I'd also suggest adding a way to short circuit that loop. 如果这样做的话会创建一个无限循环,所以我也建议您添加一种短路该循环的方法。 You could add an additional parameter that lets you track how many times you've looped through your array and once that reaches a max, kills the loop. 您可以添加一个附加参数,该参数可让您跟踪遍历数组的次数,一旦达到最大值,就会终止循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM