我真的不知道爲什麼我的代碼不工作,因爲Twilio的調試器不給我錯誤,所以我不知道該怎麼辦......我試圖在REST中進行順序撥號api使用Twilio所以它應該保持呼叫號碼,直到一個人拿起..Below是我迄今爲止寫的代碼。我正在使用會話來跟蹤呼叫。Twilio REST API順序撥號
文件名:dial.php
<?php
session_start();
require 'Services/Twilio.php';
$version = "2010-04-01";
$arr = array('4167641123','6478604321','9058553456');
$sid = '....';
$token = '...';
$from = '....';
$to = '416.....';
$callback = 'www.site.com/dial.php';
$client = new Services_Twilio($sid, $token, $version);
//if this is our very first call then CallStatus should be empty so it means we can use the emptiness of this variable
//to trigger our very first call
if (!(isset($_REQUEST['CallStatus'])))
{
try {
$call = $client->account->calls->create(
$from,
$arr[0],
'http://demo.twilio.com/welcome/voice/',
array('Timeout' => 1,
'StatusCallback' => $callback)
);
var_dump($call);
} catch (Exception $e) {
var_dump($e);
}
}
// if the CallStatus variable is not empty then the else statement will execute
else
{
//if this part of code runs for the first time, it means this is our 2nd call because the 1st person did not pick up
//this means the second number in the array will be called
//each time this statement runs it adds a 1 to the index of the array but if the last index number called was the final and
//last number in the array, then this statement wont run and instead session at the bottom if statement will be initialized to 0
//so that if this script is ran again it will start off from the first number in the array
if (!($_SESSION['X']>=count($arr)-1) && isset($_REQUEST['CallStatus']) && ($_REQUEST['CallStatus']=='failed'|| $_REQUEST['CallStatus']=='no-answer' || $_REQUEST['CallStatus']=='busy'))
{
$_SESSION['X']=$_SESSION['X']+1;
try {
$call = $client->account->calls->create(
$from,
$arr[SESSION['X']],
'http://demo.twilio.com/welcome/voice/',
array('Timeout' => 1,
'StatusCallback' => $callback)
);
var_dump($call);
} catch (Exception $e) {
var_dump($e);
}
}
//initializes the session to 0 because if we have reached to this else statement,
//then it means the if statement above did not run and we have already called the last person
//in the phone number array so we are at an end and we must close the program
//by leaving session at 0 for the next trial to run properly
else
{
$_SESSION['X']=0;
}
}
使用PHP和twilio的撥號動詞我有這等文件相同,順序diallnig寫,撥號動詞的參數,允許它通過在我的情況數組的索引,但我不知道如何傳遞數組索引參數....任何想法?
<?php
// Set the numbers to call
$numbers = array("<number to call 1>", "<number to call 2>", "<number to call n>");
$number_index = isset($_REQUEST['number_index']) ? $_REQUEST['number_index'] : "0";
$DialCallStatus = isset($_REQUEST['DialCallStatus']) ? $_REQUEST['DialCallStatus'] : "";
header("content-type: text/xml");
// Check the status of the call and
// that there is a valid number to call
if($DialCallStatus!="completed" && $number_index<count($numbers)){
?>
<Response>
<Dial action="attempt_call.php?number_index=<?php echo $number_index+1 ?>">
<Number url="screen_for_machine.php">
<?php echo $numbers[$number_index] ?>
</Number>
</Dial>
</Response>
<?php
} else {
?>
<Response>
<Hangup/>
</Response>
<?php
}
?>
'SESSION ['X'] = 0;'那是什麼語言? – hakre