2

I need help in uhholding the call.I have tried two method.

1. use enqueue verb when i press the hold button I have user the update call method

<Response>
  <Enqueue waitUrl="urltoplaytheholdmusic">1111</Enqueue>
</Response>

(and when I press the unhold button I used the same update method and used.)

<Response>
  <Queue >1111</Queue>
</Response>

but when used the queue verb call gets disconnected.

2. So I tried an other way to just play the music when I press the hold button.

 <Response><Say>We are putting you on hold Please wait!</Say><Play loop="0">https://api.twilio.com/cowbell.mp3</Play></Response>

Now I don't know what to do to unhold the call.

question:reference question

this all i am doing. when I make call I have used the js liberay for that and used this function

function call(dial_number, from_phone) {

                 params = {
                     "to_phone": to_phone,
                     "from_phone": from_phone,
                     "from_id": current_user_id,
                     "to_id": user_id
                 };

                 connection = Twilio.Device.connect(params);


                 connection._onAnswer = function(conn) {
                     console.log(conn.callsid);
/*get parentcall sid when make the call*/ 
                     Sid = {
                         parent_callSid: conn.callsid,
                         type: 'outgoing'
                     };
                 };


             }

And to put the call on hold I have used this line of code

function holdaction() {
                 jQuery.ajax({
                     url: 'url',
                     type: 'POST',
                     data: 'sid=' + parentSid + '&admin_no=' + encodeURIComponent(jQuery('#twilio_from_number').val()) + '&action=' + hold_action,
                     dataType: 'json',
                     success: function(data) {}

                 });
             }

This gets the callsid by using the parentcallsid from my db call this functionto put the call on hold

function update_call($callSid, $action, $admin_no = '') {
                $rr = array(
                    "url" => "holdactionurl?type=".$action.
                    '&admin_no='.$admin_no,
                    "method" => "POST"
                );
                $call = $this->client->calls($callSid)->update($rr);
                return $call->to;
            }

And on holdactionurl I have used this-

<Response>
  <Enqueue waitUrl="wait_url">first_queue</Enqueue>
</Response>

And on wait_url I have used this-

<Response>
  <Say>You are on hold </Say>
  <Redirect>wait_url</Redirect>
</Response>

And I for unholding the call I (means the same number which have put the call on hold) used the same holdaction method with different parameter and the xml code for that is-

<Response>
  <Dial>
    <Queue>first_queue1</Queue>
  </Dial>
</Response>

I know I m doing this wrong but I can't figure out the right way so I will much appreciate If you can help me figure it out what I m doing wrong

Community
  • 1
  • 1
John Ambrose
  • 167
  • 1
  • 11
  • What are you trying to do with the call once it is unheld? Are you connecting to another caller or doing something else? I can help, I just need to know what's coming next. – philnash Feb 15 '17 at 11:00
  • thanks for replying.I put the call on hold when i press the hold button but I can't figure out how to unhold the call and reconnect the same callers again. – John Ambrose Feb 15 '17 at 11:50
  • Ok, cool, so how are they connected in the first place and what do you do with the other end? Can you share the code that you are using to achieve this so far? – philnash Feb 15 '17 at 11:51
  • I have used the this '`number `' to dail the number and used the update method to put the call on hold- `1111` and on wait_url I play the hold music and to unhold i used the same update method and used "`1111`" – John Ambrose Feb 15 '17 at 11:59
  • And I followed exact process that you have mentioned in your answer for this question [http://stackoverflow.com/questions/41236926/twilio-retrieve-call-on-hold-back?rq=1] but it's not working when I used ` ADMIN_ID ` – John Ambrose Feb 15 '17 at 12:03
  • And what happens to the other end of your call? – philnash Feb 15 '17 at 12:45
  • receiver will hear the hold music untill I press the unhold button. Actually I followed exact process that you have mentioned in your answer for this question http://stackoverflow.com/questions/41236926/twilio-retrieve-call-on-hold-back?rq=1 but when I used the process of unqueuing its not working – John Ambrose Feb 15 '17 at 12:59
  • So you want both ends of the call to hear hold music? (Sorry for all the questions, I'm just trying to get the call flow correct in my head before I answer.) – philnash Feb 15 '17 at 13:02
  • No it's okay.I want only other end(receiver) to hear the hold music . – John Ambrose Feb 15 '17 at 13:03
  • So what do you want to happen to the end that will not hear music? – philnash Feb 15 '17 at 13:04
  • Actually the caller is the administrator and he puts a user call on hold to make him wait for some time and when he will be ready he will unhold the call and start talking to the user again – John Ambrose Feb 15 '17 at 13:07
  • The process I m following to put the caller on hold in to use verbs and to dequeue it I m using but when I try to dequeue the call It wait for 9-10 sec and disconnects the call – John Ambrose Feb 15 '17 at 13:11

1 Answers1

1

Twilio developer evangelist here.

Thanks for answering my questions in the comments. I think I know where we are right now.

As you say, you have followed my answer here. In this, the caller gets put into a queue unique to the agent that they called. The agent, meanwhile, is redirected to a loop (in my example it just said "You have a caller on hold" over and over).

In your question here, you talk about redirecting the caller that has been queued to the following TwiML:

<Response>
  <Queue>1111</Queue>
</Response>

The <Queue> verb is used to dial from people outside of the queue to the next person in the queue. So in this case, you're trying to get the queued caller to dial themselves, which can't work.

Instead, you need to do the redirect on the agent, directing them out of the loop they've been placed into and calling the person out of the queue.

So, you don't dequeue the caller by moving them from <Enqueue> to <Queue>, you dequeue a caller by getting someone else to dial <Queue>

Let me know if that helps at all.

Update

From your code I believe this is what's happening.

In your server update_call function you are moving the outgoing call into a queue, effectively putting your agent on hold. I assume this means the other end is losing the connection and this is your problem. If that's not the case, just let me know.

Anyway, what we need to do is find the child call and push that off to a queue. I would split up your update_call function to perform two different things. Firstly, get the childCallSid and redirect it to the holdactionurl.

function holdChildCall($parentCallSid, $action, $admin_no = '') {
    $childCalls = $this->client->calls->read(array("ParentCallSid" => $parentCallSid));
    $childCallSid = $childCalls[0]->sid;
    $rr = array(
        "url" => "holdactionurl?type=".$action.
        '&admin_no='.$admin_no,
        "method" => "POST"
    );
    $call = $this->client->calls($childCallSid)->update($rr);
    return $call->to;
}

If you try this now then the called end, the child call, will get redirected to your Queue but your caller, your agent, the parent call, will get cut off. We need to stop that happening which we can do by adjusting the initial TwiML. Your comment below says that currently your TwiML looks like this:

<Response>
  <Dial callerId="callerid">
    <Number statusCallbackEvent="initiated ringing answered completed" statusCallback="urltohadlestatus">user_number</Number>
  </Dial>
</Response>

You need to update the <Dial> here to give it more TwiML to drop into once the child call is dropped. Add a redirect after the <Dial>.

<Response>
  <Dial callerId="callerid">
    <Number statusCallbackEvent="initiated ringing answered completed" statusCallback="urltohadlestatus">user_number</Number>
  </Dial>
  <Redirect>/admin_on_hold</Redirect>
</Response>

You can call the url whatever you want, I've called it /admin_on_hold for now. You need some TwiML at that URL that keeps the caller on the line too. You could use something similar to your existing hold notification:

<Response>
  <Say>You have a caller on hold. </Say>
  <Pause length="5"></Pause>
  <Redirect>wait_url</Redirect>
</Response>

Now when you press hold your child call, the called person, will be queued up and wait with a hold message. And your agent, the caller, the parent call, will also hear a message to say that they are keeping a caller on hold.

Now we need to reconnect the two callers. We do this by redirecting the agent call, the parent call, to the <Queue>, this will pop the child call off the queue and reconnect them. We can actually use the existing update_call function for this. Make sure you are passing the parent call SID and the $action that produces the <Queue> TwiML from holdactionurl with the same queue name that you used to <Enqueue> the caller in the first place.

function update_call($parentCallSid, $action, $admin_no = '') {
    $rr = array(
        "url" => "holdactionurl?type=".$action.
        '&admin_no='.$admin_no,
        "method" => "POST"
    );
    $call = $this->client->calls($parentCallSid)->update($rr);
    return $call->to;
}

Does this make sense? You need to make sure you redirect the child call to TwiML that uses <Enqueue>, add the extra <Redirect> after <Dial> so that your agent doesn't hang up and then when you unhold redirect the agent call to the TwiML that uses <Queue>.

Community
  • 1
  • 1
philnash
  • 70,667
  • 10
  • 60
  • 88
  • okay thanks can you please provide some code for this(you need to do the redirect on the agent, directing them out of the loop they've been placed into and calling the person out of the queue.) – John Ambrose Feb 16 '17 at 04:34
  • If you edit your original question with the code and the call flow you are currently using, I might be able to adapt it. I can't write the entire code for you as I don't know your use case or how you've started it. – philnash Feb 16 '17 at 10:05
  • All the bits that relate to this call flow. – philnash Feb 16 '17 at 10:17
  • I have edited my question and added my code for putting a call on hold and also for unhold the call. Let mention what I need .Eg. If A(admin) makes an outgoing call to B(user) and after talking for while A puts call on hold and on that time B listen hold music and when A is ready again A press unhold button and reconnect with B again.This is what I need so correct me where I m doing wrong in my code. – John Ambrose Feb 16 '17 at 10:47
  • When you make the outgoing call, what is the TwiML that connects the two calls? – philnash Feb 16 '17 at 11:10
  • here it is ` user_number ` – John Ambrose Feb 16 '17 at 11:13
  • I have updated the answer with more explanation and some code. – philnash Feb 16 '17 at 13:41
  • In your server update_call function you are moving the outgoing call into a queue, effectively putting your agent on hold. I assume this means the other end is losing the connection and this is your problem. If that's not the case, just let me know.===the other end will hear the hold music..until I press the hold button – John Ambrose Feb 16 '17 at 13:53
  • I don't know what you mean there. Have you tried what I suggested? – philnash Feb 16 '17 at 14:02
  • can you please write the TwiML for de-queuing call too. – John Ambrose Feb 17 '17 at 05:40
  • Yes it is working perfect Thank you so much for the help.And would i need to change any thing in case of incoming call? – John Ambrose Feb 17 '17 at 08:14
  • To receive call I m using this TwiML- ` clientname admin_holdurl ` – John Ambrose Feb 17 '17 at 08:22
  • On an incoming call the TwiML received by the incoming caller, so that would redirect your caller to the admin hold url, which you probably don't want. In this case you should make the `` after the `` to your `` TwiML and redirect the admin caller to `admin_holdurl` using the REST API. – philnash Feb 17 '17 at 09:07
  • OK thanks.But what will happen when the call is on hold and any of the caller disconnect the call?because the call is not disconnecting if the call is on hold and any of caller disconnects the call.In case of out going it disconnects the call but if the call is incoming is doesn't disconnect the call – John Ambrose Feb 17 '17 at 10:23
  • You could receive the webhook statusCallback for the user disconnecting and then disconnect your agent using the REST API? Or when the agent unholds they will dial an empty Queue, so will just hang up. – philnash Feb 17 '17 at 10:25
  • okay but when agent hangup then the user call is not disconnecting.so what should i do for that – John Ambrose Feb 17 '17 at 10:40
  • You could do the same with the webhook? Or keep the user in the queue as you might want the agent to dial back in in case they hang up by accident? It's really up to you. – philnash Feb 17 '17 at 10:41
  • but its not working this is the twiml ==` cleint holdmusic ` – John Ambrose Feb 17 '17 at 10:47
  • What do you mean it's not working? You have to do some more work to implement the suggestions I've just made. If something new is broken then I recommend you ask a new question rather than getting bogged down in comments here. And when you do, please include what you have done to attempt what you're working on. – philnash Feb 17 '17 at 10:49