twiliotwilio-programmable-voicetwilio-conference

Twilio Voice conference from Browser using PHP


I have successfully implemented Voice calls functionality in my php application using JS SDK.

Now, I need to implement Call Monitoring and barge in features, that I believe are only available using Twilio Conference.

My current code looks like

$response = new VoiceResponse();
$dial = $response->dial('');
//If Incoming call, redirect the call to my browser client
if($phonenumber == $mytwiliophonenumber)
{
 $dial->client($browserclientname);
}
//If outgoing, make the call to the phone number
else
{
 $dial->number($phonenumber);
}

Now, what is the easiest way to change this to conference?

I have read that I need to dial the conference, but it is not working.

$dial->conference('anyconferencename');

Any guidance?


Solution

  • A conference has a fundamental difference to connecting two callers together in a regular dial. A conference acts as a room that participants join individually, rather than when you use client or number which places an outbound call leg to the client or number you are dialling.

    If you have your user dial into a conference using $dial->conference you will need to create another leg to call the other person into the conference too. You can do this using the conference participants API.

    So, instead of your current code, you could update to something like this:

    $response = new VoiceResponse();
    $dial = $response->dial('');
    //If Incoming call, redirect the call to my browser client
    if($phonenumber == $mytwiliophonenumber)
    {
      $participant = "client:" . $browserclientname;
    }
    //If outgoing, make the call to the phone number
    else
    {
      $participant = $phonenumber;
    }
    
    $conferenceName = 'conferencename';
    $twilio->conferences($conferenceName)
                          ->participants
                          ->create($mytwiliophonenumber, // from
                                   $participant, // to
                          );
    $dial->conference($conferenceName);
    

    In this option, regardless of whether the call is inbound or outbound, the caller is placed in a conference call. And another call is generated to add the other participant to the conference call too.