Task Resource
A Task represents a single item of work waiting to be processed. Tasks can represent whatever type of work is important for your team. Twilio applications can create tasks from phone calls or SMS messages. Your CRM or ticketing system can generate tasks from emails or chat messages sent in by your customers. Your own applications can create custom tasks representing whatever unique work your users handle.
Task properties
Taskの属性
すべてのTaskに属性が存在し、それを使って、アプリケーションがTaskをルーティングし、割り当て時に適切なアクションを実行するために必要などんな種類のデータも渡すことができます。 属性はJSONデータで表されます。次に例を示します。
{
"type": "call",
"contact": "+15558675309",
"customer-value": "gold",
"task-reason": "support",
"callSid": "CA42ed11..."
}
Task Version
Tasks have a version, represented in the ETag
header when you POST
or GET
the Task Resource. ETags
are a method of showing whether a resource has changed; if the ETag
is the same, then the resource is the same.
Tasks can also use the If-Match
header when updating or deleting a Task Resource. If the ETag
does not match the provided version, the operation will fail with a 412
response. You can then GET
the latest version of the Task and try updating it again. When the If-Match
is not provided, the Task will update without a check.
You can read about Task Mutation and Conflict Resolution to learn about working with Task versions.
Task Lifecycle
A Task does not have an explicit Lifecycle property, but it's an important concept for understanding how Tasks work. A Task's lifecycle is controlled by a Workflow, which will manage the Task's priority and find matching Workers to handle the Task. The Task State page and Workflows and Assignment page provide more detail on the Task lifecycle.
Resource Properties in REST API format | |
---|---|
account_sid
|
The SID of the Account that created the Task resource. |
age
|
The number of seconds since the Task was created. |
assignment_status
|
The current status of the Task's assignment. Can be: |
attributes
|
The JSON string with custom attributes of the work. Note If this property has been assigned a value, it will only be displayed in FETCH action that returns a single resource. Otherwise, it will be null. |
addons
|
An object that contains the addon data for all installed addons. |
date_created
|
The date and time in GMT when the resource was created specified in ISO 8601 format. |
date_updated
|
The date and time in GMT when the resource was last updated specified in ISO 8601 format. |
task_queue_entered_date
|
The date and time in GMT when the Task entered the TaskQueue, specified in ISO 8601 format. |
priority
|
The current priority score of the Task as assigned to a Worker by the workflow. Tasks with higher priority values will be assigned before Tasks with lower values. |
reason
|
The reason the Task was canceled or completed, if applicable. |
sid
|
The unique string that we created to identify the Task resource. |
task_queue_sid
|
The SID of the TaskQueue. |
task_queue_friendly_name
|
The friendly name of the TaskQueue. |
task_channel_sid
|
The SID of the TaskChannel. |
task_channel_unique_name
|
The unique name of the TaskChannel. |
timeout
|
The amount of time in seconds that the Task can live before being assigned. |
workflow_sid
|
The SID of the Workflow that is controlling the Task. |
workflow_friendly_name
|
The friendly name of the Workflow that is controlling the Task. |
workspace_sid
|
The SID of the Workspace that contains the Task. |
url
|
The absolute URL of the Task resource. |
links
|
The URLs of related resources. |
Create a Task resource
https://taskrouter.twilio.com/v1/Workspaces/{WorkspaceSid}/Tasks
パラメーター
Parameters in REST API format | |
---|---|
workspace_sid
Path
|
The SID of the Workspace that the new Task belongs to. |
timeout
オプション
|
The amount of time in seconds the new task can live before being assigned. Can be up to a maximum of 2 weeks (1,209,600 seconds). The default value is 24 hours (86,400 seconds). On timeout, the |
priority
オプション
|
The priority to assign the new task and override the default. When supplied, the new Task will have this priority unless it matches a Workflow Target with a Priority set. When not supplied, the new Task will have the priority of the matching Workflow Target. Value can be 0 to 2^31^ (2,147,483,647). |
task_channel
オプション
|
When MultiTasking is enabled, specify the TaskChannel by passing either its |
workflow_sid
オプション
|
The SID of the Workflow that you would like to handle routing for the new Task. If there is only one Workflow defined for the Workspace that you are posting the new task to, this parameter is optional. |
attributes
オプション
|
A URL-encoded JSON string with the attributes of the new task. This value is passed to the Workflow's |
例 1
Please contact us if your use case will require more than 25,000 in-flight Tasks for any given Workspace. We define in-flight Tasks as all Tasks that are not in status canceled
or completed
.
Fetch a Task resource
https://taskrouter.twilio.com/v1/Workspaces/{WorkspaceSid}/Tasks/{Sid}
パラメーター
Parameters in REST API format | |
---|---|
workspace_sid
Path
|
The SID of the Workspace with the Task to fetch. |
sid
Path
|
The SID of the Task resource to fetch. |
例 1
Read multiple Task resources
https://taskrouter.twilio.com/v1/Workspaces/{WorkspaceSid}/Tasks
パラメーター
Parameters in REST API format | |
---|---|
workspace_sid
Path
|
The SID of the Workspace with the Tasks to read. |
priority
オプション
|
The priority value of the Tasks to read. Returns the list of all Tasks in the Workspace with the specified priority. |
assignment_status
オプション
|
The |
workflow_sid
オプション
|
The SID of the Workflow with the Tasks to read. Returns the Tasks controlled by the Workflow identified by this SID. |
workflow_name
オプション
|
The friendly name of the Workflow with the Tasks to read. Returns the Tasks controlled by the Workflow identified by this friendly name. |
task_queue_sid
オプション
|
The SID of the TaskQueue with the Tasks to read. Returns the Tasks waiting in the TaskQueue identified by this SID. |
task_queue_name
オプション
|
The |
evaluate_task_attributes
オプション
|
The attributes of the Tasks to read. Returns the Tasks that match the attributes specified in this parameter. |
ordering
オプション
|
How to order the returned Task resources. y default, Tasks are sorted by ascending DateCreated. This value is specified as: |
has_addons
オプション
|
Whether to read Tasks with addons. If |
例 1
例 2
Tasks are deleted 5 minutes after either they are canceled or completed. You can still query events that occurred for a Task via the Events API.
EvaluateTaskAttributes で以下の演算子を使うことができます。
- 等号:
==
、=
- 不等号:
!=
- より大きい:
>
- より小さい:
<
- 以上:
>=
- 以下:
<=
- カッコ(演算子の優先度を示す):
( )
- 角カッコ(リスト/配列を示す):
[ ]
HAS
,>-
。比較式の左辺のTask属性の値にExpressionの右辺の文字列が含まれるかどうか判断します。IN
,<-
。Expressionの左辺のTask属性の値が右辺のリストに * 含まれるかどうか判断します。AND
- 左辺と右辺のサブExpressionが両方とも true の場合、true として解決されます。それ以外の場合は false として解決されます。OR
- 左辺と右辺のサブExpressionの一方または両方とも true の場合、true として解決されます。それ以外の場合は false として解決されます。
By default, this will return the first 50 Tasks. Supply a PageSize parameter to fetch more than 50 Tasks. See paging for more information.
Update a Task resource
https://taskrouter.twilio.com/v1/Workspaces/{WorkspaceSid}/Tasks/{Sid}
パラメーター
Parameters in REST API format | |
---|---|
workspace_sid
Path
|
The SID of the Workspace with the Task to update. |
sid
Path
|
The SID of the Task resource to update. |
attributes
オプション
|
The JSON string that describes the custom attributes of the task. |
assignment_status
オプション
|
The new status of the task. Can be: |
reason
オプション
|
The reason that the Task was canceled or completed. This parameter is required only if the Task is canceled or completed. Setting this value queues the task for deletion and logs the reason. |
priority
オプション
|
The Task's new priority value. When supplied, the Task takes on the specified priority unless it matches a Workflow Target with a Priority set. Value can be 0 to 2^31^ (2,147,483,647). |
task_channel
オプション
|
When MultiTasking is enabled, specify the TaskChannel with the task to update. Can be the TaskChannel's SID or its |
if_match
ヘッダー
|
If provided, applies this mutation if (and only if) the ETag header of the Task matches the provided value. This matches the semantics of (and is implemented with) the HTTP If-Match header. |
例 1
When a pending Task's attributes are updated, the Task will be re-driven through the Workflow identified by the WorkflowSid associated with the task. Depending on the Workflow's filters, TaskRouter may move the Task into a different TaskQueue. The age of the Task will remain the same. If the Task is moved to a new TaskQueue, its TaskQueue position relative to other tasks will be determined by its age and priority, as usual.
例 2
The previous version of Etag can be found in the client by accessing the following attribute:
client.httpClient.lastResponse.headers.etag
Delete a Task resource
https://taskrouter.twilio.com/v1/Workspaces/{WorkspaceSid}/Tasks/{Sid}
Deletes the Task identified by TaskSid.
For all pending reservations associated with the deleted Task, these will also be deleted at task deletion time.
パラメーター
Parameters in REST API format | |
---|---|
workspace_sid
Path
|
The SID of the Workspace with the Task to delete. |
sid
Path
|
The SID of the Task resource to delete. |
if_match
ヘッダー
|
If provided, deletes this Task if (and only if) the ETag header of the Task matches the provided value. This matches the semantics of (and is implemented with) the HTTP If-Match header. |
例 1
例 2
ヘルプが必要ですか?
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.