Sisir
Sisir

Reputation: 2804

Twilio Multiple Number Dialing, What is Equivalent in REST API of Given TWIML

As we know it is very easy to dial multiple numbers at once via TwiML. Note That, Once one of the dialed numbers picks up. Rest of the numbers are disconnected automatically.

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Dial>
    <Number>415-123-4567</Number>
    <Number>415-321-7654</Number>
    <Number>415-456-7890</Number>
  </Dial>
</Response>

But What would be the Equivalent of this REST API? Considering I am using PHP helper libraries. I can make single number call like this.

// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "{{ sid }}";
$token = "{{ auth_token }}";
$client = new Services_Twilio($sid, $token);

$call = $client->account->calls->create("+14158675309", "+14155551212", "http://demo.twilio.com/docs/voice.xml", array());

My guess is I can loop through numbers to create single calls. But how do disconnect other numbers when one call is picked up?

Upvotes: 2

Views: 1347

Answers (1)

Devin Rader
Devin Rader

Reputation: 10366

Twilio evangelist here.

I think what you'd need to do in order to create a simul-dial app using the REST API is create a loop that initiates all of the outbound calls you want to make. Each time you start a new call save the CallSid for that call in an some kind of datastore like a database.

Which ever call answers first it is going to make an HTTP request to the URL you specified when you created the call. In that PHP file you can loop over that list of CallSids you saved earlier and use the REST API to set all but that first calls Status property to "completed". Doing this tells Twilio to hang up on all of the other calls.

Hope that helps.

Upvotes: 3

Related Questions