首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >关于进行调用的twilio REST api问题

关于进行调用的twilio REST api问题
EN

Stack Overflow用户
提问于 2011-08-10 23:58:50
回答 1查看 2.9K关注 0票数 2

一个

现在我已经使用Dial verb完成了顺序拨号,但现在我希望我的应用程序执行dial verb不起作用的呼叫,因此我需要REST api.....

我不知道怎么做,我刚开始休息。使用超时是否会使其跳过行?如果超时工作,那么也许我可以让这个工作,但除此之外,我真的没有想法..

另外,如何在REST中获取调用的状态?

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

代码语言:javascript
运行
复制
<?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();
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-08-11 00:37:14

使用PHP helper library

代码语言:javascript
运行
复制
<?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. 向传出调用添加了一个参数数组,以便:

代码语言:javascript
运行
复制
- set the timeout (note: may not be string '15', if this does not work try 15 as a number)
- determine what to do if a machine answers (in this case I chose to hang up)
- determine what to do when the call ends (in this case Twilio requests `'yourNextNumberHandler.php'` to proccess the next numbers)

set

  • 在底部,我们有echo 'The status of the call is '.$call->status;,它会在下面的setQUEUED,RINGING,IN-PROGRESS, COMPLETED,FAILED,BUSY,or NO_ANSWER 中给出一个输出,另一种处理多个调用的方法是执行如下检查

$i=0;$myPhoneList =$i=0(‘14162351836’,'16472871987',18003984785');if ($ call ->status == 'COMPLETED'){ //重新呼叫号码$myPhoneList$i++;}

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

我并没有经常使用twilio,但我希望这对我有所帮助

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7013932

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档