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
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
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
Hope this helps.
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.
<Dial>
verb is the "child" –
Barbarity Twilio.Device
. –
Zettazeugma 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.
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);
});
}
© 2022 - 2024 — McMap. All rights reserved.