Search code examples
phpandroidtwilioconferencing

Error while doing conferencing in Twilio


I am developing an application for doing voice calls via Twilio API But it disconnects after first call.

Here is my code:

my index.php

<?php
$serverroot=$_SERVER['DOCUMENT_ROOT'].'/twilioapi/twilio-php-master/Services/Twilio.php';
require($serverroot); 
$version = "2010-04-01"; 
 $num= '+1 218-461-4418';
 $num1= '+91$$$$$$$$$$$';
 $num2= '+91$$$$$$$$$$$';
 $num3= '+91$$$$$$$$$$$';  

$account_sid = '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$'; 
$auth_token = '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$'; 
$client = new TwilioRestClient($account_sid, $auth_token); 

  $participants = array($num1, $num2, $num3);

  // Go through the participants array and call each person.
  foreach ($participants as $particpant)
  {
    $vars = array(
      'From' => $num,
      'To' => $participant,
      'Url' => 'http://my_url.com/twilioapi/mytest2.xml');

    echo $response = $client->request("/$version/Accounts/$account_sid/Calls", "GET", $vars);
  }

//echo json_encode($response);

?>

xml file

<Response>
    <Say>Joining a conference room</Say>
       <Dial>
         <Conference>MyRoom</Conference>
       </Dial>
</Response>

regards


Solution

  • Twilio developer evangelist here.

    I'm not sure why your code would make one call and then disconnect. I can tell you one thing I'd do differently though, which might help.

    Instead of making the call to the API using a TwilioRestClient object like you did:

    // Set up $client
    $client = new TwilioRestClient($account_sid, $auth_token); 
    // Make request (using $vars from loop)
    $client->request("/$version/Accounts/$account_sid/Calls", "GET", $vars);
    

    You can actually require the Services_Twilio class and make calls much easier with it:

    // set up $client
    $client = new Sevices_Twilio($account_sid, $auth_token);
    
    // set up participants then...
    
    foreach ($participants as $particpant) {
      echo $response = $client->account->calls->create(
        $num,          // The from number
        $participant,  // The to number
        'http://my_url.com/twilioapi/mytest2.xml'
      );
    

    }

    One other thing that occurs to me. The call to the Calls endpoint to create a call should be a POST not a GET. Perhaps that is why it is failing. Using the Services_Twilio object should help with that though.

    Take a look at the documentation on creating calls or let me know if you need any further help.