Hey guys,
One of our issues with Zoho desk is the inability to route to external numbers depending on the time of day.
Because our agents are not 24/7 on the desk, we will sometimes get calls after hours which will cause the customer to leave a message, which isn't ideal as some issues are urgent.
We use a 3rd party answering service to ensure that after hours calls get routed to the on-call technician's mobile phone, and if they don't answer, we have at least someone taking down the information needed to log a ticket with urgency.
We couldn't get this functionality in Zoho desk, but we could create it using
Twillio Functions.
Note: Twillio notes that Functions are
BETA - it's an additional cost, but the 10,000 invocations are free.
Note that this will change the Webhooks that Zoho Desk set using the Twillio API. I'm unsure how frequently these API's get checked/changed, so this may break (
untested). Does anyone have any insight on this?
Let's get started.
First, let's create the Node.js code on Twillio Functions.
Log into Twillio - go to
RunTime > Functions
Create a new function and give it a path name and function name.
I called it
"Call Forward"
.
The code is as below (note we take no responsibility or warranty for this code).
- exports.handler = function(context, event, callback)
- {
- let callerId = event.CallerId || null;
- let timeout = event.Timeout || null;
- //---
-
- let twiml = new Twilio.twiml.VoiceResponse();
-
- //Get time/date information
-
- var date = new Date();
- var day = date.getDay();
- var current_hour = date.getHours();
-
-
- //Check if Past 5pm or Saturday/Sunday
-
- if(current_hour > 17 || (day > 5 || day === 0) )
- {
- twiml. say("You have reached our after hours support, please hold while we direct your call") // Replace this with your own message or remove it if you just want it to redirect.
-
- //Set dial forwarding dial parameters
- let dialParams = {};
- if (callerId) {
- dialParams.callerId = callerId;
- }
- if (timeout) {
- dialParams.timeout = timeout;
- }
- twiml.dial(dialParams, "+6100000000"); //Replace with your forwarding number!
- callback(null, twiml);
- }
- else
- {
- //Forward to the DESK!
-
- twiml.redirect({
- method: 'POST'
- }, 'https://desk.zoho.com/newctiapi/xml/cticall/twillio?cx0d0d0x0x0x'); // Replace this with the webhook set by Desk
-
- callback(null, twiml);
- }
-
- twiml.say('Sorry, something went wrong. Please email us at help@help.com. Goodbye.');
- // return the TwiML
- callback(null, twiml);
- };
Save the code.
Now go to
Phone Numbers > Active Numbers > (Click on your Desk Phone Number)
Where is says
A CALL COMES IN
Change this to Functions and select the function you just created.
Note that you will need to pull the Webhook and put this URL into line 42 of the code above
I hope this helps someone else in need of time based call routing