1

I have implemented Twilio Conference call using Twilio JavaScript SDK and PHP. So far, the functionality that is working is:

  1. Agent can make an outgoing call from browser to a mobile phone
  2. Agent can receive an incoming call on browser from another phone
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML\VoiceResponse;
use Twilio\Rest\Client;

$response = new VoiceResponse();
$dial = $response->dial('');
$dial->conference('first-conference-room',
    ['startConferenceOnEnter' => 'true', 'endConferenceOnExit' => 'true']);

$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);

$twilio->conferences("first-conference-room")
                      ->participants
                      ->create($fromnumber,
                               $tonumber,[
                       "statusCallbackEvent" => ["ringing","initiated","answered","completed"],
                       "statusCallback" => "link-to-php-function-to-write-call-record-to-database",
                       "statusCallbackMethod" => "POST"
                          ]);
return $response;
?>

Now, as a supervisor, once a conference call is established between the agent (using browser) and another phone number, I fetch and show the ongoing call's record with a button to join as a supervisor.

Any suggestion on what can be done so 3rd person can join the conference as supervisor or coach?

A separate question - Is a Twilio conference between three people (numbers) charged as two Twilio voice calls or one Twilio voice call with third person joining the conference for a smaller fee?

Manish Jain
  • 65
  • 1
  • 6

1 Answers1

0

Your supervisor is also in a browser, so when you click the join button, I assume you are making a call with the Twilio Voice SDK and your TwiML App directs the webhook to your endpoint that runs the second block of code from your question.

When you want to coach a call, you actually want more than just muting. You want to be able to listen to the call, talk to the agent without the person on the other end hearing, or barge in and talk to both people in the conference. To do this you need to use the coach attribute of the <Conference> TwiML.

To use coach you need to get the SID of the agent's call leg. If the agent is placing the outbound call from the browser, then their SID will be the CallSid parameter that is sent to your webhook URL. If they are receiving the call, then their call SID is returned from the API call to create a participant in the conference.

Once you have the SID, in the webhook response for your agent you need to dial into the conference and add the coach attribute with the value of the agent's call SID.

$response = new VoiceResponse();
        $dial = $response->dial('');
        $dial->conference('first-conference-room', ['coach' => $agentCallSid ]);
        echo $response;

A separate question - Is a Twilio conference between three people (numbers) charged as two Twilio voice calls or one Twilio voice call with third person joining the conference for a smaller fee?

Twilio charges per leg of call. Each connection between Twilio and a caller is a leg. So in this case, three people in a conference are three legs and are charged the conference rate per minute each.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • Hi @philnash, supervisor has twilio device intialised on his browser using Javascript SDK. Currently, when supervisor clicks the join button, a post call is made to the PHP function supervisecall() which has the dial->conference code. I have added that code to the original question. Who should supervisor initiate the call to using Javascript SDK? We don't want his phone or conference to be ringing for him to join the ongoing conference call. Hope it makes sense. – Manish Jain Aug 11 '22 at 13:00
  • Your Supervisor should dial into the conference using the Twilio `Device`, not make a `POST` request to your own server. Alternatively, you can make a `POST` request to your own server, but what the server should do is [create a participant in the conference](https://www.twilio.com/docs/voice/api/conference-participant-resource#create-a-participant) setting the properties `coaching` and `callSidToCoach` and using the identity of the supervisor, which will place a call to the supervisor in the browser and join them to the conference. – philnash Aug 12 '22 at 02:55
  • how do we dial into conference using Twilio Device? Twilio.Device.connect requires a number to dial. **About second option-** When I create a participant in the conference, it again requires the from and to numbers, which works if I use the **From=** twilio caller id and **to=** browser client name, but then it rings the phone and supervisor has to answer it, rather than joining the call on pressing on Join button. – Manish Jain Aug 12 '22 at 03:06
  • 1
    A Twilio Device doesn’t require a number to dial, it passes the parameters that you pass to `connect` onto the webhook URL you define in your TwiML app. It is the TwiML that defines what call the Device makes/joins. This is the process you should use to place the call with the Device when you click join. – philnash Aug 12 '22 at 03:19
  • Thanks Phil. I was missing this point. Now, I was able to join as coach but rather than agent, other party was able to listen to me. How do I get the callsid of the agent call (first leg), not the call to customer phone (second leg)? – Manish Jain Aug 13 '22 at 13:11
  • 1
    When an agent makes an outgoing call, their call Sid is in the parameters sent to your webhook. When the agent receives the incoming call, their call Sid is in the parameters returned from the API request to create a conference participant. – philnash Aug 15 '22 at 01:51