How to play hold music when phone call is waiting for an answer client in Twiml

断了今生、忘了曾经 提交于 2020-03-05 00:31:32

问题


I'm building a call system with Twilio Twiml where a user calls to my Twilio number and needs to enter a code to be attended:

callsip.php

<?php 
   echo header('content-type: text/xml');
   echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<Response>
 <Play>https://mywebsite.com/welcome.mp3</Play>
 <Gather numDigits="11" action="myfile.php">
    <Say voice="alice">Please enter your code</Say>
 </Gather>
</Response>

After enter the code, the call goes to Twilio clients:

myfile.php

<?php 
  echo header('content-type: text/xml');
  echo '<?xml version="1.0" encoding="UTF-8"?>';
  $code = $_POST['Digits'];
?>
<Response>
  <Dial timeout="20" record="record-from-answer" recordingStatusCallback="https://mywebsite.com/record.php" recordingStatusCallbackEvent="in-progress completed absent">
        <Client>
            <Identity>myuser</Identity>
            <Parameter name="code" value="<?php echo $code; ?>"/>
        </Client>
    </Dial>
</Response>

I want user listen a hold music while is waiting for an answer, I tried adding a Enqueue tag in myfile.php:

<Response>
<Enqueue waitUrl="https://mywebsite.com/hold_music.php">support</Enqueue>
...
</Response>

hold_music.php

<?php 
 echo header('content-type: text/xml');
 echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<Response>
  <Play loop="0">https://mywebsite.com/hold_music.mp3</Play>
</Response>

But I'm a bit lost, the hold music is playing but Twilio clients are not being called.

How can I fix it?

I'd like your help.


回答1:


Adding music on hold to your call flow requires a media resource to play the music while the dialed party answers. One way to accomplish that is to enable Agent Conference in your Twilio console here, and add the initial caller to that conference as part of the Gather action URL logic, then Create an Agent Conference Participant using that ConferenceSID with Early Media set to False.

Note, you will not be able to dial using the original CallersID, unless that number is a Verified CallerID (you can also use a Twilio number in your account as the outbound CallerID). Also, make sure to account for cases where the dialed party doesn't answer, so the original caller is not left on the conference, listening to music forever.

Alan



来源:https://stackoverflow.com/questions/60117172/how-to-play-hold-music-when-phone-call-is-waiting-for-an-answer-client-in-twiml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!