Twilio:以编程方式加入会议并播放 <Say>命令或<播放>声音文件? [英] Twilio: programmatically join conference and play <Say> command or <Play> sound file?

查看:20
本文介绍了Twilio:以编程方式加入会议并播放 <Say>命令或<播放>声音文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个用户,我将他们加入了一个 .

I have two users and I joined them both into a <Conference>.

我想让机器人加入,然后发布公告.

I would like to have a robot join the <Conference> and then make an announcement.

我正在考虑两种方法:

  1. 将每个人带到会议中,将他们重定向到播放声音的 TwiML,然后将他们移回会议.

  1. Take everyone in the conference, redirect them to a TwiML that plays a sound, and then move them back into the Conference.

创建一个以某种方式加入会议并播放 TwiML 的机器人,但从文档中我不清楚如何做到这一点.

Create a bot that somehow joins the Conference and plays TwiML, but it's not clear for me, from the documentation, how to do that.

推荐答案

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

Twilio developer evangelist here.

这两种方法都行得通,但效果略有不同.无论当时谁在发言,重定向都会中断会议,但加入的机器人可能会被发言.这取决于哪种更适合您的用例.

Either of those approaches will work, though will have slightly different effects. Redirecting will cut the conference regardless of who is speaking at the time, but a bot joining in may get spoken over. It depends on which will work better for your use case.

要进行重定向,您需要浏览会议参与者列表,通过将他们的呼叫更新到新的 URL 并从 播放声音重定向回到您的原始会议 URL.类似的东西:

To do the redirect, you'll need to run through the list of Conference participants, redirect them by updating their call to a new URL and return TwiML from that URL that plays the sound and redirects back to your original Conference URL. Something like:

$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:

Then your /conference_message endpoint would need TwiML like this:

<Response>
  <Play>http://example.com/message.mp3</Play>
  <Redirect>http://example.com/conference</Redirect>
</Response>

另一方面,让机器人进入房间需要您创建一个调用会议号并提供一个指向 TwiML 的 URL 以play 消息,然后 hangup.像这样:

On the other hand, having a bot enter the room requires you to create a call to the conference number and supply a URL which points to the TwiML to play the message and then hangup. Like this:

$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:

Then your /conference_message endpoint would return TwiML like this:

<Response>
  <Play>http://example.com/message.mp3</Play>
  <Hangup/>
</Response>

告诉我这是否有帮助.

这篇关于Twilio:以编程方式加入会议并播放 &lt;Say&gt;命令或&lt;播放&gt;声音文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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