In my application, I need to do Twilio holding and retrieving back a call. I researched and got this link : https://www.twilio.com/docs/api/rest/change-call-state.
javascript
function holdCall() { // hold a call
var callSid = connection.parameters.CallSid;
$.ajax({
url: "http://www.domain.com/phone/phone_ajax.php",
type: 'POST',
data: {
callSid: callSid
},
success: function(data) {
console.log(data);
},
error: function() {
},
complete: function() {
}
});
}
The ajax call will go to this page.
phone_ajax.php
require_once ( "http://www.domain.com/phone/phone_api/vendor/autoload.php");
use TwilioRestClient;
use TwilioJwtClientToken;
// initialize
if ( $_POST['callSid'] ) { // hold a call
$client = new Client($twilioAccountSID, $twilioAuthenticationToken);
$calls = $client->calls->read(
array("ParentCallSid" => $_POST['callSid'])
);
// Loop over the list of calls and echo a property for each one
foreach ($calls as $call) {
// This will return child call sid e.g CA9ccxxxxxxxxxx
$twilioCall = $client
->calls($call->sid)
->update(
array(
"url" => "http://demo.twilio.com/docs/voice.xml",
"method" => "POST"
)
);
echo $twilioCall->to;
}
}
I tried calling to my mobile phone, picked up the call and clicked Hold button. The call in my browser got ended and the call in my phone didn't ended up (I can hear hold music in my phone). When I again click on the Hold button in the dialpas, the call should be retrieved back. How can I achieve this?
Can anyone help me to do this? Thanks in advance.
See Question&Answers more detail:os