Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Say verb to all Conference participants

Tags:

twilio

I'm setting up a pretty simple conference call system, where the user enters a PIN and is connected to a conference associated with that. I'm also setting it up so they record their name before entering the room.

My plan is to take the recording URL, then get the list of participants and make the REST API call to each caller modifying their call to to the Say "Now entering", then Play the recording url. I think I'm going to have to send them back into the room after that as well, I'm not sure.

I think that modifying each call will take them out of the Conference room, which is not ideal. Is there an easier way to use Say/Play to all members of a conference built into the REST API?

like image 303
Alex Avatar asked Jul 24 '13 22:07

Alex


1 Answers

As of July 13th 2018, Twilio now allows you to send a POST request to the Conference (to announce something to the whole conference) or Conference Participant (to announce something to a single caller) resources with an AnnounceUrl property that links to either:

  • a WAV or MP3 audio file, or
  • a TwiML document that uses the <Say /> and/or <Play /> verbs.

Along with that property, you can also specify an AnnounceMethod property that lets you specify whether to GET or POST (the default) that URL.

A good place to send the aforementioned POST to play back your recorded name might be in a status callback that's set when you use the <Conference /> verb to put each user into the conference, like so:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Dial>
    <Conference statusCallback="/conference/join-callback"
                statusCallbackEvent="join">
      {conference ID}
    </Conference>
  </Dial>
</Response>

The old workaround remains below for posterity.


Someone on the Twilio forums was interested in the very same question, and the answer is currently that there isn't a direct REST API call for that.

What you'll need to do is, when a participant joins the conference, you'll use the REST API to make Twilio dial back in to your application. You can choose how to detect that you're calling into your own conference however you like (for example, comparing the outbound and inbound phone numbers for equality); once you've detected that, you can join that call directly to the conference and use the TwiML <Say /> and <Play /> verbs to play back the introduction for everybody.

It's a little bit convoluted, but this way you won't be removing each participant from the conference (preventing them from hearing each other for a moment) and then rejoining them.

Here's something that should resemble a good end-to-end solution.

First, the user dials in and you go through the standard prompts to get the PIN for the conference room and their name.

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Gather action="/conference/pin" finishOnKey="#">
        <Say>Please the conference pin number followed by the pound key.</Say>
    </Gather>
</Response>

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Say>Say your name and then press the pound key.</Say>
    <Record action="/conference/name" finishOnKey="#" />
</Response>

Now, once you have the user's pin and recording, two things will happen; the response from the post to /conference/name will contain the <Conference> verb, placing the user in the room:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Dial>
    <Conference>{conference ID}</Conference>
  </Dial>
</Response>

...and, asynchronous to that, it will use the REST API to initiate a new call back into the conference room.

POST /2010-04-01/Accounts/{AccountSid}/Calls
From = {your conference phone number}
To = {your conference phone number}
SendDigits = wwww{conference PIN}#
Url = /conference/announce?name={name ID}

Now, the next bit gets confusing. Twilio will now be talking to your callback URL for the incoming end of the call, and the URL you specified above for the outgoing end of the call. Your incoming call handler will need to detect that the conference line is calling back into itself and behave differently; it will first need to respond with simple TwiML that allows the outgoing end of the call to enter the pin for the conference room.

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Gather action="/conference/announce-pin" finishOnKey="#" />
</Response>

The SendDigits parameter of the POST will provide the digits that bit of TwiML is expecting. That action should then respond by conferencing in the new call.

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Dial>
    <Conference>{conference ID}</Conference>
  </Dial>
</Response>

The last piece of the puzzle is the TwiML emitted by the URL you specified in the POST. That's the markup that will run once the loopback call is added to the conference.

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Play>/conference/name-recordings/{name ID}</Play>
    <Say>has joined the call.</Say>
    <Hangup />
</Response>

That markup runs, plays the caller's name and a message into the conference room, and then hangs up.

like image 200
Adam Maras Avatar answered Nov 13 '22 21:11

Adam Maras