如何在等待连接成功的同时调用号码并向来电者播放音乐?
下面的代码在执行 <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>
注意:最好不使用 session 功能。可能有 <Enqueue>
的东西?
最佳答案
此处为 Twilio 开发人员布道师。
你可以用 <Enqueue>
做到这一点.它的工作原理如下:
您需要替换 <Play>
s 的 TwiML然后 <Dial>
s .这必须是动态操作,因为您需要 make the three simultaneous calls using the REST API而不是 TwiML。您将返回的 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>
在网址 http://example.com/dial_queue
您需要返回将被叫方拨入原始调用方的 TwiML。您在原始示例中有一个耳语 URL,您可以通过将其内联到 TwiML 中来实现。
<Response>
<Say>Your custom message</Say>
<Dial>
<Queue>dialling</Queue>
</Dial>
</Response>
请注意,您拨的是 <Queue>
的名称你在原版中使用的 <Enqueue>
.如果此系统将用于多个调用者,那么您可能需要为他们生成唯一的队列名称。
最后要做的事情是一旦调用接通就取消其他两个调用,如果没有调用应答则取消队列。我会把它留给你,因为我相信有很多方法可以通过你自己的设置实现它。
让我知道这是否有帮助。
关于twilio - 在 TWIML <dial> 中等待答案时播放音乐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41321365/