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

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

报告相同问题?

悬赏问题

  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳