0

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?

Manish Jain
  • 65
  • 1
  • 6

1 Answers1

1

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.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • Thanks. I was able to place an outgoing call (conference) with the other party, yet to test the incoming part, where the other party calls the Twilio number. Three questions - 1. The conference didn't end when the other party ended the call at their end. 2. How do I change the background music until the call is answered by agent? 3. How can a supervisor monitor this call / listen in to this call? – Manish Jain Jul 22 '22 at 05:17
  • 1
    1. You'll need to set [`endConferenceOnExit`](https://www.twilio.com/docs/voice/twiml/conference#attributes-endConferenceOnExit) to be true. 2. You can set a [`waitUrl` to control hold music](https://www.twilio.com/docs/voice/twiml/conference#attributes-waitUrl) (yes, the default music is bad, you should change it ). 3. You'll want to look into the coaching features known as [Agent Conference](https://www.twilio.com/blog/2017/12/agent-conference-generally-available.html) for monitoring, coaching and barging in. – philnash Jul 23 '22 at 01:01
  • I updated the code to add endConferenceOnExit, still the conference ends only when agent ends, not when participant ends. $dial->conference($conferenceName,['startConferenceOnEnter' => 'true', 'endConferenceOnExit' => 'true']); – Manish Jain Jul 23 '22 at 01:47
  • You'll need to set [`endConferenceOnExit` for the participants you add via the REST API](https://www.twilio.com/docs/voice/api/conference-participant-resource?code-sample=code-create-a-conference-participant&code-language=PHP&code-sdk-version=6.x#participant-properties) as well then. – philnash Jul 23 '22 at 01:48
  • Thanks mate, waiturl worked. Still struggling with ending the conference when the participant ends my outgoing call to them. Is it because I am adding the participant and myself in the same conference create function call? Do I need add the participant separately? – Manish Jain Jul 24 '22 at 08:02
  • Might be a good idea to ask a new question and share the code you are now using. – philnash Jul 24 '22 at 12:14