Twilio,In Incoming calls when I queue the call second time call status gets completed.But the hold music is still play on both side of the call.Here is my code to update calls.(First time hold unhold is working fine but when try to hold the second time is goes on the hold but when I fetch the call info by callsid the callstatus gets completed.)
function hold_call($parentCallSid,$action='hold'){
echo $parentCallSid;
$admin_id = get_current_user_id();
$childCalls = $this->client->calls->read(array("ParentCallSid" => $parentCallSid));
$childCallSid = $childCalls[0]->sid;
$rr = array(
"url" => "url/TwiML/hold_unhold.php?action=$action&admin_id=".$admin_id,
"method" => "POST"
);
// echo 'CallSid-> '.$childCallSid;
$call = $this->client->calls($childCallSid)->update($rr);
$call1 = $this->client->calls($parentCallSid)->fetch();
print_r($call);
print_r($call1);
//return $call->to;
}
function unhold_call($parentCallSid,$action='unhold'){
//echo $parentCallSid;
$admin_id = get_current_user_id();
$rr = array(
"url" => "url/hold_unhold.php?action=$action&admin_id=".$admin_id,
"method" => "POST"
);
//$call = $this->client->calls->read(array("ParentCallSid" => 'CA9631b87ec900aaa309f1847872cf0da3'));
$call1 = $this->client->calls($parentCallSid)->update($rr);
print_r($call1);
//return $call->to;
}
on hol_unhold.php
if($_REQUEST['action']=='hold'){
?>
<Response>
<Enqueue waitUrl="adHoldmusic.xml"><?php echo $_REQUEST['admin_id'] ?></Enqueue>
</Response>
<?php }else{
?>
<Response>
<Dial>
<Queue><?php echo $_REQUEST['admin_id'] ?></Queue>
</Dial>
<Play loop="0"><?php echo $hold_music;?></Play>
</Response>
<?php }
and for receiving call i m using this twiml-
<Response>
<Dial>
<Client statusCallbackEvent="initiated ringing answered completed" statusCallback="twilio_call_notification_handler.php" statusCallbackMethod="POST"><?php echo isset($numbers[$_REQUEST['Called']]) ? $numbers[$_REQUEST['Called']] : 'new'; ?></Client>
</Dial>
<Play loop="0"><?php echo $hold_music;?></Play>
</Response>