0

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> 
John Ambrose
  • 167
  • 1
  • 11
  • Are you saying that one call gets hung up on when you just fetch the data about it? – philnash Feb 27 '17 at 06:58
  • thanks for replying.When fetch the data using the parentcallsid the call status shows completed right after queuing it second time. – John Ambrose Feb 27 '17 at 07:00
  • That may well be because the original `` is complete, even though the call is ongoing. Can you unhold and rejoin the calls together successfully the second time? – philnash Feb 27 '17 at 07:13
  • No when I try to unhold it second time the update function gives the error -"Call is not in-progress. Cannot redirect" – John Ambrose Feb 27 '17 at 07:22
  • the whole scenario is I m creating the call using number like +15555555555 with the rest api then when user pick up the call I check if It is human then I again dial the same number +15555555555(got this idea form here -[http://stackoverflow.com/questions/42417185/when-we-make-call-using-rest-api-then-what-twiml-we-use-on-that-url-parameter]) to connect it with the user.and then I m doing all of this hold and unhold on this new call. – John Ambrose Feb 27 '17 at 07:38
  • If the person has already answered the phone, then dialling them again won't help. What do you want to do if it is a human? – philnash Mar 01 '17 at 21:52
  • I want the human to connect with me.//Like if I called using +155555555555 number through REST API and a human answer the call then the human should connect with number +1555555555.// – John Ambrose Mar 02 '17 at 07:51

0 Answers0