在 TWIML 中等待答案时播放音乐 <dial>

Play music while waiting an answer in TWIML <dial>

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

下面的代码在执行 <dial>(这是逻辑)

之前等待音乐结束
<?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>

注意:如果使用会议功能就好了。可能有 <Enqueue> 的东西?

这里是 Twilio 开发人员布道者。

你可以用 <Enqueue> 做到这一点。它的工作原理如下:

您需要替换 <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 的 TwiML 而不是 TwiML。你会 return 的 TwiML 会按照你的建议将你的原始呼叫者放入队列并播放他们的音乐。在 PHP 中看起来有点像:

<?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 处,您需要 return TwiML 将被叫方拨入原始呼叫方。在您的原始示例中有耳语 URL,您可以通过将其内联到 TwiML 中来实现。

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

请注意,您拨的 <Queue> 的名称与您在原始 <Enqueue> 中使用的名称相同。如果此系统将用于多个呼叫者,那么您可能需要为他们生成唯一的队列名称。

最后要做的事情是在呼叫接通后取消其他两个呼叫,并在 none 呼叫应答时取消队列。我会把它留给你,因为我相信有很多方法可以通过你自己的设置来实现它。

如果有帮助请告诉我。