Twilio:以编程方式加入会议并播放<say>命令或<play>声音文件?

时间:2016-03-20 16:58:33

标签: twilio twilio-php conference

我有两个用户,我将他们加入<Conference>

我想让机器人加入<Conference>,然后发布公告。

我正在考虑两种方法:

  1. 让大家参加会议,将他们重定向到播放声音的TwiML,然后将其移回会议。

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

1 个答案:

答案 0 :(得分:1)

Twilio开发者传道者在这里。

这些方法中的任何一种都可行,但效果会略有不同。重定向将削减会议,无论当时谁在发言,但加入的机器人可能会被说出来。这取决于哪个更适合您的用例。

要进行重定向,您需要浏览list of Conference participants,然后按updating their call to a new URL重定向,然后从plays the soundredirects返回的网址返回TwiML您原来的会议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到会议号并提供指向TwiML的网址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>

让我知道这是否有帮助。