Skip to contentSkip to navigationSkip to topbar
On this page

Time of Day Routing for TaskRouter


TaskRouter supports time of day expressions that can be used in the Workflow in both Filter and Target Worker Expressions. When evaluating the expressions TaskRouter will fill in the attributes with appropriate values and continues to evaluate the entire expression.

The supported time of day expressions are as follows:


taskrouter.currentTime

taskroutercurrenttime page anchor

This attribute contains current time as an integer in HHMM format with the time represented in 24hr clock in UTC.

Use the following expression to check if the current time is between 8 AM UTC to 6:30 PM UTC,

taskrouter.currentTime > 0800 AND taskrouter.currentTime < 1830

taskrouter.currentHour

taskroutercurrenthour page anchor

This attribute contains the current hour as string in HH format, with the hour represented in 24-hour time notation in UTC.

Use the following expression to check if the current hour is between 8 AM UTC to 6 PM UTC,

taskrouter.currentHour > 8 AND taskrouter.currentHour < 18

This attribute contains current minute with time represented in UTC format.

taskrouter.currentMin > 10 AND taskrouter.currentMin < 50

This attribute contains the day of the week as string in time represented in UTC format.

Day of the Weektaskrouter.dayOfWeek
MondayMon
TuesdayTue
WednesdayWed
ThursdayThu
FridayFri
SaturdaySat
SundaySun

In this example we are checking for different open and closing hours based on day of the week and if place tasks into appropriate queues

1
{
2
"task_routing": {
3
"filters": [
4
{
5
"targets": [
6
{
7
"queue": "WQ57cab415732dec475f600c75eab44cc9"
8
}
9
],
10
"filter_friendly_name": "MyFilterName",
11
"expression": "(taskrouter.dayOfWeek IN ['Mon', 'Tue', 'THU']
12
AND taskrouter.currentTime > 800
13
AND taskrouter.currentTime < 1730)
14
OR
15
(taskrouter.dayOfWeek IN ['Wed', 'Fri']
16
AND taskrouter.currentTime > 900
17
AND taskrouter.currentTime < 1830)
18
OR
19
(taskrouter.dayOfWeek = 'Sat'
20
AND taskrouter.currentTime > 1100
21
AND taskrouter.currentTime < 1530)"
22
}
23
],
24
"default_filter": {
25
"queue": "WQ78e472fe73068cf03c533099dbaa453b"
26
}
27
}
28
}

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.