admin管理员组文章数量:1390238
I am trying to implement a hold functionality using the Twilio JavaScript SDK for voice calls and PHP. However, when I attempt to put both legs of the call on hold, I encounter an issue where one leg is successfully placed on hold, but the other leg gets dropped.
Basically, Whenever I call the hold function, the caller is getting disconnected. The code described below only applies to the callee not the caller.
I have shared my code below. Can anyone please take a look and let me know what corrections I need to make? Thank you!
Call_hold.php
$jsonn = file_get_contents('../outgoing1.txt')
$dataaaa = json_decode($jsonn, true)
$child_leg = $dataaaa['CallSid'];
$parent_id = $dataaaa['ParentCallSid'];
/*----- Modify the person I called child leg sent to wait music -----*/
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => " SID/Calls/$child_leg.json",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_HTTPHEADER => array(
'Authorization: Basic xxxxxxxxxxxxxxx',
'Content-Type: application/x-www-form-urlencoded'
),
));
$response = curl_exec($curl);
$data = json_decode($response, true);
$ssid_id = $data['sid'];`
`$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => " SID/Calls/$ssid_id.json",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => 'Method=POST&Url=outbound_customer_queue.php',
CURLOPT_HTTPHEADER => array(
'Authorization: Basic xxxxxxxxxxxxxxx',
'Content-Type: application/x-www-form-urlencoded'
),
));
$response = curl_exec($curl);`
`/* ------- The Caller(me) ParentCallSid sent to waiting hold music ---------- */
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => " SID/Calls/$paren_id.json",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => 'Method=POST&Url=outbound_agent_queue.php',
CURLOPT_HTTPHEADER => array(
'Authorization: Basic xxxxxxxxxxxxxxx',
'Content-Type: application/x-www-form-urlencoded'
),
));
$response = curl_exec($curl);
XML:
outbound_customer_queue.php
echo '<?xml version="1.0" encoding="UTF-8" ?>
<Response>
<Say>Listen, please. Our agent team is very busy at the moment, and the agent you are talking to has put your call on hold. Please wait until the call is connected back to them. Thank you.</Say>
<Enqueue waitUrl="wait-music.php">supporting</Enqueue>
<Redirect>wait-music</Redirect>
</Response>';
wait-music.php
echo '<?xml version="1.0" encoding="UTF-8" ?>';
echo "<Response>";
echo "<Say>Hey, you are caller number ".$_REQUEST['QueuePosition'].". There is an average wait time of ".$_REQUEST['AvgQueueTime']."</Say>";
echo "<Play>.mp3</Play>";
echo "</Response>";
outbound_agent_queue.php
echo '<?xml version="1.0" encoding="UTF-8" ?>
<Response>
<Say>You have successfully placed the call on hold. Please be aware that the customer is waiting, and they will be returned to you when you connect back.</Say>
<Pause length="5"></Pause>
<Enqueue waitUrl="wait-music.php">supporting</Enqueue>
<Redirect>wait-music</Redirect>
</Response>';
outgoing1.txt
{
"Called": "+16789835670",
"ParentCallSid": "CA5218906a7d0574ec3cc351b29fa51362",
"ToState": "Arizona",
"CallerCountry": "US",
"Direction": "outbound-dial",
"Timestamp": "Fri, 14 Mar 2025 13:47:33 +0000",
"CallbackSource": "call-progress-events",
"SipResponseCode": "200",
"CallerState": "PA",
"ToZip": "",
"SequenceNumber": "3",
"CallSid": "CAc2fe08c722becd59574c3e0b99b025cf",
"To": "+16789835670",
"CallerZip": "",
"ToCountry": "US",
"CalledZip": "",
"ApiVersion": "2010-04-01",
"CalledCity": "",
"CallStatus": "completed",
"Duration": "1",
"From": "+18145593276",
"CallDuration": "32",
"AccountSid": "******",
"CalledCountry": "US",
"CallerCity": "",
"ToCity": "",
"FromCountry": "US",
"FromCity": "",
"CalledState": "Arizona",
"FromZip": "",
"FromState": "AZ"
}
Issue:
When I try to use the above code, it only places the person I called (child leg) on hold while the call to the caller (me, the parent leg) gets disconnected, which makes the outbound call to that person. I want both legs of the call (caller and callee) to be placed on hold simultaneously, but it doesn’t seem to be working as expected.
本文标签: Put caller on hold using PHP javascript SDK in twilioStack Overflow
版权声明:本文标题:Put caller on hold using PHP javascript SDK in twilio - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744607014a2615416.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论