关闭
doulu4534 2011-08-10 07: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 08: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

    展开全部

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部