Reputation: 323
I am using the following code to initiate calls. If the call is not answered, I want to capture this event (unanswered call) and call an alternative phone number. Currently with the below code, if a phone is not answered once, it is calling 3 times and then giving up without calling the StatusCallback URL at all. What am I doing wrong? (I can call the URL from browser with parameters.)
Thx a lot.
// Piece of PHP code making the call $this->info('Calling providers:');
$account_sid = ...
$auth_token = ...
$client = new \Services_Twilio($account_sid, $auth_token);
try {
$this->info ('Calling phone... ');
// Make a call
$call = $client->account->calls->create('+448008021203', '+'.$phone_to_call, 'http://xyz/order_msg.html', array(
'Method' => 'GET',
"StatusCallback" => "http://xyz/phone_events?alt_phone=".$alternate_phone,
"StatusCallbackMethod" => "GET",
"StatusCallbackEvent" => array("completed"),
'Record' => 'false',
));
$this->info('Called with :' . $call);
}
}catch (\Exception $e) {
$this->error('Exception :'.$e->getMessage());
}
// StatusCallback URL = http://xyz/phone_events PHP-Laravel code
$status =Input::get('CallStatus');
$alternate_phone =Input::get('alt_phone');
if (! empty($alternate_phone) && ! empty($status)) {
if ($status != "completed" || $status != "queued") {
/* start the next call */
$account_sid = ...;
$auth_token = ...;
$client = new \Services_Twilio($account_sid, $auth_token);
try {
$client->account->calls->create('+448008021203', '+'.$alt_phone, 'http://xyz/order_msg.html', array(
'Method' => 'GET',
"StatusCallback" => "http://xyz/phone_events,
"StatusCallbackMethod" => "GET",
"StatusCallbackEvent" => array("completed"),
'Record' => 'false',
));
} catch (\Exception $e) {
$log->error('Phone Events Error: ' . $e);
}
}
}
Upvotes: 1
Views: 54