javascriptphptwiliotwilio-apitwilio-twiml

Dequeue Twilio call reservation to a conference room


I am trying to dequeue an enqueued inbound call to a conference room using PHP/Symfony and the JavaScript Voice SDK.

What I have working now is dequeuing the call to an individual agent. But I want to enable supervisory monitoring and coaching. For this, it seems, I need a conference room.

On the server side I enqueue the call using the default "Assign to Anyone" workflow...

        $voiceResponse = new VoiceResponse;
        $enqueue = $voiceResponse->enqueue('',['workflowSid' => $ccmanager->getWorkflowSid()]);
        $xml = $voiceResponse->asXml();
        $response = new Response($xml, Response::HTTP_OK, ['context-type' => 'text/xml']);
        return $response;

Client side, when one of the agents decides to pick up the call, I dequeue the reservation...

this.dequeueReservation = function(data)
{
    let contactUri = self.getContactUri();
    let reservation = self.getReservation(data.phone_number);
    if(reservation) {
        console.log('before reservation dequeue');
        reservation.dequeue(
            null,
            null,
            'record-from-answer',
            30, // seconds to answer
            'https://d72d-76-18-83-142.ngrok.io/anon/voice/status', // status callback url
            'initiated,ringing,answered,completed',
            contactUri,
            (error, newReservation) => onDequeue(data, error, newReservation)
        );
    }
}

Where getContactUri() is...

this.getContactUri = function() {
    switch(self.agent.call_routing) {
        case 'workstation':
            return 'client:' + self.agent.worker_name;
        case 'business_phone':
            return '+1' + self.agent.business_phone;
        case 'other_phone':
            return '+1' + self.agent.other_phone;
        default:
            return null;
    }
}

So all this works great, but there is no way to add supervisor functions with this approach (apparently). What I need to do (apparently) is to dequeue the reservation to a conference room and then separately connect the agent to the conference room.

This would be easy if I was able to create a contactUri for a conference room. However there does not seem to be a 'conference_room:" form of the contactUri however.

Alternately I could perhaps, server-side, route the inbound call first to a conference room and then enqueue the conference room. This does not seem possible.

In any event I need the task queue as part of the solution so I can properly route calls to the various agents.

How do I do this?


Solution

  • To dequeue to a conference, you can use either the REST API or the Taskrouter Javascript client.

    REST API

    Update a Member Resource

    // Download the helper library from https://www.twilio.com/docs/node/install
    // Find your Account SID and Auth Token at twilio.com/console
    // and set the environment variables. See http://twil.io/secure
    const accountSid = process.env.TWILIO_ACCOUNT_SID;
    const authToken = process.env.TWILIO_AUTH_TOKEN;
    const client = require('twilio')(accountSid, authToken);
    
    client.queues('QUXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
          .members('CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
          .update({url: 'https://example.com'})
          .then(member => console.log(member.callSid));
    

    The url is the above example is the url that will return Twiml for a conference.

    Create A Simple Conference

    const VoiceResponse = require('twilio').twiml.VoiceResponse;
    
    
    const response = new VoiceResponse();
    const dial = response.dial();
    dial.conference('Room 1234');
    
    console.log(response.toString());
    

    The Twiml that A Simple Conference produces:

    <?xml version="1.0" encoding="UTF-8"?>
    <Response>
      <Dial>
        <Conference>Room 1234</Conference>
      </Dial>
    </Response>
    

    Taskrouter.js Client

    Use reservation.conference

    reservation.conference(
        "18004746453",
        "WAxxx",
        "30",
        "client:joey",
        function(error, reservation) {
            if(error) {
                console.log(error.code);
                console.log(error.message);
                return;
            }
            console.log("conference initiated");
        }
    );