我有两个用户,我将他们加入了 <Conference>
.
我想有一个机器人加入<Conference>
然后发布公告。
我正在考虑两种方法:
最佳答案
Twilio 开发人员布道者在这里。
这两种方法中的任何一种都可以使用,但效果会略有不同。无论当时谁在发言,重定向都会中断 session ,但加入的机器人可能会被发言。这取决于哪个更适合您的用例。
要进行重定向,您需要运行 list of Conference participants ,通过 updating their call to a new URL 重定向它们并从该 URL 返回 TwiML plays the sound和 redirects回到您原来的 session URL。就像是:
$sid = "{{ account_sid }}";
$token = "{{ auth_token }}";
$client = new Services_Twilio($sid, $token);
// Loop over the list of participants and redirect ($client->account->conferences->get(CONFERENCE_SID)->participants as $participant) {
$call = $client->account->calls->get($participant->call_sid);
$call->update(array(
"Url" => "http://example.com/conference_message"
));
}
那么你的
/conference_message
端点需要像这样的 TwiML:<Response>
<Play>http://example.com/message.mp3</Play>
<Redirect>http://example.com/conference</Redirect>
</Response>
另一方面,让机器人进入房间需要您create a call到 session 号并提供一个指向 TwiML 的 URL 到 play消息,然后 hangup .像这样:
$sid = "{{ account_sid }}";
$token = "{{ auth_token }}";
$client = new Services_Twilio($sid, $token);
$call = $client->account->calls->create(A_TWILIO_NUMBER, THE_CONFERENCE_NUMBER, "http://example.com/conference_message");
那么你的
/conference_message
端点将像这样返回 TwiML:<Response>
<Play>http://example.com/message.mp3</Play>
<Hangup/>
</Response>
让我知道这是否有帮助。
关于Twilio:以编程方式加入 session 并播放 <Say> 命令或 <Play> 声音文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36116688/