开发者

twilio Rest api call making not working

开发者 https://www.devze.com 2023-03-27 14:31 出处:网络
I am really frustrated as I can\'t figure out why my Twilio callStatus for the REST api is not working :S...Any ideas?

I am really frustrated as I can't figure out why my Twilio callStatus for the REST api is not working :S...Any ideas?

It makes a call at stackoverflow.php but when it hits the yournextnumber.php it doesn't execute the if statements because most likely there is no value in the callStatus any idea why the status is not being sent?

stackoverflow.php

<?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 = '....';
$token = '....';


// A phone number you have previously validated with Twilio
$phonenumber = '....';

// 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
    '....', // The number of the phone receiving call
    'http://demo.twilio.com/welcome/voice/',
    array('Timeout'=>5,
          'IfMachine'=>'hangup',
          'StatusCallback'=>'http://example.com/twilio-twilio-php-28c214f/yourNextNumberHandler.php'));

  echo 'Started call: ' . $call->sid;
  echo 'The status of the call is '.$call->status;
} catch (Exception $e) {
  echo 'Error: ' . $e->getMessage();
}
?>

yourNextNumber.php

  <?php
// Include the Twilio PHP library
    require 'Services/Twilio.php';

    // Twilio REST API version
    $version = "2010-04-01";
    print_r()//error_log() $_REQUEST
    // Set our Account SID and AuthToken
    $sid = '....';
    $token = '....';


// A phone number you have previously validated with Twilio
    $phonenumber = '....';

// Instantiate a new Twilio Rest Client
$client = new Services_Twilio($sid, $token, $version);


if ($_REQUEST['CallStatus']=='completed')
{

try {
// Initiate a new outbound call
$call = $client->account->calls->create(
$phonenumber, // The number of the phone initiating the call
'..', // The number of the phone receiving call
'http://demo.twilio.com/welcome/voice/',
array('Timeout'=>5)
);

}
catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}

}   



if ($_REQUEST['CallStatus']=='no-answer')
{

try {
// Initiate a new outbound call
$call = $client->account->calls->create(
$phonenumber, // The number of the phone initiating the call
'...', // The number of the phone receiving call
'http://demo.twilio.com/welcome/voice/',
array('Timeout'=>5)
);

}
catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
}


if ($_REQUEST['CallStatus']=='ringing')
{

try {
// Initiate a new outbound call
$call = $client->account->calls->create(
$phonenumber, // The number of the phone initiating the call
'....', // The number of the phone receiving call
'http://demo.twilio.com/welcome/voice/',
array('Timeout'=>5)
);

}
catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
}


if ($_REQUEST['CallStatus']=='busy')
{

try {
// Initiate a new outbound call
$call = $client->account->calls->create(
$phonenumber, // The number of the phone initiating the call
'...', // The number of the phone receiving call
'http://demo.twilio.com/welcome/voice/',
array('Timeout'=>5)
);

}
catch (Exception $e) {
echo 'Erro开发者_开发知识库r: ' . $e->getMessage();
}
}

if ($_REQUEST['CallStatus']=='queued')
{

try {
// Initiate a new outbound call
$call = $client->account->calls->create(
$phonenumber, // The number of the phone initiating the call
'....', // The number of the phone receiving call
'http://demo.twilio.com/welcome/voice/',
array('Timeout'=>5)
);

}
catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
}

    ?>


Have you checked your PHP error log? You need a catch for each of those try blocks.


Instead of using if statements for the CallStatus processing, convert it to a switch statement. That way you can set a default case that gets performed regardless of the status. Then you could easily log (or notify someone) when you find an unexpected CallStatus.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号