I've got a need to create a Twilio IVR for a virtual call center with some basic requests.
- Incoming call connects and requests inputs from caller.
- 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.
- 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.
- 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.
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!