这里是 Twilio 开发者宣传员。
这些方法中的任何一种都可以,但效果会略有不同。无论当时谁在发言,重定向都会中断会议,但加入的机器人可能会被发言。这取决于哪个更适合您的用例。
要进行重定向,您需要遍历 list of Conference participants,通过 updating their call to a new URL 重定向它们,然后将 TwiML 从该 URL 中的 plays the sound 和 redirects 返回到您的原始会议 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 的 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>
让我知道这是否有帮助。