开发者

Twilio and PHP?

I am hoping there are numerous Twilio developer here along with PHP scripters...I am trying to edit a basic Twimlet FindMe and I am really stuck from a while...I cant find any threads on editing it and I do think there is quite a lot of use for Twimlets and should be documented more as many beginners use it as a starting point. For my case, I need help editing the Twimlet with source below so I can manually add the phone numbers I would like to call in order till one of the people pick up..The current code uses input boxes to gather the info which I dont want to use..I have spent numerous hours trying to get this to work but I am stuck....I tried removing the REQUEST and putting numbers in there but it didnt work and I am beginner at using Twilio so I need a hand. Thanks a lot.

<?php

     require "twilio-lib.php";

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

    // init as array, if it's not
    if(!is_array($_REQUEST['PhoneNumbers']))
        $_REQUEST['PhoneNumbers'] = array($_REQUEST['PhoneNumbers']);

    // remove empty entries from PhoneNumbers
    $_REQUEST['PhoneNumbers'] = @array_filter($_REQUEST['PhoneNumbers']);

    // verify no more than 10 numbers given
    if(count($_REQUEST['PhoneNumbers']) > 10)
        $_REQUEST['PhoneNumbers'] = array_splice($_REQUEST['PhoneNumbers'], 10);

    // if The Dial flag is present, it means we're returning from an attempted Dial
    if(isset($_REQUEST['Dial']) && ($_REQUEST['DialStatus'] == "answered" || $_REQUEST['DialCallStatus'] == "completed")) {

        // answered call, so just hangup
        $response->addHangup();

    } else {

        // No dial flag, or anything other than "answered", roll on to the next (or first, as it may be) number

        // resort the PhoneNumbers array, in case anything untoward happened to it        
        sort($_REQUEST['PhoneNumbers']);

        // get the next number of the array
        if(!$nextNumber = @array_shift($_REQUEST['PhoneNumbers'])) {

            // if no phone numbers left, redirect to the FailUrl

          开发者_JS百科  // FailUrl found, so redirect and kill the cookie
            if(strlen($_REQUEST["FailUrl"])) {
                header("Location: {$_REQUEST["FailUrl"]}");
                die;
            } else {

                // no FailUrl found, so just end the call
                $response->addHangup();

            }

        } else {

            // re-assemble remaining numbers into a QueryString, shifting the 0th off the array
            $qs = "FailUrl=".urlencode($_REQUEST['FailUrl'])."&Timeout=".urlencode($_REQUEST['Timeout'])."&Message=".urlencode($_REQUEST['Message']);
            foreach($_REQUEST['PhoneNumbers'] AS $number)
                $qs .= "&PhoneNumbers%5B%5D=" . urlencode($number);

            // add a dial to the response
            $dial = $response->addDial(array("action"=>"{$_SERVER['SCRIPT_URI']}?Dial=true&$qs", "timeout"=>$_REQUEST['Timeout'] ? $_REQUEST['Timeout'] : 60));

            // add the number to dial
            $dial->addNumber($nextNumber, array("url"=>"whisper?Message=".urlencode($_REQUEST['Message'])));

        }

    } 

    // send the response
    $response->Respond();

?>


The simplest solution would be to set $_REQUEST['PhoneNumbers'] at the top of the script.

$_REQUEST['PhoneNumbers'] = array('1235556789', '1235551234');

In normal operation, the Twimlet expects the incoming request to provide the array - like this:

http://twimlets.com/findme?PhoneNumbers%5B0%5D=1235556789&PhoneNumbers%5B1%5D=1235551234&

By setting $_REQUEST['PhoneNumbers] at the top of the script, you're able to manually set the list of numbers without having to change the rest of the code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜