gpt4 book ai didi

php - Twilio REST API 顺序拨号

转载 作者:搜寻专家 更新时间:2023-10-31 21:43:42 25 4
gpt4 key购买 nike

我真的不明白为什么我的代码不工作,因为 Twilio 的调试器没有给我错误,所以我不知道该怎么做......我正在尝试使用 Twilio 在 REST api 中进行顺序拨号,所以它应该按顺序调用号码,直到有人接听为止。下面是我到目前为止编写的代码。我正在使用 session 来跟踪调用。

文件名: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 的 Dial 动词编写的顺序 diallnig,Dial 动词的参数允许它传递数组索引,但在我的情况下,我不知道如何传递数组索引参数... .有什么想法吗?

<?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; 并没有按照您的预期执行。如果这是一个 session 变量,它应该写成 $_SESSION['X']=0;

要发现这些问题,请向最高级别启用错误报告,然后将错误记录到一个文件中,然后观察该文件。它会给你一些提示。

参见 Error Handling and Logging Docs .

关于php - Twilio REST API 顺序拨号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7110267/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com