Reputation: 13
If i put a call on hold means the primary number is on hold but the secondary number was disconnected..
$arrR = array();
$callSid = "sample callsid here";
$client = new Client(SmsSpool::$arrTwilioSetting['sid'],
SmsSpool::$arrTwilioSetting['auth_token']);
$rr = array(
"url" => "http://demo.twilio.com/docs/voice.xml",
"method" => "POST"
);
$call = $client->calls($callSid)->update($rr);
$op = $call->to;
$arrR[] = $op;
return $arrR;
Here it works on primary call on hold and disconnect the secondary caller.
And please guide me to un hold a call also.
Upvotes: 1
Views: 583
Reputation: 73029
Twilio developer evangelist here.
The easiest way to handle placing calls on hold is to use a conference to host the call. Once you have a participant in a conference you can place them on hold by making an update request to the participant resource, setting hold
to True
and setting the holdUrl
for the hold music.
$participant = $client
->conferences("CFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
->participants("CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
->update([
"hold" => True,
"holdUrl" => "http://www.myapp.com/hold_music"
]);
You can then update the participant again, setting hold
to False
to return them to the call.
If you want to use a regular call, there's a bit more work to do. As you have found when you update one leg of the call to send it somewhere else, the other leg completes the call and hangs up. To deal with this you need to provide somewhere for the other leg to go. You can do this by providing further TwiML after the <Dial>
.
<Response>
<Dial>+CUSTOMER_NUMBER</Dial>
<Redirect>https://example.com/hold</Redirect>
</Response>
In the TwiML above, if you update the other leg of the call, then the <Dial>
will complete and the call will move on to the <Redirect>
(though you can put any TwiML here). When you unhold the call, you need to reconnect the two legs of the call. It's best to do this by <Enqueue>
ing the call you are putting on hold and then, when unholding, updating the other leg to <Dial>
into the <Queue>
.
But, like I said, using <Conference>
is much easier than handling the separate call legs like this.
Upvotes: 1