0
votes

I've got a need to create a Twilio IVR for a virtual call center with some basic requests.

  1. Incoming call connects and requests inputs from caller.
  2. Depending on digit input or voice input, outbound call(s) to agent(s) are created. This can be either simultaneous calling or first in, first out via TaskRouter.
  3. Call needs to have either Machine Detection or gather input to ensure agent connects. Mainly the objective is to avoid answering machines as virtual representatives may ignore calls resulting on personal VM picking up.
  4. If no agent connects within timeout, then direct inbound call to voicemail which gets transcribed and emailed to a group email.

Originally we had a solution in place via OpenVBX although I don't believe this is support (and there have been improvements to the Twilio platform which leads to new solutions). I've attempted to utilize only Twilio hosted platforms (StudioFlow) and functions.

Here is the StudioFlow flow that leads currently to TaskRouter. The TaskRouter Workflow then calls back functions that I'm attempting to use to connected to the queued caller.

enter image description here

The TaskRoute Workflow callback is: /assignment

exports.handler = function(context, event, callback) {
    const taskAttributes = JSON.parse(event.TaskAttributes),
        workerAttributes = JSON.parse(event.WorkerAttributes),
        client = context.getTwilioClient();

    client.calls.create({
        machineDetection: 'Enable',
        url: 'https://' + context.DOMAIN_NAME + '/agent-response?ReservationSid='+event.ReservationSid+'&TaskSid='+event.TaskSid,
        from: taskAttributes.called,
        to: workerAttributes.contact_uri
    });
};

Then the /agent-response

exports.handler = function(context, event, callback) {
    var status = '';
    console.log(JSON.stringify(event));

    if (event.AnsweredBy !== 'machine_start') {
        status = 'accepted';
    }

    if (status == 'accepted') {
        return callback(null, {
            'instruction': 'dequeue',
            'post_work_activity_sid': '<AVAILABLE-SID>'
        });
    } else {
        return callback(null,{
            'instruction': 'reject'
        });
    }
};

So currently the call goes out to the agent with machine detection. I cannot figure out how to dequeue/connect the outbound agent call with the queued TaskRouter call.

Does anyone have 1) suggestions how to do this more efficiently and/or 2) how to connect to the queued inbound sid?

Thanks!

1

1 Answers

0
votes

here is a way, how I can see your fix:

1) You don't need to use TaskRoute Workflow callback is: /assignment. You can setup all needed things on Workflow configuration page: enter image description here

2) Once you enqueued your call to the right queue, you will work with Reservations for agent (You can read more about it here )

worker.on("reservation.created", function (reservation) {

            reservation.conference(reservation.task.attributes.from, 

// use conference here, but you can use Dequeue or Call instead.

                "IDLE ActivitySid",
                undefined,
                `client:${Current Agent Client Key}`,
                undefined,
                {

some call configuration settings

                }); 
        });

3) The last step is to use Twilio.Device (you can read full spec here) to get and start this call by:

Twilio.Device.incoming(function (conn) {
                // accept the incoming connection and start two-way audio
                conn.accept();
        });

Let me know, if you need more support with building Twilio Call Center.