在 TWIML <dial> 中等待应答时播放音乐 [英] Play music while waiting an answer in TWIML <dial>

查看:20
本文介绍了在 TWIML <dial> 中等待应答时播放音乐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在等待连接成功的同时拨打号码并向来电者播放音乐?

How to dial numbers and diffuse a music to the caller while waiting a successful connexion ?

下面的代码在执行(这是逻辑)之前等待音乐结束

The code below waits the music to end before doing the <dial> (which is logic)

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Play>http://com.twilio.music.ambient.s3.amazonaws.com/gurdonark_-_Plains.mp3</Play>
    <Dial timeout="10" callerId="+1234567890">
        <Number url="whisper?id=1">+1122334455</Number>
        <Number url="whisper?id=2">+1122334466</Number>
        <Number url="whisper?id=3">+1122334477</Number>
    </Dial>
</Response>

注意:不要使用会议功能会很好.可能有 的东西?

NB: It would be nice NOT to use conference functionalities. Something with <Enqueue> maybe ?

推荐答案

Twilio 开发人员布道者在这里.

Twilio developer evangelist here.

您可以使用 .这是它的工作原理:

You could do this with <Enqueue>. Here's how it would work:

您需要替换 的 TwiMLs 然后 s.这必须是一个动态操作,因为您需要 同时使用REST API 而不是 TwiML.您将返回的 TwiML 会按照您的建议将原始呼叫者放入队列并播放音乐.在 PHP 中,它看起来有点像:

You would need replace the TwiML that <Play>s and then <Dial>s. This would have to be a dynamic action as you would need to make the three simultaneous calls using the REST API instead of TwiML. The TwiML that you would return would put your original caller into a queue as you suggest and play them music. In PHP that would look a bit like:

<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php';
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "your_account_sid";
$token = "your_auth_token";
$client = new Client($sid, $token);

$numbers = array('+1122334455', '+1122334466', '+1122334477');

foreach ($numbers as $number) {
  $call = $client->calls->create(
      $number, $YOUR_CALLER_ID,
      array("url" => "http://example.com/dial_queue")
  );
}

header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
  <Enqueue waitUrl="http://com.twilio.music.ambient.s3.amazonaws.com/">
    dialling
  </Enqueue>
</Response>

在 URL http://example.com/dial_queue 处,您需要返回 TwiML,将被叫方拨入原始呼叫方.您在原始示例中有一个耳语 URL,您可以通过将其内联到 TwiML 中来实现.

At the URL http://example.com/dial_queue you would need to return TwiML that dials the callee into the original caller. You have a whisper URL in your original example, which you can achieve by inlining that into the TwiML.

<Response>
  <Say>Your custom message</Say>
  <Dial>
    <Queue>dialling</Queue>
  </Dial>
</Response>

请注意,您拨打的是 您在原始 中使用的.如果此系统将用于多个呼叫者,那么您可能需要为他们生成唯一的队列名称.

Note that you dial the name of the <Queue> that you used in the original <Enqueue>. If this system will be used for more than one caller, then you probably need to generate unique queue names for them.

最后要做的就是在呼叫连接后取消另外两个呼叫,如果没有呼叫应答则取消队列.我会把这个留给你,因为我相信你可以通过自己的设置来实现它.

The final things to do would then be to cancel the other two calls once a call connects and cancel the queue if none of the calls answer. I will leave that to you as I'm sure there's many ways you could achieve it with your own setup.

让我知道这是否有帮助.

Let me know if that helps at all.

这篇关于在 TWIML &lt;dial&gt; 中等待应答时播放音乐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆