Objective
This article aims to guide you through the process of setting up time-of-day routing in Twilio Studio using Liquid variables. This setup allows you to direct incoming calls based on specific time periods and days, enhancing your call management efficiency.
Product
Twilio Studio
User Account Permission/Role(s) Required
- Access to Twilio Console
- Permissions to create and modify Studio Flows
Procedure
1. Create a New Studio Flow
- Log in to Twilio Console and navigate to the Studio section.
- Create a new Studio Flow by clicking on the "Create new Flow" button.
- Name your flow and select "Start from scratch."
2. Set Up Variables
- Add a 'Set Variables' Widget to your flow.
-
Define the following variables using Liquid syntax:
-
day
:{{'now' | date: "%A"}}
- This captures the current day of the week. -
time
:{{'now' | date : "%l %M %p "}}
- This captures the current time. -
hour
:{{'now' | date: "%k"}}
- This captures the current hour in 24-hour format.
-
Warning
When using the now
keyword, the resulting time will be output in US Pacific Time, not UTC.
3. Implement Time-Based Logic
-
Add a 'Split Based On' Widget to evaluate the
hour
variable. -
Set conditions to route calls based on business hours. For example:
- Use a regex condition to match business hours:
\b(1[8-9]|2[0-3]|0[0-5])\b
for hours between 6 PM and 6 AM. - Route calls to a "Closed" message outside business hours and to an "Open" message during business hours.
- Use a regex condition to match business hours:
4. Configure Call Routing
-
Add 'Say/Play' Widgets to handle different call outcomes:
- A widget for "We are open" during business hours.
- A widget for "We are closed" after business hours.
5. Test Your Flow
- Publish your flow and configure your Twilio phone number to use this flow.
-
Test by calling the number to ensure calls are routed correctly based on the time of day.
Additional Considerations
- Time Zone Management: Ensure your server's time zone aligns with your business hours. You may need to adjust the regex to match your local time zone.
- Liquid Variables: Liquid syntax is powerful for dynamic content but may require some learning. Refer to Twilio's Liquid documentation for more details.
-
Studio Time Zone: The time zone in Studio is set to San Francisco Time, observing San Francisco's time zones.
Additional Information
- Using Twilio Functions to Add Custom JavaScript Code in Studio Flows
- Build a Serverless Call Routing Application with Time Zone Management in JavaScript
By following these steps, you can effectively manage call routing based on the time of day, enhancing customer satisfaction and operational efficiency.