twilio-ruby 3.15.1 → 3.15.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +7 -0
- data/LICENSE.md +3 -1
- data/docs/index.rst +15 -0
- data/docs/usage/taskrouter-tokens.rst +98 -0
- data/docs/usage/taskrouter.rst +226 -0
- data/lib/twilio-ruby/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55ea3eb8f942cafe675c70aad8fa1ff5bf3836bf
|
4
|
+
data.tar.gz: b2dfc49ca27752b0e6bc87f8e7c5fc9095251627
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7df8d0e86f338607a6696a0defeda6283a5055870feccf48f15f47754a92e7e32a42961d9c7acdce974595511e1f1831034251f27aadfd0514eb41daea0b6489
|
7
|
+
data.tar.gz: a9e7eeea7956069958f186b2c62811283680db576cb0479b1b835c31826a94804f9aa1ce622d42661ef73a30f9c980b3e390dfbbe98f88f597b2c215c0c52fe1
|
data/CHANGES.md
CHANGED
data/LICENSE.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
Copyright (c) 2010-2014 Andrew Benton.
|
2
2
|
|
3
|
+
The MIT License (MIT)
|
4
|
+
|
3
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
6
|
of this software and associated documentation files (the "Software"), to deal
|
5
7
|
in the Software without restriction, including without limitation the rights
|
@@ -16,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
THE SOFTWARE.
|
21
|
+
THE SOFTWARE.
|
data/docs/index.rst
CHANGED
@@ -55,6 +55,21 @@ Query the Twilio REST API to create phone calls, send SMS/MMS messages and more!
|
|
55
55
|
usage/queues
|
56
56
|
usage/sip
|
57
57
|
|
58
|
+
|
59
|
+
TaskRouter
|
60
|
+
---------
|
61
|
+
|
62
|
+
Query the Twilio TaskRouter API to set up workspaces and task routing, and
|
63
|
+
create capability tokens to authorize your client-side code to safely update
|
64
|
+
state.
|
65
|
+
|
66
|
+
.. toctree::
|
67
|
+
:maxdepth: 1
|
68
|
+
|
69
|
+
usage/taskrouter
|
70
|
+
usage/taskrouter-tokens
|
71
|
+
|
72
|
+
|
58
73
|
TwiML
|
59
74
|
---------
|
60
75
|
|
@@ -0,0 +1,98 @@
|
|
1
|
+
.. module:: twilio.task_router
|
2
|
+
|
3
|
+
============================
|
4
|
+
TaskRouter Capability Tokens
|
5
|
+
============================
|
6
|
+
|
7
|
+
|
8
|
+
TaskRouter's Worker.js library lets you add `TaskRouter
|
9
|
+
<https://www.twilio.com/docs/taskrouter>`_ Worker Activity controls
|
10
|
+
and event notifications to your web applications. Worker.js uses a Websocket
|
11
|
+
connection to TaskRouter to receive realtime notifications of Worker
|
12
|
+
Reservations and Task details, and provides a simple API for modifying a
|
13
|
+
Worker's current Activity.
|
14
|
+
|
15
|
+
TaskRouter uses Twilio capability tokens to delegate scoped access to
|
16
|
+
TaskRouter resources to your JavaScript application. Twilio capability tokens
|
17
|
+
conform to the JSON Web Token (commonly referred to as a JWT and pronounced
|
18
|
+
"jot") standard, which allow for limited-time use of credentials by a third
|
19
|
+
party. Your web server needs to generate a Twilio capability token and provide
|
20
|
+
it to your JavaScript application in order to register a TaskRouter worker.
|
21
|
+
|
22
|
+
:class:`Capability` is responsible for the creation of these
|
23
|
+
capability tokens. You'll need your Twilio AccountSid and AuthToken,
|
24
|
+
the Sid of the Workspace you want to authorize access to, and the Sid
|
25
|
+
of the Worker you're granting authorization for.
|
26
|
+
|
27
|
+
.. code-block:: ruby
|
28
|
+
|
29
|
+
require 'twilio-ruby'
|
30
|
+
|
31
|
+
# Get these values from https://twilio.com/user/account
|
32
|
+
account_sid = "AC123"
|
33
|
+
auth_token = "secret"
|
34
|
+
|
35
|
+
# Create a Workspace and Worker in the TaskRouter account portal
|
36
|
+
# or through the TaskRouter API
|
37
|
+
worker_sid = "WK789"
|
38
|
+
worker_sid = "WK789"
|
39
|
+
|
40
|
+
@capability = Twilio::TaskRouter::Capability.new account_sid, auth_token, workspace_sid, worker_sid
|
41
|
+
|
42
|
+
|
43
|
+
By default, the Capability object will allow the Worker.js process to
|
44
|
+
read from and write to the websockets used to communicate events, and also
|
45
|
+
to fetch the list of available activities in the workspace.
|
46
|
+
|
47
|
+
There are three additional permissions you can grant using the Capability
|
48
|
+
token, and in most cases you'll want to allow all of them for your application:
|
49
|
+
|
50
|
+
|
51
|
+
Attribute Fetch
|
52
|
+
===============
|
53
|
+
|
54
|
+
This authorizes requests to retrieve the registered Worker's attributes from
|
55
|
+
the TaskRouter API.
|
56
|
+
|
57
|
+
.. code-block:: ruby
|
58
|
+
|
59
|
+
@capability.allow_worker_fetch_attributes
|
60
|
+
|
61
|
+
|
62
|
+
Worker Activity Update
|
63
|
+
======================
|
64
|
+
|
65
|
+
This authorizes updates to the registered Worker's current Activity.
|
66
|
+
|
67
|
+
.. code-block:: ruby
|
68
|
+
|
69
|
+
@capability.allow_worker_activity_updates
|
70
|
+
|
71
|
+
|
72
|
+
Task Reservation Update
|
73
|
+
=======================
|
74
|
+
|
75
|
+
This authorizes updates to a Task's reservation status.
|
76
|
+
|
77
|
+
.. code-block:: ruby
|
78
|
+
|
79
|
+
@capability.allow_task_reservation_updates
|
80
|
+
|
81
|
+
|
82
|
+
Generate a Token
|
83
|
+
================
|
84
|
+
|
85
|
+
.. code-block:: ruby
|
86
|
+
|
87
|
+
token = @capability.generate_token
|
88
|
+
|
89
|
+
By default, this token will expire in one hour. If you'd like to change the
|
90
|
+
token expiration, :meth:`generate_token` takes an optional :attr:`ttl`
|
91
|
+
argument.
|
92
|
+
|
93
|
+
.. code-block:: ruby
|
94
|
+
|
95
|
+
token = @capability.generate_token(600)
|
96
|
+
|
97
|
+
This token will now expire in 10 minutes. If you haven't guessed already,
|
98
|
+
:attr:`ttl` is expressed in seconds.
|
@@ -0,0 +1,226 @@
|
|
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:: ruby
|
26
|
+
|
27
|
+
require 'twilio-ruby'
|
28
|
+
|
29
|
+
# To find these visit https://www.twilio.com/user/account
|
30
|
+
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
|
31
|
+
AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
|
32
|
+
# You can create a workspace through the portal, or put a fake value
|
33
|
+
# here to create your first workspace with the Ruby library
|
34
|
+
WORKSPACE_SID = "WSZZZZZZZZZ"
|
35
|
+
|
36
|
+
@client = Twilio::REST::TaskRouterClient.new ACCOUNT_SID, AUTH_TOKEN, WORKSPACE_SID
|
37
|
+
|
38
|
+
@workspace = @client.workspaces.create(
|
39
|
+
friendly_name: "Customer Support",
|
40
|
+
template: "FIFO", # Sets up default activities and a FIFO TaskQueue
|
41
|
+
)
|
42
|
+
puts @workspace.sid
|
43
|
+
|
44
|
+
|
45
|
+
Workflows
|
46
|
+
---------
|
47
|
+
|
48
|
+
Workflows control how tasks will be prioritized and routed into TaskQueues, and
|
49
|
+
how Tasks should escalate in priority or move across queues over time.
|
50
|
+
Workflows are described in a simple JSON format and can be modified through the
|
51
|
+
REST API or through the account portal.
|
52
|
+
|
53
|
+
The following code will create a new :class:`Workflow` resource and print its
|
54
|
+
unique ID:
|
55
|
+
|
56
|
+
.. code-block:: ruby
|
57
|
+
|
58
|
+
require 'twilio-ruby'
|
59
|
+
|
60
|
+
# To find these visit https://www.twilio.com/user/account
|
61
|
+
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
|
62
|
+
AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
|
63
|
+
|
64
|
+
# See previous examples to create a Workspace
|
65
|
+
WORKSPACE_SID = "WSZZZZZZZZZZZZZZ"
|
66
|
+
|
67
|
+
# Some JSON to configure the Workflow. See the documentation at
|
68
|
+
# http://www.twilio.com/docs/taskrouter for more details.
|
69
|
+
CONFIG = <<-EOS
|
70
|
+
{
|
71
|
+
"task_routing":{
|
72
|
+
"filters":[
|
73
|
+
{
|
74
|
+
"friendly_name":"Gold Tickets",
|
75
|
+
"expression":"customer_value == 'Gold' AND type == 'ticket'",
|
76
|
+
"targets":[
|
77
|
+
{
|
78
|
+
"task_queue_sid":"WQ0123456789abcdef0123456789abcdef",
|
79
|
+
"priority":"2"
|
80
|
+
}
|
81
|
+
]
|
82
|
+
}
|
83
|
+
],
|
84
|
+
"default_filter":{
|
85
|
+
"task_queue_sid":"WQabcdef01234567890123456789abcdef"
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
EOS
|
90
|
+
|
91
|
+
@client = Twilio::REST::TaskRouterClient.new ACCOUNT_SID, AUTH_TOKEN, WORKSPACE_SID
|
92
|
+
|
93
|
+
@workspace = @client.workflows.create(
|
94
|
+
friendly_name: "Incoming Call Flow",
|
95
|
+
assignment_callback_url: "https://example.com/callback",
|
96
|
+
fallback_assignment_callback_url: "https://example.com/callback2",
|
97
|
+
configuration: CONFIG
|
98
|
+
)
|
99
|
+
puts @workspace.sid
|
100
|
+
|
101
|
+
|
102
|
+
Activities
|
103
|
+
----------
|
104
|
+
|
105
|
+
Activities describe the current status of your Workers, which determines
|
106
|
+
whether they are eligible to receive task assignments. Workers are always set
|
107
|
+
to a single Activity.
|
108
|
+
|
109
|
+
To create a new :class:`Activity`:
|
110
|
+
|
111
|
+
.. code-block:: ruby
|
112
|
+
|
113
|
+
require 'twilio-ruby'
|
114
|
+
|
115
|
+
# To find these visit https://www.twilio.com/user/account
|
116
|
+
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
|
117
|
+
AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
|
118
|
+
|
119
|
+
# See previous examples to create a Workspace
|
120
|
+
WORKSPACE_SID = "WSZZZZZZZZZZZZZZ"
|
121
|
+
|
122
|
+
@client = Twilio::REST::TaskRouterClient.new ACCOUNT_SID, AUTH_TOKEN, WORKSPACE_SID
|
123
|
+
|
124
|
+
@activity = @client.activities.create(
|
125
|
+
friendly_name: "Coffee Break",
|
126
|
+
available: false # Whether workers are available to handle tasks during this activity
|
127
|
+
)
|
128
|
+
puts @activity.sid
|
129
|
+
|
130
|
+
|
131
|
+
Workers
|
132
|
+
-------
|
133
|
+
|
134
|
+
Workers represent an entity that is able to perform tasks, such as an agent
|
135
|
+
working in a call center, or a salesperson handling leads.
|
136
|
+
|
137
|
+
To create a new :class:`Worker`:
|
138
|
+
|
139
|
+
.. code-block:: ruby
|
140
|
+
|
141
|
+
require 'twilio-ruby'
|
142
|
+
|
143
|
+
# To find these visit https://www.twilio.com/user/account
|
144
|
+
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
|
145
|
+
AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
|
146
|
+
|
147
|
+
# See previous examples to create a Workspace
|
148
|
+
WORKSPACE_SID = "WSZZZZZZZZZZZZZZ"
|
149
|
+
|
150
|
+
@client = Twilio::REST::TaskRouterClient.new ACCOUNT_SID, AUTH_TOKEN, WORKSPACE_SID
|
151
|
+
|
152
|
+
@worker = @client.workers.create(
|
153
|
+
friendly_name:"Jamie",
|
154
|
+
attributes:'{"phone": "+14155551234", "languages": ["EN", "ES"]}'
|
155
|
+
)
|
156
|
+
puts @worker.sid
|
157
|
+
|
158
|
+
|
159
|
+
TaskQueues
|
160
|
+
----------
|
161
|
+
|
162
|
+
TaskQueues are the resource you use to categorize Tasks and describe which
|
163
|
+
Workers are eligible to handle those Tasks. As your Workflows process Tasks,
|
164
|
+
those Tasks will pass through one or more TaskQueues until the Task is assigned
|
165
|
+
and accepted by an eligible Worker.
|
166
|
+
|
167
|
+
To create a new :class:`TaskQueue`:
|
168
|
+
|
169
|
+
.. code-block:: ruby
|
170
|
+
|
171
|
+
require 'twilio-ruby'
|
172
|
+
|
173
|
+
# To find these visit https://www.twilio.com/user/account
|
174
|
+
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
|
175
|
+
AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
|
176
|
+
|
177
|
+
# See previous examples to create a Workspace
|
178
|
+
WORKSPACE_SID = "WSZZZZZZZZZZZZZZ"
|
179
|
+
|
180
|
+
@client = Twilio::REST::TaskRouterClient.new ACCOUNT_SID, AUTH_TOKEN, WORKSPACE_SID
|
181
|
+
|
182
|
+
@queue = @client.task_queues.create(
|
183
|
+
friendly_name: "Sales",
|
184
|
+
# The Activity to assign workers when a task is reserved for them
|
185
|
+
reservation_activity_sid: "WA11111111111",
|
186
|
+
# The Activity to assign workers when a task is assigned to them
|
187
|
+
assignment_activity_sid: "WA222222222222",
|
188
|
+
)
|
189
|
+
puts @queue.sid
|
190
|
+
|
191
|
+
|
192
|
+
Tasks
|
193
|
+
-----
|
194
|
+
|
195
|
+
A Task instance resource represents a single item of work waiting to be
|
196
|
+
processed.
|
197
|
+
|
198
|
+
To create a new :class:`Task` via the REST API:
|
199
|
+
|
200
|
+
.. code-block:: ruby
|
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
|
+
|
209
|
+
@client = Twilio::REST::TaskRouterClient.new ACCOUNT_SID, AUTH_TOKEN, WORKSPACE_SID
|
210
|
+
|
211
|
+
# Some JSON containing attributes for this task. User-defined.
|
212
|
+
TASK_ATTRIBUTES = <<-EOS
|
213
|
+
{
|
214
|
+
"type": "call",
|
215
|
+
"contact": "+15558675309",
|
216
|
+
"customer-value": "gold",
|
217
|
+
"task-reason": "support",
|
218
|
+
"callSid": "CA42ed11..."
|
219
|
+
}
|
220
|
+
EOS
|
221
|
+
|
222
|
+
@task = @client.create(
|
223
|
+
attributes: TASK_ATTRIBUTES,
|
224
|
+
assignment_status: 'pending',
|
225
|
+
)
|
226
|
+
puts @task.sid
|
data/lib/twilio-ruby/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twilio-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.15.
|
4
|
+
version: 3.15.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Benton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -119,6 +119,8 @@ files:
|
|
119
119
|
- docs/usage/queues.rst
|
120
120
|
- docs/usage/recordings.rst
|
121
121
|
- docs/usage/sip.rst
|
122
|
+
- docs/usage/taskrouter-tokens.rst
|
123
|
+
- docs/usage/taskrouter.rst
|
122
124
|
- docs/usage/token-generation.rst
|
123
125
|
- docs/usage/transcriptions.rst
|
124
126
|
- docs/usage/twiml.rst
|