我希望这里有很多Twilio开发人员和PHP脚本编写人员。。。我正在尝试编辑一个基本的Twimlet FindMe,我真的被卡住了一段时间。。。我找不到任何关于编辑它的线索,我确实认为Twimlets有很多用处,应该更多地记录下来,因为许多初学者都把它作为起点。就我的情况而言,我需要帮助编辑以下来源的Twimlet,这样我就可以手动添加我想拨打的电话号码,直到其中一个人接听为止。。当前代码使用输入框来收集我不想使用的信息。。我花了很多时间试图让它发挥作用,但我被卡住了。。。。我试着删除REQUEST并在其中输入数字,但没有成功,而且我是Twilio的初学者,所以我需要帮助。非常感谢。
<?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'] == "answerswered" || $_REQUEST['DialCallStatus'] == "completed")) {
// answered call, so just hangup
$response->addHangup();
} else {
// No dial flag, or anything other than "answerswered", 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();
?>
最简单的解决方案是在脚本顶部设置$_REQUEST['PhoneNumbers']
。
$_REQUEST['PhoneNumbers'] = array('1235556789', '1235551234');
在正常操作中,Twimlet期望传入的请求提供数组,如下所示:
http://twimlets.com/findme?PhoneNumbers%5B0%5D=1235556789&PhoneNumbers%5B1%5D=1235551234&
通过在脚本顶部设置$_REQUEST['PhoneNumbers]
,您可以手动设置数字列表,而无需更改代码的其余部分。