2011-06-08 45 views
1

我希望有许多Twilio开发人员在这里与PHP脚本编写人员...我想编辑一个基本的Twimlet FindMe,我真的坚持了一段时间...我无法找到任何线程编辑它,我认为对于Twimlets有相当多的用途,应该记录更多,因为许多初学者使用它作为起点。对于我的情况,我需要帮助编辑Twimlet的源代码下面,所以我可以手动添加电话号码,我想调用,直到其中一个人拿起..当前代码使用输入框来收集信息,我不想要使用..我花了很多小时试图让这个工作,但我卡住....我试图删除请求,并把数字在那里,但它没有工作,我是初学者在使用Twilio,所以我需要一只手。非常感谢。Twilio和PHP?

<?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 

      // 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(); 

?> 

回答

1

最简单的解决方案是在脚本的顶部设置$_REQUEST['PhoneNumbers']

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

在正常操作中,Twimlet预计传入的请求提供阵列 - 这样的:

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

通过在脚本的顶部设置$_REQUEST['PhoneNumbers],你能够手动设置数字列表无需更改代码的其余部分。