The call center operates weekdays only and is closed during the holidays. Also, the call center closes early on the day before special holidays. The product team wants to play a message in the IVR during the close hours.
Setting up the schedule requires
- Service – Environment as a service(server) that handles functions and assets.
- Function – API that provides status of the working hours based on the current datetime.
- Asset – JSON file for the schedule.
- Integration with IVR
Service
Represents a service environment which handles functions and assets as well as environments and 3rd party dependencies. To create functions and assets, this is a must have.
Manage Services
Twilio Console → Functions and Assets → Services
Create a new service if needed. I named it schedule as you see on the screenshot below.
Once you select the service, you will see this screen.
I already added the code as a function and the JSON file as an asset.
The API endpoint is /get-schedule and the JSON file name is USSchedule.json which is named based on the combination of the country name and the filename as {country}Schedule.json.
Function
This is an API written in Node.js.
Parameters
Key | Value |
country | US |
timezone | New_York |
Response
{ |
Code
const axios = require('axios'); |
Asset/JSON file for the schedule
IMPORTANT This JSON file should be updated yearly due to the holidays and irregular hours. The schedule must be a valid JSON format. Ensure the JSON format via JSONLint. For detailed schema, refer to https://www.twilio.com/blog/advanced-schedules-studio.
{ |
We have three keys: holidays, partialDays and regularHours. On Holidays, the contact center is closed the entire day. On Partial Days, we have irregular hours, and we also include the Regular hours. The evaluation will be done from top to bottom, first we check for a holiday, then for a partial day, then finally the regular schedule.
Dependencies
The service runs with node v14. I could add the latest version of the following libraries at this moment.
- axios; 0.27.2
- moment-timezone; 0.5.37
- moment-range; 4.0.2
To add the dependencies, click the Dependencies link on the left bottom navigation pane as shown on [Figure 2].
Deploy
Everytime any changes are made, the Deploy All button must be hit to load everything up on the service. Refer to [Figure 2].
TIP Enabling live logs prints out all logs and errors for better debugging while testing integrations such as IVR in this case.
Integration with IVR
Put the Studio Flow and Scheduling Function together.
Here’s the JSON for the Studio Flow above.
{ |