Reputation: 21
I've got a need to create a Twilio IVR for a virtual call center with some basic requests.
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!
Upvotes: 0
Views: 267
Reputation: 306
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:
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.
Upvotes: 0