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