Routing Calls Based on the Time of Day
Introduction
This guide describes how to use the “Create a Condition” component to route calls to different extensions depending on the time of day, from a voice app created with the 3CX Call Flow Designer (formerly VAD). Date and time routing can be done in an easier way, without C# expressions, as explained in this guide. However, the concepts explained here can be useful to route inbound calls depending on the result of different expressions.
💡 Tip: The project for this example application is available via the CFD Demos GitHub page, and is installed along with the 3CX Call Flow Designer in your Windows user documents folder, i.e. “C:\Users\YourUsername\Documents\3CX Call Flow Designer Demos”.
Step 1: Create the Project
First, we need to create a new project. Open the CFD and go to “File” > “New” > “Project”, select the folder where you want to save it, and enter a name for the project, e.g. “TimeBasedRouting”.
Step 2: Add the Execute C# Code Components
For this example, we want to determine if the current time of day is within these hour ranges:
- 00 until 09
- 09 until 12
- 12 until 18
- 18 until 00
To do this, we use three “Execute C# Code” components, as we only need to check the first 3 ranges. If the current time is not within any of these 3 ranges, then we can be sure that the time is within the 4th range, i.e. 18 and 00.
We create the three “Execute C# Code” components as:
- “timeFrom0To9” using the C# code: return DateTime.Now.Hour < 9;
- “timeFrom9To12” using the C# code: return DateTime.Now.Hour >= 9 && DateTime.Now.Hour < 12;
- “timeFrom12To18” using the C# code: return DateTime.Now.Hour >= 12 && DateTime.Now.Hour < 18;
These components return boolean values,
To evaluate these results and transfer the call to different destinations depending on that, proceed to the next step.
Step 3: Add the Create a Condition Component
Add a “Create a Condition” component to execute different branches depending on the conditions we specify:
- Drag a “Create a Condition” component from the toolbox, and drop it into the design surface of the “Main” callflow.
- Select the component added, go to the “Properties” and rename it to “selectTimeRange”.
- Configure this component with 4 branches, named “from0to9”, “from9to12”, “from12to18” and “from18to0”:
- Now we need to set the “Condition” property for each branch to be the result of the “Execute C# Code” components created in the previous step. The condition must evaluate to true to execute the components inside the branch. Branch conditions are evaluated from left to right, so if the first branch condition is not met, the next one is evaluated. We use these conditions for each branch in this example:
- “from0to9”: timeFrom0To9.ReturnValue
- “from9to12”: timeFrom9To12.ReturnValue
- “from12to18”: timeFrom12To18.ReturnValue
- “from18to0”: leave empty, i.e. execute the components in this branch when no other branch is executed.
Step 3: Add Transfer Components
Now that we have our conditions ready, we need to add a “Transfer” component to each branch, so the call is transferred to a different internal extension in each case. To do this:
- Drag a “Transfer” component from the toolbox and drop it into each branch, until all branches have one.
- Configure each “Transfer” component with a different “Destination”, e.g., set each “Transfer” component’s “Destination” property to extension 101, 102, 103 and 104 respectively.
Note: The “Destination” property is an expression, i.e. if you enter constant string values, these should be quoted. This is because this property can also reference variables or be set with the result of a function invocation. Use the “Expression Editor” to easily create this constant value for you.
Step 4: Build and Deploy to 3CX Phone System
The project is ready to build and upload to our 3CX Phone System server, with these steps:
- Select “Build” > “Build All” and the CFD generates the file “TimeBasedRouting.zip”.
- Go to the “3CX Management Console” > “Advanced” > “Call Flow Apps” > “Add/Update”, and upload the file created by the CFD in the previous step.
- The Call Flow app is ready to use. Make a call to it, and you should be transferred to a different destination depending on the time of the day.
See Also
- Learn more about CFD components.
- Automated Telephone Ordering Voice app with CRM integration via the 3CX API.
- Sending emails from a CFD voice app.
- Using the Authentication Component to Validate Customers.
- Using the Credit Card Component.
- Text to Speech with the 3CX Call Flow Designer.
- Using the Loop component to navigate upwards
- Registering and making callbacks
- Using the survey component
- Using the CRM Lookup component
- See how to integrate your PBX with a CRM via the 3CX API.
Last Updated
This document was last updated on 29th April 2021
https://www.3cx.com/docs/cfd-routing-calls-time-day/