我希望这里有许多 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'] == "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();
?>