Twilio - How to move an existing call to a conference
Asked Answered
B

4

12

With twilio, on an existing call (2 legs - caller leg and called leg), I want to move the call into a conference room. Both legs have to be present into the room How to bridge the both legs without losing one or the other leg ?

Thank you

Regards

Baziotes answered 25/3, 2014 at 18:54 Comment(0)
O
13

The trick to prevent the call being dropped is by using “action” url for parent leg to dial into conference and modifying the child leg to move in the same conference.

Here’s the detailed flow to start calls between 2 person and then upgrade that to a conference

(1) Create a TwiML Response API to dial calls in conference(based suited to your business logic ) . Here’s a simple example TwiML (http://www.mocky.io/v2/584ac0f81000002b14fb0205)

<Response>
<Dial>
<Conference>letItGoSimple</Conference>
</Dial>
</Response>

(2) When you initiate the call , your Url parameter should be set to return TwiML like the one below (example Twiml : http://www.mocky.io/v2/584ac8a3100000c914fb0214 )

<Response>
<Dial action="http://www.mocky.io/v2/584ac0f81000002b14fb0205" method="GET">
<Number>+44xxxxxxxx</Number>
</Dial>
</Response>

Note that the action url has been set to TwiML from step one . It is very important in this flow as this would prevent the call from being dropped when you modify the Child Leg of the call .

(3) After step 2 is executed, the two parties would be on a direct call (no conference)

(4) When you want to upgrade the call to a conference , POST to the child call SID with Url set to Twiml To Dial into conference ,

Example : 
curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACxxxxxxxxxxxx/Calls/CAyyyyyyyyyyyyyy -d "Url=http://www.mocky.io/v2/584ac0f81000002b14fb0205" -d "Method=GET"  -u ‘accountSID:authToken'

It is important that you modify the child leg of the call .

(5) Here is what will happen when you execute step 4

  • Child call will be redirected to the Url and would be dialed into the conference
  • Parent call will move to action and would be dialed in the same conference

Hope this helps.

Odonnell answered 9/12, 2016 at 15:9 Comment(4)
But won’t a request be sent to the action url every time the called party hangs up as well? Can you use the DialCallStatus parameter to determine if the call ended because the called party got dialed into a conference?Counterwork
Big thanks to @Odonnell for adding the explanation in step 5) of the answer. This bit of information isn't entirely clear from the docs and was the help I needed to make this work for my situation.Kherson
@Kherson Glad you found it useful!Odonnell
great post. thanks. def helped us. no other documentation found about this issue. Question: how do we keep the same recording going for the whole call session. Currently, it's 1 for the direct and 1 for the conference part. Any help appreciated. Thanks!Astigmatic
B
5

Twilio evangelist here.

So the best answer is to just put both calls into a conference to start. Its a little more difficult since you have to use the API to initiate the second leg, but it gives you a lot more flexibility to move call legs around.

If thats not possible, then it gets a bit more challenging since there isn't a great way today to get the SID of the second call. What you would likely need to do is use the Calls list resource in the REST API to find the SID of that second call. You can use the list filter parameters To and Status to find the specific call. Once you have the call resource of the second leg, it contains a parameter called parent_call_sid which is the SID of the original incoming call.

Now that you have the SID's for both call legs you can use the REST API to redirect both calls to new Voice Urls which return TwiML containing the <Conference> noun.

Hope that helps.

Barbarity answered 7/4, 2014 at 17:44 Comment(6)
when I update the incoming call to a conference one it ends the outgoing one, and if I update the outgoing call to a conference one it ends the incoming one, how can I update both calls simultaneously?Inoperative
Devin, so who starts the call is always the parent, and who receives is the child SID ? Thanks!Inhesion
@Brayan, correct. The incoming call is considered the "parent" and the outgoing call made via the <Dial> verb is the "child"Barbarity
I'm wondering if there has been any updated on this situation in the last couple of years. What Timo above states is correct and is a problem. If you have a call established with the Dial verb between two callers, and these callers then desire to add a party they need to be moved to a conference room first. However, when the first party is moved to the conference room the other party (regardless of which it is) is immediately disconnected.Slug
@Slug , please see me response below .Odonnell
@DevinRader I'm using twilio.js so starting in a conference call has the problem of not hanging up on the user when I hang up through Twilio.Device.Zettazeugma
A
5

Twilio employee here.

To add to am1704's answer, a variation on the same theme is to use the <Redirect> verb after <Dial>:

<Response>
  <Dial>
    <Number>+44xxxxxxxx</Number>
  </Dial>
  <Redirect method="GET">http://www.mocky.io/v2/584ac0f81000002b14fb0205</Redirect>
</Response>

Once the child call has been moved to the conference, the TwiML will continue with the verb after <Dial>.

Both techniques require knowledge of the call state. In some calls, the desired next step might be <Hangup>. In others, one might want to move the parent leg to a conference.

Automat answered 9/12, 2016 at 15:52 Comment(2)
How could we use knowledge of the call state to determine whether to hang up or dial the parent leg into the conference?Counterwork
You would need to know the intent of the caller. By default I imagine you would want to hangup the call; but if the caller wanted to add a third party, they would first have to promote a 1:1 call to be a conference, and that action would cause the application controlling the call flow to return the appropriate TwiML.Automat
A
1

This thread was helpful, but one suggestion to add to what am1704 said-

If you want to avoid using the action= method am1704 used, you can also move the child leg, then the parent leg with a second HTTP (curl) request. Note that the direction of the call is important here: the parent leg is whatever leg was dialed first. It's also important that you execute each curl request one right after another, not simultaneously.

Here's an example of how to send an HTTP request in node.js that will update one of the legs. You'd need to execute it twice.

var ACCTSID = process.env.ACCTSID;  // Twilio Account SID
var AUTHTOKEN = process.env.AUTHTOKEN;  // Twilio Auth Token
var request = require('request');

function parentFunction() { // update a call in progress to move it to a conference

  console.log('parameter: ' + parent); // log param

  SID = parent.SID ; console.log('SID to add to conf: ' + SID); // The SID of the parent call
  end = parent.end ; console.log('end call on exit: ' + end) // end conference on exit - true or false
  xml = '<Response><Dial><Conference endConferenceOnExit=\"' + end + '\" beep=\"' + beep +'\">' + key + '</Conference></Dial></Response>'; console.log('xml: ' + xml); //xml

  formData = {
    Twiml: xml
    }

   options = { 
     method: 'POST',
     auth: {
       user: ACCTSID,
       pass: AUTHTOKEN
     },
     url: 'https://api.twilio.com/2010-04-01/Accounts/' + ACCTSID + '/Calls/' + SID + '.json',
     headers:
     { 
       'cache-control': 'no-cache',
       'Content-Type': 'text/plain'
     },
     form: formData //your payload
   };

   request(options, function (error, response, body) {
     if (error) throw new Error(error);
     console.log('response body for: ' + SID + ':' + body);

  });
}
Aubrey answered 9/11, 2020 at 8:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.