【问题标题】:twilio REST api question for making calls用于拨打电话的 twilio REST api 问题
【发布时间】:2011-08-10 15:58:50
【问题描述】:

一个

现在我正在使用 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();
}

【问题讨论】:

  • 顶部的

标签: php rest twilio


【解决方案1】:

使用PHP helper library

<?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-&gt;status;,它应该会给你一个输出到以下集合之一QUEUED,RINGING,IN-PROGRESS, COMPLETED,FAILED,BUSY,or NO_ANSWER 另一种处理多个调用的方法是进行检查

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

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

我没怎么用过 twilio,但我希望这会有所帮助

【讨论】:

  • 这不是我需要的...如果我需要检查通话状态,我将如何发布 StatusCallback?我已经知道响应的格式是 xml...你熟悉 Twilio 吗?
  • 我用您提供的代码替换了我的呼叫信息,但代码不起作用,它不拨打号码或显示xml。
  • 它确实调用了但超时不起作用我想一旦它传递给yournextnumber.php就处理超时?状态除了 QUEUED 外没有显示任何内容。 :( T_T
  • 我认为echo 'The status of the call is '.$call-&gt;status; 在实际启动呼叫之前处理得太早了(也就是排队)。尝试从参数列表中删除,'ifmachine'=&gt;'hangup','status_callback'=&gt;'yourNextNumberHandler.php',然后再进行其他操作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-17
  • 1970-01-01
  • 2018-07-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多