Reputation: 187
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
Upvotes: 2
Views: 1841
Reputation: 73029
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>
.
Upvotes: 1