Workflow Resource
Workflows control how tasks will be prioritized and routed into Queues, and how Tasks should escalate in priority or move across queues over time. Workflows are described in a simple JSON format and can be modified through the REST API or through the account portal. You can learn more about Workflows here.
You specify which Workflow should control a Task when you add the Task to the Workspace. The Workflow will manage the Task's queue and priority until it is either assigned to a Worker, removed from the queue, or modified.
When a Task is assigned to a Worker, your application will receive a callback to the Workflow's AssignmentCallbackUrl
, and your application can then do whatever is required to deliver the Task to the worker (for example, instructing Twilio to dial the phone number of the Worker selected to receive the call). Read more about Task assignment here.
Multiple Workflows
A Workspace can contain multiple Workflows. This allows you to have different sets of routing rules for different types of applications or situations.
For example, a call center has one group of Workers that handles both phone and chat tasks. These two Task types have different service-level targets and agent requirements. They will also originate from separate external applications. To separate application concerns, the call center creates a single Workspace with two separate Workflows, one for phone calls and the other for chat requests.
Creating and Distributing Tasks
Whenever you add a Task to a Workspace you indicate which Workflow should route the Task. The Workflow will prioritize the task and place it into a queue, where it will be distributed to the first available Worker that has the necessary capabilities. See the Task Resource for more information.
Handling Task Assignments with the AssignmentCallbackUrl
Every Workflow has an AssignmentCallbackURL
property, as well as a FallbackAssignmentCallbackUrl
in case requests to the first URL fail. When a Worker is assigned a Task, TaskRouter will make an HTTP request to this URL. Your application must handle this request to then do whatever is required to connect the Task to the Worker in your application. For example, this might mean pushing a case to an instance of an agent's web application, or dialing an agent's phone number using Twilio. See this section for more information on handling Task Assignment callbacks.
The AssignmentCallbackUrl is not required if you are planning on using just the JS SDK. In that case, simply leave the value blank.
If we cannot hit your AssignmentCallbackUrl
or FallbackAssignmentCallbackUrl
, TaskRouter will automatically change your Reservation status to canceled
. To get a better sense of how assignment callbacks work, use a tool like Beeceptor to ensure that the assignment callback is firing correctly and to examine the contents of the post.
Workflow properties
Pagination is not supported under this resource. Please avoid usage of the page
query parameter.
Resource Properties in REST API format | |
---|---|
account_sid
|
The SID of the Account that created the Workflow resource. |
assignment_callback_url
|
The URL that we call when a task managed by the Workflow is assigned to a Worker. See Assignment Callback URL for more information. |
configuration
|
A JSON string that contains the Workflow's configuration. See Configuring Workflows for more information. |
date_created
|
The date and time in GMT when the resource was created specified in RFC 2822 format. |
date_updated
|
The date and time in GMT when the resource was last updated specified in RFC 2822 format. |
document_content_type
|
The MIME type of the document. |
fallback_assignment_callback_url
|
The URL that we call when a call to the |
friendly_name
|
The string that you assigned to describe the Workflow resource. For example, |
sid
|
The unique string that we created to identify the Workflow resource. |
task_reservation_timeout
|
How long TaskRouter will wait for a confirmation response from your application after it assigns a Task to a Worker. Can be up to |
workspace_sid
|
The SID of the Workspace that contains the Workflow. |
url
|
The absolute URL of the Workflow resource. |
links
|
The URLs of related resources. |
Create a Workflow resource
https://taskrouter.twilio.com/v1/Workspaces/{WorkspaceSid}/Workflows
Parameters
Parameters in REST API format | |
---|---|
workspace_sid
Path
|
The SID of the Workspace that the new Workflow to create belongs to. |
friendly_name
Required
|
A descriptive string that you create to describe the Workflow resource. For example, |
configuration
Required
|
A JSON string that contains the rules to apply to the Workflow. See Configuring Workflows for more information. |
assignment_callback_url
Optional
|
The URL from your application that will process task assignment events. See Handling Task Assignment Callback for more details. |
fallback_assignment_callback_url
Optional
|
The URL that we should call when a call to the |
task_reservation_timeout
Optional
|
How long TaskRouter will wait for a confirmation response from your application after it assigns a Task to a Worker. Can be up to |
Example 1
Fetch a Workflow resource
https://taskrouter.twilio.com/v1/Workspaces/{WorkspaceSid}/Workflows/{Sid}
Parameters
Parameters in REST API format | |
---|---|
workspace_sid
Path
|
The SID of the Workspace with the Workflow to fetch. |
sid
Path
|
The SID of the Workflow resource to fetch. |
Example 1
Read multiple Workflow resources
https://taskrouter.twilio.com/v1/Workspaces/{WorkspaceSid}/Workflows
Parameters
Parameters in REST API format | |
---|---|
workspace_sid
Path
|
The SID of the Workspace with the Workflow to read. |
friendly_name
Optional
|
The |
Example 1
Update a Workflow resource
https://taskrouter.twilio.com/v1/Workspaces/{WorkspaceSid}/Workflows/{Sid}
Modifies a Workflow. Whenever you modify a workflow, the following will take place:
- TaskRouter validates your Workflow configuration to ensure it is syntactically correct and that all queues referenced in the document exist. If any problems are found, the update will fail, and the active Workflow will remain in place.
- Assuming there are no problems with the configuration provided, TaskRouter will use the previous Workflow to route any Tasks that were pending prior to the change. New Tasks will begin using the updated Workflow immediately.
Parameters
Parameters in REST API format | |
---|---|
workspace_sid
Path
|
The SID of the Workspace with the Workflow to update. |
sid
Path
|
The SID of the Workflow resource to update. |
friendly_name
Optional
|
A descriptive string that you create to describe the Workflow resource. For example, |
assignment_callback_url
Optional
|
The URL from your application that will process task assignment events. See Handling Task Assignment Callback for more details. |
fallback_assignment_callback_url
Optional
|
The URL that we should call when a call to the |
configuration
Optional
|
A JSON string that contains the rules to apply to the Workflow. See Configuring Workflows for more information. |
task_reservation_timeout
Optional
|
How long TaskRouter will wait for a confirmation response from your application after it assigns a Task to a Worker. Can be up to |
re_evaluate_tasks
Optional
|
Whether or not to re-evaluate Tasks. The default is |
Example 1
Delete a Workflow resource
https://taskrouter.twilio.com/v1/Workspaces/{WorkspaceSid}/Workflows/{Sid}
Deletes a Workflow. Will return an error if there are any pending or reserved Tasks still being controlled by this Workflow.
Parameters
Parameters in REST API format | |
---|---|
workspace_sid
Path
|
The SID of the Workspace with the Workflow to delete. |
sid
Path
|
The SID of the Workflow resource to delete. |
Example 1
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 by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.