I am using the Twilio REST API to make reminder calls and I’m not getting the correct CallStatus.
When a call is ignored or receives no answer, I am still getting completed as a status in both $_POST['CallStatus'] as well as in /2010-04-01/Accounts/XXX/Calls/XXX.json that I call in the StatusCallback parameter for the API request.
Below is my code :
$client = new Services_Twilio($account_sid, $auth_token);
try
{
$options = array("StatusCallback" => site_url()."/callsms/endofcall/");
$call = $client->account->calls->create(
'+1xxxxxxxxxx', // From a valid Twilio number
'+1xxxxxxxxxx', // Call this number
site_url()."/callsms/call_user_xml/",
$options
);
//return $call->sid;
} catch (Exception $e) {
echo 'Error starting phone call: ' . $e->getMessage() . "\n";
}
In the endofcall page I have written :
$twilio_configs = $this->config->item('twilio');
$account_sid = $twilio_configs['account_sid'];
$auth_token = $twilio_configs['auth_token'];
// set URL and other appropriate options
$curl = 'https://'.$account_sid.':'.$auth_token.'@api.twilio.com/2010-04-01/Accounts/'.$account_sid.'/Calls/'.$csid.'.json';
$content = file_get_contents($curl);
$result = json_decode($content);
if($result->status=='completed')
{
//DATABASE ENTRY
}
Please help!
If a call goes to voicemail, it will still show up as
completed. It will only show up asno-answerif you don’t have voicemail configured and ignore the call.