I'm deploying Twilio on my website following Javascript Quickstart: https://www.twilio.com/docs/voice/client/javascript/quickstart
I receive multiple calls and register info to my database, if I don't want my Twilio client answers an incoming call, I can hangup using the callSid according to this url: https://www.twilio.com/docs/voice/api/call-resource?code-sample=code-update-a-call-resource-to-end-the-call&code-language=PHP&code-sdk-version=5.x
Code:
<?php
include "../../../twilio_client/vendor/autoload.php";
use Twilio\Rest\Client;
$callsid = $_POST['callsid'];
// put your Twilio API credentials here
$accountSid = 'AC2XXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$authToken = '67XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$twilio = new Client($accountSid, $authToken);
$call = $twilio->calls($callsid)->update(array("status" => "canceled"));
$calla = $twilio->calls($callsid)->fetch();
$parentCall = $calla->parentCallSid;
$call = $twilio->calls($parentCall)->update(array("status" => "completed"));
?>
This works great, so in the same way but If I want to answer an incoming call using the callSid I tried with this according to this url: https://www.twilio.com/docs/voice/api/call-resource?code-sample=code-update-a-call-in-progress-with-twiml
Code:
<?php
include "../../../twilio_client/vendor/autoload.php";
use Twilio\Rest\Client;
$callsid = $_POST['callsid']; //callSid
$usrclient = $_POST['usrclient'];//client connected to receive calls
// put your Twilio API credentials here
$accountSid = 'AC2XXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$authToken = '67XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$twilio = new Client($accountSid, $authToken);
$call = $twilio->calls($callsid)->update(array("twiml" => "<Response><Dial><Client>".$usrclient."</Client></Dial></Response>"));
?>
But it doesn't work, It shows me this error:
[Wed Jan 15 23:14:06.493068 2020] [:error] [pid 30189] [client 190.239.139.220:18718] PHP Fatal error: Uncaught exception 'Twilio\\Exceptions\\RestException' with message '[HTTP 400] Unable to update record: Call is not in-progress.
How can I fix it?
I'd like your help.
Thanks.