doulu4534 2011-08-10 15:58
浏览 237
已采纳

twilio REST api打电话的问题

A

Right now I have sequential dialing being done using Dial verb but now I want my application to do the calling for which the dial verb does not work and thus I need the REST api.....

I can't figure out how to do this, I am new to REST. Does using a timeout make it skip lines? If timeout works then perhaps I can make this work but other than that I really have no ideas..

Also, how can I get the status of the call in REST?

Lets say my code looks like this, how would I change it to get the status of the call and set a timeout on the call?

<?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();
}
  • 写回答

1条回答 默认 最新

  • duanhe8280 2011-08-10 16:37
    关注

    Using the 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();
    }
    ?>
    

    This code is based on the documentation in https://github.com/twilio/twilio-php/blame/master/docs/api/rest.rst

    So I did a couple things:

    1. Added an array of parameters to the outgoing call in order to:

      • 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)

    2. On the bottom we have echo 'The status of the call is '.$call->status; which should give you an out put in one of the following setQUEUED,RINGING,IN-PROGRESS, COMPLETED,FAILED,BUSY,or NO_ANSWER another way to process multiple calls would be to do a check like

      $i=0; $myPhoneList = array('14162351836','16472871987',18003984785'); if ($call->status == 'COMPLETED'){ //Place a new call to number $myPhoneList[$i++]; }

    instead of using the callback 'yourNextNumberHandler.php' of status_callback parameter

    I haven't used twilio that much, but I hope this helps

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决