开发者

twilio php Sequential Dialing

I 开发者_StackOverflow社区am planning on building a sequential dialing twilio program and so far I have a little bit of code and I am a little stuck....What should I do or can I do to make Twilio call a number, if that number doesnt pick up call the next number in the array, if that number doesnt pick up call another number....

<?php
    require "twilio.php";

    // initiate response library
    $response = new Response();

    header("content-type: text/xml");
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";


$PhoneNumbers= array('4167841543','6478704858');



$variableToCall=$PhoneNumbers[0];

    if(($_REQUEST['DialStatus'] == "busy" || $_REQUEST['DialCallStatus'] == "no-answer" || $_REQUEST['DialCallStatus'] == "failed" || $_REQUEST['DialCallStatus'] == "canceled")) {

       $variableToCall=$PhoneNumbers[1];

    }




?>


<Response>
<Dial> <?php echo $variableToCall ?> </Dial>

</Response>


To best use Twilio you need to both send web service requests (REST) as well as provide URLs to which Twilio will post call data and get further instructions (TwiML)

You make Initial Call with REST. http://www.twilio.com/docs/api/rest/making_calls. If you need later calls to wait for the initial call to finish. Then your script will have to wait for the first call to complete before creating another call. Since Twilio can't post to your running script, you will have to track the status of the call using some sort of shared storage mechanism.

Twilio will be posting to the url you provide in the call request. That url will have a script which will update the call status in your shared storage. Your other script will be checking the status and waiting until your call completes.


If I understand your use case directly, you are looking to call one phone until it times out, then dial another number, and then finally one last number which you are storing in an array in your PHP code.

While you can do this in session, I think that you may find implementation easier by using the callback argument in the calls->create method. For example, you currently use the callback method to refer to our default voice welcome like so:

https://gist.github.com/1155487/919a93ed2ea9f5c8eb9f7cb75d99951f76430f2b

An easy way to pass the current index of your script would be altering the third callback argument to reference your own script:

https://gist.github.com/1155487/533223a4199dacc2dffff3bb5a6ceb107f94a697


You should also take a look at this example application for more detail on making outbound phone calls. It illustrates a lot of the steps you need to take.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜