Menu

Expand
Rate this page:

Time of Day Routing

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

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

This attribute contains current hour as string in HH formt with hour represented in 24hr clock 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

taskrouter.currentMin

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

taskrouter.currentMin > 10 AND taskrouter.currentMin < 50

taskrouter.dayOfWeek

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

Day of the Week taskrouter.dayOfWeek
Monday Mon
Tuesday Tue
Wednesday Wed
Thursday Thu
Friday Fri
Saturday Sat
Sunday Sun

Example

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

{
    "task_routing": {
        "filters": [
            {
                "targets": [
                    {
                        "queue": "WQ57cab415732dec475f600c75eab44cc9"
                    }
                ],
                "filter_friendly_name": "MyFilterName",
                "expression": "(taskrouter.dayOfWeek IN ['Mon', 'Tue', 'THU'] 
                                AND taskrouter.currentTime > 800 
                                AND taskrouter.currentTime < 1730) 
                            OR 
                                (taskrouter.dayOfWeek IN ['Wed', 'Fri'] 
                                AND taskrouter.currentTime > 900 
                                AND taskrouter.currentTime < 1830) 
                            OR 
                                (taskrouter.dayOfWeek = 'Sat' 
                                AND taskrouter.currentTime > 1100 
                                AND taskrouter.currentTime < 1530)"
            }
        ],
        "default_filter": {
            "queue": "WQ78e472fe73068cf03c533099dbaa453b"
        }
    }
}
Rate this page:

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.

        
        
        

        Thank you for your feedback!

        We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

        Sending your feedback...
        🎉 Thank you for your feedback!
        Something went wrong. Please try again.

        Thanks for your feedback!

        Refer us and get $10 in 3 simple steps!

        Step 1

        Get link

        Get a free personal referral link here

        Step 2

        Give $10

        Your user signs up and upgrade using link

        Step 3

        Get $10

        1,250 free SMSes
        OR 1,000 free voice mins
        OR 12,000 chats
        OR more