twilio-ruby 4.4.0 → 4.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +85 -0
- data/Makefile +3 -0
- data/README.md +1 -1
- data/issue_template.md +25 -0
- data/lib/twilio-ruby/rest/accounts.rb +1 -1
- data/lib/twilio-ruby/rest/base_client.rb +3 -2
- data/lib/twilio-ruby/rest/ip-messaging/channels.rb +15 -0
- data/lib/twilio-ruby/rest/ip-messaging/credentials.rb +19 -0
- data/lib/twilio-ruby/rest/ip-messaging/members.rb +8 -0
- data/lib/twilio-ruby/rest/ip-messaging/messages.rb +8 -0
- data/lib/twilio-ruby/rest/ip-messaging/roles.rb +8 -0
- data/lib/twilio-ruby/rest/ip-messaging/services.rb +17 -0
- data/lib/twilio-ruby/rest/ip-messaging/users.rb +8 -0
- data/lib/twilio-ruby/rest/ip_messaging_client.rb +100 -0
- data/lib/twilio-ruby/rest/keys.rb +6 -0
- data/lib/twilio-ruby/rest/pricing/messaging.rb +15 -0
- data/lib/twilio-ruby/rest/pricing/voice.rb +0 -3
- data/lib/twilio-ruby/rest/pricing_client.rb +2 -4
- data/lib/twilio-ruby/rest/trunking/credential_lists.rb +8 -0
- data/lib/twilio-ruby/rest/trunking/ip_access_control_lists.rb +8 -0
- data/lib/twilio-ruby/rest/trunking/origination_urls.rb +8 -0
- data/lib/twilio-ruby/rest/trunking/phone_numbers.rb +8 -0
- data/lib/twilio-ruby/rest/trunking/trunks.rb +19 -0
- data/lib/twilio-ruby/rest/trunking_client.rb +106 -0
- data/lib/twilio-ruby/task_router/capability.rb +11 -5
- data/lib/twilio-ruby/task_router/workflow_builder.rb +7 -1
- data/lib/twilio-ruby/util/access_token.rb +158 -0
- data/lib/twilio-ruby/version.rb +1 -1
- data/lib/twilio-ruby.rb +22 -0
- data/spec/rest/ip-messaging/channel_spec.rb +21 -0
- data/spec/rest/ip-messaging/service_spec.rb +30 -0
- data/spec/rest/ip_messaging_client_spec.rb +21 -0
- data/spec/rest/key_spec.rb +11 -0
- data/spec/rest/pricing_client_spec.rb +15 -0
- data/spec/rest/trunking/trunk_spec.rb +36 -0
- data/spec/task_router/workflow_builder_spec.rb +501 -0
- data/spec/task_router_deprecated_spec.rb +15 -6
- data/spec/task_router_worker_spec.rb +24 -7
- data/spec/util/access_token_spec.rb +161 -0
- metadata +35 -3
@@ -0,0 +1,501 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Twilio::TaskRouter::WorkflowConfiguration do
|
4
|
+
describe 'with a workflow builder' do
|
5
|
+
|
6
|
+
it 'should construct a default rule target' do
|
7
|
+
everyoneQueue = 'WQf6724bd5005b30eeb6ea990c3e59e536'
|
8
|
+
defaultTarget = Twilio::TaskRouter::WorkflowRuleTarget.new everyoneQueue
|
9
|
+
expect(defaultTarget.queue).to eq(everyoneQueue)
|
10
|
+
expect(defaultTarget.priority).to be_nil
|
11
|
+
expect(defaultTarget.timeout).to be_nil
|
12
|
+
expect(defaultTarget.expression).to be_nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should construct a simple rule target' do
|
16
|
+
everyoneQueue = 'WQf6724bd5005b30eeb6ea990c3e59e536'
|
17
|
+
priority = 10
|
18
|
+
timeout = 60
|
19
|
+
defaultTarget = Twilio::TaskRouter::WorkflowRuleTarget.new everyoneQueue, priority, timeout
|
20
|
+
expect(defaultTarget.queue).to eq(everyoneQueue)
|
21
|
+
expect(defaultTarget.priority).to eq(priority)
|
22
|
+
expect(defaultTarget.timeout).to eq(timeout)
|
23
|
+
expect(defaultTarget.expression).to be_nil
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should construct a worker filter rule target' do
|
27
|
+
everyoneQueue = 'WQf6724bd5005b30eeb6ea990c3e59e536'
|
28
|
+
priority = 10
|
29
|
+
timeout = 60
|
30
|
+
filterWorkerExpression = "task.language IN worker.languages";
|
31
|
+
defaultTarget = Twilio::TaskRouter::WorkflowRuleTarget.new everyoneQueue, priority, timeout, filterWorkerExpression
|
32
|
+
expect(defaultTarget.queue).to eq(everyoneQueue)
|
33
|
+
expect(defaultTarget.priority).to eq(priority)
|
34
|
+
expect(defaultTarget.timeout).to eq(timeout)
|
35
|
+
expect(defaultTarget.expression).to eq(filterWorkerExpression)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should construct simple rule' do
|
39
|
+
salesQueue = "WQf6724bd5005b30eeb6ea990c3e59e536"
|
40
|
+
salesTarget = Twilio::TaskRouter::WorkflowRuleTarget.new salesQueue
|
41
|
+
expression = "type=='sales'"
|
42
|
+
friendlyName = "Sales"
|
43
|
+
salesTargets = [salesTarget]
|
44
|
+
salesRule = Twilio::TaskRouter::WorkflowRule.new expression, salesTargets, friendlyName
|
45
|
+
expect(salesRule.expression).to eq(expression)
|
46
|
+
expect(salesRule.friendly_name).to eq(friendlyName)
|
47
|
+
expect(salesRule.targets[0]).to eq(salesTarget)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should construct a full workflow' do
|
51
|
+
salesQueue = "WQf6724bd5005b30eeb6ea990c3e59e536"
|
52
|
+
marketingQueue = "WQ8c62f84b61ccfa6a333757cd508f0aae"
|
53
|
+
supportQueue = "WQ5940dc0da87eaf6e3321d62041d4403b"
|
54
|
+
everyoneQueue = "WQ6d29383312b24bd898a8df32779fc043"
|
55
|
+
|
56
|
+
defaultTarget = Twilio::TaskRouter::WorkflowRuleTarget.new everyoneQueue
|
57
|
+
|
58
|
+
salesTarget = Twilio::TaskRouter::WorkflowRuleTarget.new salesQueue
|
59
|
+
salesRule = Twilio::TaskRouter::WorkflowRule.new "type=='sales'", [salesTarget], 'Sales'
|
60
|
+
|
61
|
+
marketingTarget = Twilio::TaskRouter::WorkflowRuleTarget.new marketingQueue
|
62
|
+
marketingRule = Twilio::TaskRouter::WorkflowRule.new "type=='marketing'", [marketingTarget], 'Marketing'
|
63
|
+
|
64
|
+
supportTarget = Twilio::TaskRouter::WorkflowRuleTarget.new supportQueue
|
65
|
+
supportRule = Twilio::TaskRouter::WorkflowRule.new "type=='support'", [supportTarget], 'Support'
|
66
|
+
|
67
|
+
rules = [salesRule, marketingRule, supportRule]
|
68
|
+
|
69
|
+
config = Twilio::TaskRouter::WorkflowConfiguration.new rules, defaultTarget
|
70
|
+
json = config.to_json
|
71
|
+
|
72
|
+
expected = "{
|
73
|
+
\"task_routing\":{
|
74
|
+
\"filters\":[
|
75
|
+
{
|
76
|
+
\"expression\":\"type=='sales'\",
|
77
|
+
\"targets\":[
|
78
|
+
{
|
79
|
+
\"queue\":\"WQf6724bd5005b30eeb6ea990c3e59e536\"
|
80
|
+
}
|
81
|
+
],
|
82
|
+
\"friendly_name\":\"Sales\"
|
83
|
+
},
|
84
|
+
{
|
85
|
+
\"expression\":\"type=='marketing'\",
|
86
|
+
\"targets\":[
|
87
|
+
{
|
88
|
+
\"queue\":\"WQ8c62f84b61ccfa6a333757cd508f0aae\"
|
89
|
+
}
|
90
|
+
],
|
91
|
+
\"friendly_name\":\"Marketing\"
|
92
|
+
},
|
93
|
+
{
|
94
|
+
\"expression\":\"type=='support'\",
|
95
|
+
\"targets\":[
|
96
|
+
{
|
97
|
+
\"queue\":\"WQ5940dc0da87eaf6e3321d62041d4403b\"
|
98
|
+
}
|
99
|
+
],
|
100
|
+
\"friendly_name\":\"Support\"
|
101
|
+
}
|
102
|
+
],
|
103
|
+
\"default_filter\":{
|
104
|
+
\"queue\":\"WQ6d29383312b24bd898a8df32779fc043\"
|
105
|
+
}
|
106
|
+
}
|
107
|
+
}"
|
108
|
+
|
109
|
+
expected = JSON.parse(expected).to_json
|
110
|
+
|
111
|
+
expect(expected).to eq(json)
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should construct a full workflow with timeouts' do
|
115
|
+
salesQueue = "WQf6724bd5005b30eeb6ea990c3e59e536"
|
116
|
+
marketingQueue = "WQ8c62f84b61ccfa6a333757cd508f0aae"
|
117
|
+
supportQueue = "WQ5940dc0da87eaf6e3321d62041d4403b"
|
118
|
+
everyoneQueue = "WQ6d29383312b24bd898a8df32779fc043"
|
119
|
+
|
120
|
+
defaultTarget = Twilio::TaskRouter::WorkflowRuleTarget.new everyoneQueue
|
121
|
+
|
122
|
+
salesTarget1 = Twilio::TaskRouter::WorkflowRuleTarget.new salesQueue, 5, 30
|
123
|
+
salesTarget2 = Twilio::TaskRouter::WorkflowRuleTarget.new salesQueue, 10
|
124
|
+
salesRule = Twilio::TaskRouter::WorkflowRule.new "type=='sales'", [salesTarget1, salesTarget2], 'Sales'
|
125
|
+
|
126
|
+
marketingTarget1 = Twilio::TaskRouter::WorkflowRuleTarget.new marketingQueue, 1, 120
|
127
|
+
marketingTarget2 = Twilio::TaskRouter::WorkflowRuleTarget.new marketingQueue, 3
|
128
|
+
marketingRule = Twilio::TaskRouter::WorkflowRule.new "type=='marketing'", [marketingTarget1, marketingTarget2], 'Marketing'
|
129
|
+
|
130
|
+
supportTarget1 = Twilio::TaskRouter::WorkflowRuleTarget.new supportQueue, 10, 30
|
131
|
+
supportTarget2 = Twilio::TaskRouter::WorkflowRuleTarget.new supportQueue, 15
|
132
|
+
supportRule = Twilio::TaskRouter::WorkflowRule.new "type=='support'", [supportTarget1, supportTarget2], 'Support'
|
133
|
+
|
134
|
+
rules = [salesRule, marketingRule, supportRule]
|
135
|
+
|
136
|
+
config = Twilio::TaskRouter::WorkflowConfiguration.new rules, defaultTarget
|
137
|
+
json = config.to_json
|
138
|
+
|
139
|
+
expected = "{
|
140
|
+
\"task_routing\":{
|
141
|
+
\"filters\":[
|
142
|
+
{
|
143
|
+
\"expression\":\"type=='sales'\",
|
144
|
+
\"targets\":[
|
145
|
+
{
|
146
|
+
\"queue\":\"WQf6724bd5005b30eeb6ea990c3e59e536\",
|
147
|
+
\"priority\": 5,
|
148
|
+
\"timeout\": 30
|
149
|
+
},
|
150
|
+
{
|
151
|
+
\"queue\":\"WQf6724bd5005b30eeb6ea990c3e59e536\",
|
152
|
+
\"priority\": 10
|
153
|
+
}
|
154
|
+
],
|
155
|
+
\"friendly_name\":\"Sales\"
|
156
|
+
},
|
157
|
+
{
|
158
|
+
\"expression\":\"type=='marketing'\",
|
159
|
+
\"targets\":[
|
160
|
+
{
|
161
|
+
\"queue\":\"WQ8c62f84b61ccfa6a333757cd508f0aae\",
|
162
|
+
\"priority\": 1,
|
163
|
+
\"timeout\": 120
|
164
|
+
},
|
165
|
+
{
|
166
|
+
\"queue\":\"WQ8c62f84b61ccfa6a333757cd508f0aae\",
|
167
|
+
\"priority\": 3
|
168
|
+
}
|
169
|
+
],
|
170
|
+
\"friendly_name\":\"Marketing\"
|
171
|
+
},
|
172
|
+
{
|
173
|
+
\"expression\":\"type=='support'\",
|
174
|
+
\"targets\":[
|
175
|
+
{
|
176
|
+
\"queue\":\"WQ5940dc0da87eaf6e3321d62041d4403b\",
|
177
|
+
\"priority\": 10,
|
178
|
+
\"timeout\": 30
|
179
|
+
},
|
180
|
+
{
|
181
|
+
\"queue\":\"WQ5940dc0da87eaf6e3321d62041d4403b\",
|
182
|
+
\"priority\": 15
|
183
|
+
}
|
184
|
+
],
|
185
|
+
\"friendly_name\":\"Support\"
|
186
|
+
}
|
187
|
+
],
|
188
|
+
\"default_filter\":{
|
189
|
+
\"queue\":\"WQ6d29383312b24bd898a8df32779fc043\"
|
190
|
+
}
|
191
|
+
}
|
192
|
+
}";
|
193
|
+
|
194
|
+
expected = JSON.parse(expected).to_json
|
195
|
+
|
196
|
+
expect(expected).to eq(json)
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'should be able to parse the workflow' do
|
200
|
+
json = "{
|
201
|
+
\"task_routing\":{
|
202
|
+
\"filters\":[
|
203
|
+
{
|
204
|
+
\"expression\":\"type=='sales'\",
|
205
|
+
\"targets\":[
|
206
|
+
{
|
207
|
+
\"queue\":\"WQf6724bd5005b30eeb6ea990c3e59e536\",
|
208
|
+
\"priority\": 5,
|
209
|
+
\"timeout\": 30
|
210
|
+
},
|
211
|
+
{
|
212
|
+
\"queue\":\"WQf6724bd5005b30eeb6ea990c3e59e536\",
|
213
|
+
\"priority\": 10
|
214
|
+
}
|
215
|
+
],
|
216
|
+
\"friendly_name\":\"Sales\"
|
217
|
+
},
|
218
|
+
{
|
219
|
+
\"expression\":\"type=='marketing'\",
|
220
|
+
\"targets\":[
|
221
|
+
{
|
222
|
+
\"queue\":\"WQ8c62f84b61ccfa6a333757cd508f0aae\",
|
223
|
+
\"priority\": 1,
|
224
|
+
\"timeout\": 120
|
225
|
+
},
|
226
|
+
{
|
227
|
+
\"queue\":\"WQ8c62f84b61ccfa6a333757cd508f0aae\",
|
228
|
+
\"priority\": 3
|
229
|
+
}
|
230
|
+
],
|
231
|
+
\"friendly_name\":\"Marketing\"
|
232
|
+
},
|
233
|
+
{
|
234
|
+
\"expression\":\"type=='support'\",
|
235
|
+
\"targets\":[
|
236
|
+
{
|
237
|
+
\"queue\":\"WQ5940dc0da87eaf6e3321d62041d4403b\",
|
238
|
+
\"priority\": 10,
|
239
|
+
\"timeout\": 30
|
240
|
+
},
|
241
|
+
{
|
242
|
+
\"queue\":\"WQ5940dc0da87eaf6e3321d62041d4403b\",
|
243
|
+
\"priority\": 15
|
244
|
+
}
|
245
|
+
],
|
246
|
+
\"friendly_name\":\"Support\"
|
247
|
+
}
|
248
|
+
],
|
249
|
+
\"default_filter\":{
|
250
|
+
\"queue\":\"WQ6d29383312b24bd898a8df32779fc043\"
|
251
|
+
}
|
252
|
+
}
|
253
|
+
}"
|
254
|
+
|
255
|
+
config = Twilio::TaskRouter::WorkflowConfiguration.parse_json(json)
|
256
|
+
|
257
|
+
expect(config.rules.length).to eq(3)
|
258
|
+
expect(config.default_target).to_not be_nil
|
259
|
+
# sales assertions
|
260
|
+
expect(config.rules[0].expression).to eq("type=='sales'")
|
261
|
+
expect(config.rules[0].friendly_name).to eq("Sales")
|
262
|
+
expect(config.rules[0].targets.length).to eq(2)
|
263
|
+
expect(config.rules[0].targets[0].queue).to eq("WQf6724bd5005b30eeb6ea990c3e59e536")
|
264
|
+
expect(config.rules[0].targets[0].priority).to eq(5)
|
265
|
+
expect(config.rules[0].targets[0].timeout).to eq(30)
|
266
|
+
expect(config.rules[0].targets[1].queue).to eq("WQf6724bd5005b30eeb6ea990c3e59e536")
|
267
|
+
expect(config.rules[0].targets[1].priority).to eq(10)
|
268
|
+
# marketing assertions
|
269
|
+
expect(config.rules[1].expression).to eq("type=='marketing'")
|
270
|
+
expect(config.rules[1].friendly_name).to eq("Marketing")
|
271
|
+
expect(config.rules[1].targets.length).to eq(2)
|
272
|
+
expect(config.rules[1].targets[0].queue).to eq("WQ8c62f84b61ccfa6a333757cd508f0aae")
|
273
|
+
expect(config.rules[1].targets[0].priority).to eq(1)
|
274
|
+
expect(config.rules[1].targets[0].timeout).to eq(120)
|
275
|
+
expect(config.rules[1].targets[1].queue).to eq("WQ8c62f84b61ccfa6a333757cd508f0aae")
|
276
|
+
expect(config.rules[1].targets[1].priority).to eq(3)
|
277
|
+
# support assertions
|
278
|
+
expect(config.rules[2].expression).to eq("type=='support'")
|
279
|
+
expect(config.rules[2].friendly_name).to eq("Support")
|
280
|
+
expect(config.rules[2].targets.length).to eq(2)
|
281
|
+
expect(config.rules[2].targets[0].queue).to eq("WQ5940dc0da87eaf6e3321d62041d4403b")
|
282
|
+
expect(config.rules[2].targets[0].priority).to eq(10)
|
283
|
+
expect(config.rules[2].targets[0].timeout).to eq(30)
|
284
|
+
expect(config.rules[2].targets[1].queue).to eq("WQ5940dc0da87eaf6e3321d62041d4403b")
|
285
|
+
expect(config.rules[2].targets[1].priority).to eq(15)
|
286
|
+
# default filter
|
287
|
+
expect(config.default_target.queue).to eq("WQ6d29383312b24bd898a8df32779fc043")
|
288
|
+
end
|
289
|
+
|
290
|
+
it 'should be able to parse the workflow with filter friendly name' do
|
291
|
+
json = "{
|
292
|
+
\"task_routing\":{
|
293
|
+
\"filters\":[
|
294
|
+
{
|
295
|
+
\"expression\":\"type=='sales'\",
|
296
|
+
\"targets\":[
|
297
|
+
{
|
298
|
+
\"queue\":\"WQf6724bd5005b30eeb6ea990c3e59e536\",
|
299
|
+
\"priority\": 5,
|
300
|
+
\"timeout\": 30
|
301
|
+
},
|
302
|
+
{
|
303
|
+
\"queue\":\"WQf6724bd5005b30eeb6ea990c3e59e536\",
|
304
|
+
\"priority\": 10
|
305
|
+
}
|
306
|
+
],
|
307
|
+
\"filter_friendly_name\":\"Sales\"
|
308
|
+
},
|
309
|
+
{
|
310
|
+
\"expression\":\"type=='marketing'\",
|
311
|
+
\"targets\":[
|
312
|
+
{
|
313
|
+
\"queue\":\"WQ8c62f84b61ccfa6a333757cd508f0aae\",
|
314
|
+
\"priority\": 1,
|
315
|
+
\"timeout\": 120
|
316
|
+
},
|
317
|
+
{
|
318
|
+
\"queue\":\"WQ8c62f84b61ccfa6a333757cd508f0aae\",
|
319
|
+
\"priority\": 3
|
320
|
+
}
|
321
|
+
],
|
322
|
+
\"filter_friendly_name\":\"Marketing\"
|
323
|
+
},
|
324
|
+
{
|
325
|
+
\"expression\":\"type=='support'\",
|
326
|
+
\"targets\":[
|
327
|
+
{
|
328
|
+
\"queue\":\"WQ5940dc0da87eaf6e3321d62041d4403b\",
|
329
|
+
\"priority\": 10,
|
330
|
+
\"timeout\": 30
|
331
|
+
},
|
332
|
+
{
|
333
|
+
\"queue\":\"WQ5940dc0da87eaf6e3321d62041d4403b\",
|
334
|
+
\"priority\": 15
|
335
|
+
}
|
336
|
+
],
|
337
|
+
\"filter_friendly_name\":\"Support\"
|
338
|
+
}
|
339
|
+
],
|
340
|
+
\"default_filter\":{
|
341
|
+
\"queue\":\"WQ6d29383312b24bd898a8df32779fc043\"
|
342
|
+
}
|
343
|
+
}
|
344
|
+
}"
|
345
|
+
|
346
|
+
config = Twilio::TaskRouter::WorkflowConfiguration.parse_json(json)
|
347
|
+
|
348
|
+
expect(config.rules.length).to eq(3)
|
349
|
+
expect(config.default_target).to_not be_nil
|
350
|
+
# sales assertions
|
351
|
+
expect(config.rules[0].expression).to eq("type=='sales'")
|
352
|
+
expect(config.rules[0].friendly_name).to eq("Sales")
|
353
|
+
expect(config.rules[0].targets.length).to eq(2)
|
354
|
+
expect(config.rules[0].targets[0].queue).to eq("WQf6724bd5005b30eeb6ea990c3e59e536")
|
355
|
+
expect(config.rules[0].targets[0].priority).to eq(5)
|
356
|
+
expect(config.rules[0].targets[0].timeout).to eq(30)
|
357
|
+
expect(config.rules[0].targets[1].queue).to eq("WQf6724bd5005b30eeb6ea990c3e59e536")
|
358
|
+
expect(config.rules[0].targets[1].priority).to eq(10)
|
359
|
+
# marketing assertions
|
360
|
+
expect(config.rules[1].expression).to eq("type=='marketing'")
|
361
|
+
expect(config.rules[1].friendly_name).to eq("Marketing")
|
362
|
+
expect(config.rules[1].targets.length).to eq(2)
|
363
|
+
expect(config.rules[1].targets[0].queue).to eq("WQ8c62f84b61ccfa6a333757cd508f0aae")
|
364
|
+
expect(config.rules[1].targets[0].priority).to eq(1)
|
365
|
+
expect(config.rules[1].targets[0].timeout).to eq(120)
|
366
|
+
expect(config.rules[1].targets[1].queue).to eq("WQ8c62f84b61ccfa6a333757cd508f0aae")
|
367
|
+
expect(config.rules[1].targets[1].priority).to eq(3)
|
368
|
+
# support assertions
|
369
|
+
expect(config.rules[2].expression).to eq("type=='support'")
|
370
|
+
expect(config.rules[2].friendly_name).to eq("Support")
|
371
|
+
expect(config.rules[2].targets.length).to eq(2)
|
372
|
+
expect(config.rules[2].targets[0].queue).to eq("WQ5940dc0da87eaf6e3321d62041d4403b")
|
373
|
+
expect(config.rules[2].targets[0].priority).to eq(10)
|
374
|
+
expect(config.rules[2].targets[0].timeout).to eq(30)
|
375
|
+
expect(config.rules[2].targets[1].queue).to eq("WQ5940dc0da87eaf6e3321d62041d4403b")
|
376
|
+
expect(config.rules[2].targets[1].priority).to eq(15)
|
377
|
+
# default filter
|
378
|
+
expect(config.default_target.queue).to eq("WQ6d29383312b24bd898a8df32779fc043")
|
379
|
+
end
|
380
|
+
|
381
|
+
it 'should be able to parse the workflow with filter friendly name and marshall as friendly name' do
|
382
|
+
json = "{
|
383
|
+
\"task_routing\":{
|
384
|
+
\"filters\":[
|
385
|
+
{
|
386
|
+
\"expression\":\"type=='sales'\",
|
387
|
+
\"targets\":[
|
388
|
+
{
|
389
|
+
\"queue\":\"WQf6724bd5005b30eeb6ea990c3e59e536\",
|
390
|
+
\"priority\": 5,
|
391
|
+
\"timeout\": 30
|
392
|
+
},
|
393
|
+
{
|
394
|
+
\"queue\":\"WQf6724bd5005b30eeb6ea990c3e59e536\",
|
395
|
+
\"priority\": 10
|
396
|
+
}
|
397
|
+
],
|
398
|
+
\"filter_friendly_name\":\"Sales\"
|
399
|
+
},
|
400
|
+
{
|
401
|
+
\"expression\":\"type=='marketing'\",
|
402
|
+
\"targets\":[
|
403
|
+
{
|
404
|
+
\"queue\":\"WQ8c62f84b61ccfa6a333757cd508f0aae\",
|
405
|
+
\"priority\": 1,
|
406
|
+
\"timeout\": 120
|
407
|
+
},
|
408
|
+
{
|
409
|
+
\"queue\":\"WQ8c62f84b61ccfa6a333757cd508f0aae\",
|
410
|
+
\"priority\": 3
|
411
|
+
}
|
412
|
+
],
|
413
|
+
\"filter_friendly_name\":\"Marketing\"
|
414
|
+
},
|
415
|
+
{
|
416
|
+
\"expression\":\"type=='support'\",
|
417
|
+
\"targets\":[
|
418
|
+
{
|
419
|
+
\"queue\":\"WQ5940dc0da87eaf6e3321d62041d4403b\",
|
420
|
+
\"priority\": 10,
|
421
|
+
\"timeout\": 30
|
422
|
+
},
|
423
|
+
{
|
424
|
+
\"queue\":\"WQ5940dc0da87eaf6e3321d62041d4403b\",
|
425
|
+
\"priority\": 15
|
426
|
+
}
|
427
|
+
],
|
428
|
+
\"filter_friendly_name\":\"Support\"
|
429
|
+
}
|
430
|
+
],
|
431
|
+
\"default_filter\":{
|
432
|
+
\"queue\":\"WQ6d29383312b24bd898a8df32779fc043\"
|
433
|
+
}
|
434
|
+
}
|
435
|
+
}"
|
436
|
+
|
437
|
+
config = Twilio::TaskRouter::WorkflowConfiguration.parse_json(json)
|
438
|
+
|
439
|
+
newJSON = config.to_json
|
440
|
+
|
441
|
+
expected = "{
|
442
|
+
\"task_routing\":{
|
443
|
+
\"filters\":[
|
444
|
+
{
|
445
|
+
\"expression\":\"type=='sales'\",
|
446
|
+
\"targets\":[
|
447
|
+
{
|
448
|
+
\"queue\":\"WQf6724bd5005b30eeb6ea990c3e59e536\",
|
449
|
+
\"priority\": 5,
|
450
|
+
\"timeout\": 30
|
451
|
+
},
|
452
|
+
{
|
453
|
+
\"queue\":\"WQf6724bd5005b30eeb6ea990c3e59e536\",
|
454
|
+
\"priority\": 10
|
455
|
+
}
|
456
|
+
],
|
457
|
+
\"friendly_name\":\"Sales\"
|
458
|
+
},
|
459
|
+
{
|
460
|
+
\"expression\":\"type=='marketing'\",
|
461
|
+
\"targets\":[
|
462
|
+
{
|
463
|
+
\"queue\":\"WQ8c62f84b61ccfa6a333757cd508f0aae\",
|
464
|
+
\"priority\": 1,
|
465
|
+
\"timeout\": 120
|
466
|
+
},
|
467
|
+
{
|
468
|
+
\"queue\":\"WQ8c62f84b61ccfa6a333757cd508f0aae\",
|
469
|
+
\"priority\": 3
|
470
|
+
}
|
471
|
+
],
|
472
|
+
\"friendly_name\":\"Marketing\"
|
473
|
+
},
|
474
|
+
{
|
475
|
+
\"expression\":\"type=='support'\",
|
476
|
+
\"targets\":[
|
477
|
+
{
|
478
|
+
\"queue\":\"WQ5940dc0da87eaf6e3321d62041d4403b\",
|
479
|
+
\"priority\": 10,
|
480
|
+
\"timeout\": 30
|
481
|
+
},
|
482
|
+
{
|
483
|
+
\"queue\":\"WQ5940dc0da87eaf6e3321d62041d4403b\",
|
484
|
+
\"priority\": 15
|
485
|
+
}
|
486
|
+
],
|
487
|
+
\"friendly_name\":\"Support\"
|
488
|
+
}
|
489
|
+
],
|
490
|
+
\"default_filter\":{
|
491
|
+
\"queue\":\"WQ6d29383312b24bd898a8df32779fc043\"
|
492
|
+
}
|
493
|
+
}
|
494
|
+
}"
|
495
|
+
|
496
|
+
expected = JSON.parse(expected).to_json
|
497
|
+
|
498
|
+
expect(expected).to eq(newJSON)
|
499
|
+
end
|
500
|
+
end
|
501
|
+
end
|
@@ -42,7 +42,7 @@ describe Twilio::TaskRouter::Capability do
|
|
42
42
|
it 'should allow websocket operations and fetching the workspace by default' do
|
43
43
|
token = @capability.generate_token
|
44
44
|
decoded, header = JWT.decode token, 'foobar'
|
45
|
-
expect(decoded['policies'].size).to eq(
|
45
|
+
expect(decoded['policies'].size).to eq(6)
|
46
46
|
|
47
47
|
activites_fetch_policy = {
|
48
48
|
'url' => 'https://taskrouter.twilio.com/v1/Workspaces/WS456/Activities',
|
@@ -53,14 +53,23 @@ describe Twilio::TaskRouter::Capability do
|
|
53
53
|
}
|
54
54
|
expect(decoded['policies'][0]).to eq(activites_fetch_policy)
|
55
55
|
|
56
|
-
|
56
|
+
task_fetch_policy = {
|
57
57
|
'url' => 'https://taskrouter.twilio.com/v1/Workspaces/WS456/Tasks/**',
|
58
58
|
'method' => 'GET',
|
59
59
|
'query_filter' => {},
|
60
60
|
'post_filter' => {},
|
61
61
|
'allow' => true
|
62
62
|
}
|
63
|
-
expect(decoded['policies'][1]).to eq(
|
63
|
+
expect(decoded['policies'][1]).to eq(task_fetch_policy)
|
64
|
+
|
65
|
+
worker_reservation_fetch_policy = {
|
66
|
+
'url' => 'https://taskrouter.twilio.com/v1/Workspaces/WS456/Workers/WK789/Reservations/**',
|
67
|
+
'method' => 'GET',
|
68
|
+
'query_filter' => {},
|
69
|
+
'post_filter' => {},
|
70
|
+
'allow' => true
|
71
|
+
}
|
72
|
+
expect(decoded['policies'][2]).to eq(worker_reservation_fetch_policy)
|
64
73
|
|
65
74
|
get_policy = {
|
66
75
|
"url" => 'https://event-bridge.twilio.com/v1/wschannels/AC123/WK789',
|
@@ -69,7 +78,7 @@ describe Twilio::TaskRouter::Capability do
|
|
69
78
|
"post_filter" => {},
|
70
79
|
"allow" => true
|
71
80
|
}
|
72
|
-
expect(decoded['policies'][
|
81
|
+
expect(decoded['policies'][3]).to eq(get_policy)
|
73
82
|
post_policy = {
|
74
83
|
"url" => 'https://event-bridge.twilio.com/v1/wschannels/AC123/WK789',
|
75
84
|
"method" => 'POST',
|
@@ -77,7 +86,7 @@ describe Twilio::TaskRouter::Capability do
|
|
77
86
|
"post_filter" => {},
|
78
87
|
"allow" => true
|
79
88
|
}
|
80
|
-
expect(decoded['policies'][
|
89
|
+
expect(decoded['policies'][4]).to eq(post_policy)
|
81
90
|
|
82
91
|
worker_fetch_policy = {
|
83
92
|
'url' => 'https://taskrouter.twilio.com/v1/Workspaces/WS456/Workers/WK789',
|
@@ -86,7 +95,7 @@ describe Twilio::TaskRouter::Capability do
|
|
86
95
|
'post_filter' => {},
|
87
96
|
'allow' => true
|
88
97
|
}
|
89
|
-
expect(decoded['policies'][
|
98
|
+
expect(decoded['policies'][5]).to eq(worker_fetch_policy)
|
90
99
|
end
|
91
100
|
|
92
101
|
it 'should add a policy when #allow_worker_activity_updates is called' do
|
@@ -42,7 +42,7 @@ describe Twilio::TaskRouter::WorkerCapability do
|
|
42
42
|
it 'should allow websocket operations and activity list fetches by default' do
|
43
43
|
token = @capability.generate_token
|
44
44
|
decoded, header = JWT.decode token, 'foobar'
|
45
|
-
expect(decoded['policies'].size).to eq(
|
45
|
+
expect(decoded['policies'].size).to eq(6)
|
46
46
|
get_policy = {
|
47
47
|
"url" => 'https://event-bridge.twilio.com/v1/wschannels/AC123/WK789',
|
48
48
|
"method" => 'GET',
|
@@ -78,14 +78,23 @@ describe Twilio::TaskRouter::WorkerCapability do
|
|
78
78
|
}
|
79
79
|
expect(decoded['policies'][3]).to eq(activities_policy)
|
80
80
|
|
81
|
-
|
81
|
+
tasks_policy = {
|
82
82
|
'url' => 'https://taskrouter.twilio.com/v1/Workspaces/WS456/Tasks/**',
|
83
83
|
'method' => 'GET',
|
84
84
|
'query_filter' => {},
|
85
85
|
'post_filter' => {},
|
86
86
|
'allow' => true
|
87
87
|
}
|
88
|
-
expect(decoded['policies'][4]).to eq(
|
88
|
+
expect(decoded['policies'][4]).to eq(tasks_policy)
|
89
|
+
|
90
|
+
worker_reservations_policy = {
|
91
|
+
'url' => 'https://taskrouter.twilio.com/v1/Workspaces/WS456/Workers/WK789/Reservations/**',
|
92
|
+
'method' => 'GET',
|
93
|
+
'query_filter' => {},
|
94
|
+
'post_filter' => {},
|
95
|
+
'allow' => true
|
96
|
+
}
|
97
|
+
expect(decoded['policies'][5]).to eq(worker_reservations_policy)
|
89
98
|
end
|
90
99
|
|
91
100
|
it 'should add a policy when #allow_activity_updates is called' do
|
@@ -107,7 +116,7 @@ describe Twilio::TaskRouter::WorkerCapability do
|
|
107
116
|
expect(decoded['policies'].size).to eq(policies_size+1)
|
108
117
|
end
|
109
118
|
|
110
|
-
it 'should add
|
119
|
+
it 'should add two policies when #allow_reservation_updates is called' do
|
111
120
|
token = @capability.generate_token
|
112
121
|
decoded, header = JWT.decode token, 'foobar'
|
113
122
|
policies_size = decoded['policies'].size
|
@@ -115,15 +124,23 @@ describe Twilio::TaskRouter::WorkerCapability do
|
|
115
124
|
@capability.allow_reservation_updates
|
116
125
|
token = @capability.generate_token
|
117
126
|
decoded, header = JWT.decode token, 'foobar'
|
118
|
-
|
127
|
+
tasks_policy = {
|
119
128
|
'url' => 'https://taskrouter.twilio.com/v1/Workspaces/WS456/Tasks/**',
|
120
129
|
'method' => 'POST',
|
121
130
|
'query_filter' => {},
|
122
131
|
'post_filter' => {},
|
123
132
|
'allow' => true
|
124
133
|
}
|
125
|
-
expect(decoded['policies'][-
|
126
|
-
|
134
|
+
expect(decoded['policies'][-2]).to eq(tasks_policy)
|
135
|
+
worker_reservations_policy = {
|
136
|
+
'url' => 'https://taskrouter.twilio.com/v1/Workspaces/WS456/Workers/WK789/Reservations/**',
|
137
|
+
'method' => 'POST',
|
138
|
+
'query_filter' => {},
|
139
|
+
'post_filter' => {},
|
140
|
+
'allow' => true
|
141
|
+
}
|
142
|
+
expect(decoded['policies'][-1]).to eq(worker_reservations_policy)
|
143
|
+
expect(decoded['policies'].size).to eq(policies_size+2)
|
127
144
|
end
|
128
145
|
end
|
129
146
|
end
|