|
| 1 | +.. module:: twilio.rest.resources.task_router |
| 2 | + |
| 3 | +========== |
| 4 | +TaskRouter |
| 5 | +========== |
| 6 | + |
| 7 | +Twilio TaskRouter is a system for distributing tasks such as phone calls, |
| 8 | +leads, support tickets, and other work items to the people and processes that |
| 9 | +can best handle them. |
| 10 | + |
| 11 | +For more information, see the `TaskRouter documentation |
| 12 | +<https://www.twilio.com/docs/taskrouter>_`. |
| 13 | + |
| 14 | + |
| 15 | +Creating a Workspace |
| 16 | +-------------------- |
| 17 | + |
| 18 | +A Workspace is a container for your Tasks, Workers, TaskQueues, Workflows and |
| 19 | +Activities. Each of these items exists within a single Workspace and will not |
| 20 | +be shared across Workspaces. |
| 21 | + |
| 22 | +The following code will create a new :class:`Workspace` resource and print |
| 23 | +its unique ID. |
| 24 | + |
| 25 | +.. code-block:: python |
| 26 | +
|
| 27 | + from twilio.rest import TwilioTaskRouterClient |
| 28 | +
|
| 29 | + # To find these visit https://www.twilio.com/user/account |
| 30 | + ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX" |
| 31 | + AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY" |
| 32 | +
|
| 33 | + client = TwilioTaskRouterClient(ACCOUNT_SID, AUTH_TOKEN) |
| 34 | +
|
| 35 | + workspace = client.workspaces.create( |
| 36 | + friendly_name="Customer Support", |
| 37 | + template="FIFO", # Sets up default activities and a FIFO TaskQueue |
| 38 | + ) |
| 39 | + print workspace.sid |
| 40 | +
|
| 41 | +
|
| 42 | +Workflows |
| 43 | +--------- |
| 44 | + |
| 45 | +Workflows control how tasks will be prioritized and routed into TaskQueues, and |
| 46 | +how Tasks should escalate in priority or move across queues over time. |
| 47 | +Workflows are described in a simple JSON format and can be modified through the |
| 48 | +REST API or through the account portal. |
| 49 | + |
| 50 | +The following code will create a new :class:`Workflow` resource and print its |
| 51 | +unique ID: |
| 52 | + |
| 53 | +.. code-block:: python |
| 54 | +
|
| 55 | + from twilio.rest import TwilioTaskRouterClient |
| 56 | +
|
| 57 | + # To find these visit https://www.twilio.com/user/account |
| 58 | + ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX" |
| 59 | + AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY" |
| 60 | +
|
| 61 | + # See previous examples to create a Workspace |
| 62 | + WORKSPACE_SID = "WSZZZZZZZZZZZZZZ" |
| 63 | +
|
| 64 | + # Some JSON to configure the Workflow. See the documentation at |
| 65 | + # http://www.twilio.com/docs/taskrouter for more details. |
| 66 | + CONFIG = """ |
| 67 | +{ |
| 68 | + "task_routing":{ |
| 69 | + "filters":[ |
| 70 | + { |
| 71 | + "friendly_name":"Gold Tickets", |
| 72 | + "expression":"customer_value == 'Gold' AND type == 'ticket'", |
| 73 | + "targets":[ |
| 74 | + { |
| 75 | + "task_queue_sid":"WQ0123456789abcdef0123456789abcdef", |
| 76 | + "priority":"2" |
| 77 | + } |
| 78 | + ] |
| 79 | + } |
| 80 | + ], |
| 81 | + "default_filter":{ |
| 82 | + "task_queue_sid":"WQabcdef01234567890123456789abcdef" |
| 83 | + } |
| 84 | + } |
| 85 | +} |
| 86 | +""" |
| 87 | +
|
| 88 | + client = TwilioTaskRouterClient(ACCOUNT_SID, AUTH_TOKEN) |
| 89 | +
|
| 90 | + workspace = client.workflows(WORKSPACE_SID).create( |
| 91 | + friendly_name="Incoming Call Flow", |
| 92 | + assignment_callback_url="https://example.com/callback", |
| 93 | + fallback_assignment_callback_url="https://example.com/callback2", |
| 94 | + configuration=CONFIG |
| 95 | + ) |
| 96 | + print workspace.sid |
| 97 | +
|
| 98 | +
|
| 99 | +Activities |
| 100 | +---------- |
| 101 | + |
| 102 | +Activities describe the current status of your Workers, which determines |
| 103 | +whether they are eligible to receive task assignments. Workers are always set |
| 104 | +to a single Activity. |
| 105 | + |
| 106 | +To create a new :class:`Activity`: |
| 107 | + |
| 108 | +.. code-block:: python |
| 109 | +
|
| 110 | + from twilio.rest import TwilioTaskRouterClient |
| 111 | +
|
| 112 | + # To find these visit https://www.twilio.com/user/account |
| 113 | + ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX" |
| 114 | + AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY" |
| 115 | +
|
| 116 | + # See previous examples to create a Workspace |
| 117 | + WORKSPACE_SID = "WSZZZZZZZZZZZZZZ" |
| 118 | +
|
| 119 | + client = TwilioTaskRouterClient(ACCOUNT_SID, AUTH_TOKEN) |
| 120 | + activity = client.activities(WORKSPACE_SID).create( |
| 121 | + friendly_name="Coffee Break", |
| 122 | + available=False, # Whether workers are available to handle tasks during this activity |
| 123 | + ) |
| 124 | +
|
| 125 | +
|
| 126 | +Workers |
| 127 | +------- |
| 128 | + |
| 129 | +Workers represent an entity that is able to perform tasks, such as an agent |
| 130 | +working in a call center, or a salesperson handling leads. |
| 131 | + |
| 132 | +To create a new :class:`Worker`: |
| 133 | + |
| 134 | +.. code-block:: python |
| 135 | +
|
| 136 | + from twilio.rest import TwilioTaskRouterClient |
| 137 | +
|
| 138 | + # To find these visit https://www.twilio.com/user/account |
| 139 | + ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX" |
| 140 | + AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY" |
| 141 | +
|
| 142 | + # See previous examples to create a Workspace |
| 143 | + WORKSPACE_SID = "WSZZZZZZZZZZZZZZ" |
| 144 | +
|
| 145 | + client = TwilioTaskRouterClient(ACCOUNT_SID, AUTH_TOKEN) |
| 146 | + worker = client.workers(WORKSPACE_SID).create( |
| 147 | + friendly_name="Jamie", |
| 148 | + attributes="""{ |
| 149 | + "phone": "+14155551234", |
| 150 | + "languages": ["EN", "ES"] |
| 151 | +} |
| 152 | +""" |
| 153 | + ) |
| 154 | + print worker.sid |
| 155 | +
|
| 156 | +
|
| 157 | +TaskQueues |
| 158 | +---------- |
| 159 | + |
| 160 | +TaskQueues are the resource you use to categorize Tasks and describe which |
| 161 | +Workers are eligible to handle those Tasks. As your Workflows process Tasks, |
| 162 | +those Tasks will pass through one or more TaskQueues until the Task is assigned |
| 163 | +and accepted by an eligible Worker. |
| 164 | + |
| 165 | +To create a new :class:`TaskQueue`: |
| 166 | + |
| 167 | +.. code-block:: python |
| 168 | +
|
| 169 | + from twilio.rest import TwilioTaskRouterClient |
| 170 | +
|
| 171 | + # To find these visit https://www.twilio.com/user/account |
| 172 | + ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX" |
| 173 | + AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY" |
| 174 | +
|
| 175 | + # See previous examples to create a Workspace |
| 176 | + WORKSPACE_SID = "WSZZZZZZZZZZZZZZ" |
| 177 | +
|
| 178 | + client = TwilioTaskRouterClient(ACCOUNT_SID, AUTH_TOKEN) |
| 179 | +
|
| 180 | + queue = client.task_queues(WORKSPACE_SID).create( |
| 181 | + friendly_name="Sales", |
| 182 | + # The Activity to assign workers when a task is reserved for them |
| 183 | + reservation_activity_sid="WA11111111111", |
| 184 | + # The Activity to assign workers when a task is assigned to them |
| 185 | + assignment_activity_sid="WA222222222222", |
| 186 | + ) |
| 187 | + print queue.sid |
| 188 | +
|
| 189 | +
|
| 190 | +Tasks |
| 191 | +----- |
| 192 | + |
| 193 | +A Task instance resource represents a single item of work waiting to be |
| 194 | +processed. |
| 195 | + |
| 196 | +To create a new :class:`Task` via the REST API: |
| 197 | + |
| 198 | +.. code-block:: python |
| 199 | +
|
| 200 | + from twilio.rest import TwilioTaskRouterClient |
| 201 | +
|
| 202 | + # To find these visit https://www.twilio.com/user/account |
| 203 | + ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX" |
| 204 | + AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY" |
| 205 | +
|
| 206 | + # See previous examples to create a Workspace |
| 207 | + WORKSPACE_SID = "WSZZZZZZZZZZZZZZ" |
| 208 | + # Some JSON containing attributes for this task. User-defined. |
| 209 | + TASK_ATTRIBUTES = """{ |
| 210 | + "type": "call", |
| 211 | + "contact": "+15558675309", |
| 212 | + "customer-value": "gold", |
| 213 | + "task-reason": "support", |
| 214 | + "callSid": "CA42ed11..." |
| 215 | +}""" |
| 216 | +
|
| 217 | +
|
| 218 | + client = TwilioTaskRouterClient(ACCOUNT_SID, AUTH_TOKEN) |
| 219 | + task = client.tasks(WORKSPACE_SID).create( |
| 220 | + attributes=TASK_ATTRIBUTES, |
| 221 | + assignment_status='pending', |
| 222 | +
F438
) |
| 223 | + print task.sid |
0 commit comments