4

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.

There are two approaches I'm considering:

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

  2. 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.

Racil Hilan
  • 24,690
  • 13
  • 50
  • 55
Zack Burt
  • 8,257
  • 10
  • 53
  • 81

1 Answers1

2

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.

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"
    ));
}

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>

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");

Then your /conference_message endpoint would return TwiML like this:

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

Let me know if this helps at all.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • 1
    Thanks, this is helpful! How do I get `THE_CONFERENCE_NUMBER` .. is it the ConferenceSid? Initially created the Conference through a verb, {arbitrary internal id. – Zack Burt Mar 22 '16 at 15:30
  • Ah, no, that's just a number that you could call to reach your conference. I assumed people were just dialling into the conference and your bot could too. – philnash Mar 22 '16 at 17:35
  • So there's no way to have a bot join a programmatically-created conference? – Zack Burt Mar 22 '16 at 17:36
  • Well, the only way for the bot to join in is for it to dial into the conference, say it's message and then hangup. That's what I was trying to explain above. – philnash Mar 22 '16 at 17:48
  • 1
    How can a bot dial into a conference that doesn't have a phone number (i.e., a conference that is programmatically created)? – Zack Burt Mar 24 '16 at 13:38
  • You could create a number for the conference? Or, presumably you have a Twilio number in order to get people into this conference somehow, you could program that number to direct the bot into the conference if the number is called by that bot. I'm not sure about your setup here, so it's hard to suggest anything more specific. – philnash Mar 24 '16 at 13:41
  • I guess I could create a number that is dedicated to Conferences. Then I could dial the number, have it key in the conference code, pause, and say the greeting, and leave. Cool. Thanks. – Zack Burt Mar 24 '16 at 15:06
  • @ZacharyBurt were you able to dial in to the conference? How did you assign a number to conference? – H R Aug 05 '17 at 17:33
  • @philnash Is there any way to join conference call with conferenceSid or conference friendly name. Please check my question https://stackoverflow.com/questions/47595208/add-a-bot-into-twilio-conference-and-announce-some-information-using-conferenc – Puneet Singh Dec 02 '17 at 05:42