2

一种

现在我使用 Dial 动词进行顺序拨号,但现在我希望我的应用程序执行拨号动词不起作用的呼叫,因此我需要 REST api .....

我不知道该怎么做,我是 REST 新手。使用超时是否会使其跳过行?如果超时有效,那么也许我可以完成这项工作,但除此之外我真的没有任何想法..

另外,如何在 REST 中获取通话状态?

假设我的代码看起来像这样,我将如何更改它以获取呼叫状态并设置呼叫超时?

<?php
// Include the Twilio PHP library
require 'Services/Twilio.php';
// Twilio REST API version
$version = "2010-04-01";
// Set our Account SID and AuthToken
$sid = 'AC123';
$token = 'abcd';
// A phone number you have previously validated with Twilio
$phonenumber = '4151234567';
// Instantiate a new Twilio Rest Client
$client = new Services_Twilio($sid, $token, $version);
try {
// Initiate a new outbound call
$call = $client->account->calls->create(
$phonenumber, // The number of the phone initiating the call
'5101234567', // The number of the phone receiving call
'http://demo.twilio.com/welcom/voice/'
);
echo 'Started call: ' . $call->sid;
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
4

1 回答 1

4

使用PHP 帮助程序库

<?php
// Include the Twilio PHP library
require 'Services/Twilio.php';
// Twilio REST API version
$version = "2010-04-01";
// Set our Account SID and AuthToken
$sid = 'AC123';
$token = 'abcd';
// A phone number you have previously validated with Twilio
$phonenumber = '4151234567';
// Instantiate a new Twilio Rest Client
$client = new Services_Twilio($sid, $token, $version);
try {
// Initiate a new outbound call
$call = $client->account->calls->create(
$phonenumber, // The number of the phone initiating the call
'5101234567', // The number of the phone receiving call
'http://demo.twilio.com/welcom/voice/',
array('timeout'=>'15','ifmachine'=>'hangup','status_callback'=>'yourNextNumberHandler.php')
);
echo 'Started call: ' . $call->sid;
echo 'The status of the call is '.$call->status;
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
?>

此代码基于https://github.com/twilio/twilio-php/blame/master/docs/api/rest.rst中的文档

所以我做了几件事:

  1. 向拨出呼叫添加了一组参数,以便:

    • 设置超时(注意:可能不是字符串'15',如果这不起作用,请尝试将 15 作为数字)

    • 确定如果机器应答时该怎么办(在这种情况下我选择挂断)

    • 确定通话结束时要做什么(在这种情况下,Twilio 请求'yourNextNumberHandler.php'处理下一个数字)

  2. 在底部,我们echo 'The status of the call is '.$call->status;应该在以下一组中为您提供输出QUEUED,RINGING,IN-PROGRESS, COMPLETED,FAILED,BUSY,or NO_ANSWER 一种处理多个呼叫的方法是进行检查,例如

    $i=0; $myPhoneList = array('14162351836','16472871987',18003984785'); if ($call->status == 'COMPLETED'){ //向号码发起新呼叫 $myPhoneList[$i++]; }

'yourNextNumberHandler.php'而不是使用status_callback参数的回调

我没有太多使用twilio,但我希望这会有所帮助

于 2011-08-10T16:37:14.490 回答