1

I am building a simple conference using Twilio where a conference is started by Agent using Twilio client and a contact is called and added to this conference. Just before adding this contact to conference, we would like to announce the name of the contact in the conference room (for ex: <Say>Now Joining Sam Carter </Say>). The name of the person is figured out based on their phone number from database.

When a call is connected, the following TwiML is executed which connects the contact to the conference:

<Dial callerId="+1415xxxxxxx" record="true" action="/my/action/url">
    <Conference endConferenceOnExit="true" >ConferenceRoom1</Conference>
</Dial>

Is there any way to play a message into conference just before <DIAL> verb is executed. If i write <SAY> verb before <DIAL> then it plays message to the contact, not in the CONFERENCEROOM1.

Are there any events like onConferenceEnter, which can be used to fire another TwiML whenever some participant enters the conference? Please suggest what would be the best way to achieve this behavior.

Dharmveer Jain
  • 121
  • 2
  • 11

2 Answers2

2

The short answer to the question is that it can't be done through a Twiml Event however it can be done with a kind of hack using their REST API.

The question has already been asked on SO and the answer is available here:

Use Say verb to all Conference participants

Incase the question/answer is ever deleted/removed i've pasted it below:


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

Community
  • 1
  • 1
ajtrichards
  • 29,723
  • 13
  • 94
  • 101
2

For benefit of others, this is how I have implemented this behavior :

  1. An agent has started the conference using Twilio client and he is already in conference. As soon as a participant is about to join the same conference, using REST API, modify the URL of the live conference call.

    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
    Map<String, String> filter = new HashMap<String, String>();
    filter.put("From", "client:AGENT1");
    filter.put("Status", "in-progress");
    CallList callList = account.getCalls(filter); 
    Call agentsCall = null;
    for (Call inProgressCall : callList) {
        agentsCall = inProgressCall;
        break; //return the first one only..there shouldn't be more
    }
    Map<String, String> agentsCallParams = new HashMap<String, String>();  
    agentsCallParams.put("Url", "http://myserver.com/twiml/agentmessage.xml");
    agentsCallParams.put("Method", "GET");
    agentsCall.update(agentsCallParams);`
    
  2. The above code snippet will update the twiml of existing call as below.

    <?xml version="1.0" encoding="UTF-8"?>
    <Response>
        <Say>Now joining {name of the participant}</Say>
        <Dial>
           <Conference>Conference1</Conference>
        </Dial>
    </Response>
    
  3. The above Twiml will update the call to play the message in <SAY> verb and then put the agent back into the conference.

  4. Now, make the participant join the same conference by returning the below Twiml:

    <?xml version="1.0" encoding="UTF-8"?>
    <Response>
    <Dial>
        <Conference>Conference1</Conference>
    </Dial>
    

    Hope this helps !!!

Dharmveer Jain
  • 121
  • 2
  • 11