1
+ <!DOCTYPE html> < html lang ="en "> < head >
2
+ < meta charset ="utf-8 ">
3
+ < meta name ="viewport " content ="width=device-width ">
4
+ < title > Documentation Index</ title >
5
+
6
+ <!--[if lt IE 9]>
7
+ <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
8
+ <![endif]-->
9
+ < link type ="text/css " rel ="stylesheet " href ="styles/sunlight.default.css ">
10
+
11
+ < link type ="text/css " rel ="stylesheet " href ="styles/site.simplex.css ">
12
+
13
+ </ head >
14
+
15
+ < body >
16
+
17
+ < div class ="navbar navbar-default navbar-fixed-top ">
18
+ < div class ="container ">
19
+ < div class ="navbar-header ">
20
+ < a class ="navbar-brand " href ="index.html "> Documentation</ a >
21
+ < button class ="navbar-toggle " type ="button " data-toggle ="collapse " data-target ="#topNavigation ">
22
+ < span class ="icon-bar "> </ span >
23
+ < span class ="icon-bar "> </ span >
24
+ < span class ="icon-bar "> </ span >
25
+ </ button >
26
+ </ div >
27
+ < div class ="navbar-collapse collapse " id ="topNavigation ">
28
+ < ul class ="nav navbar-nav ">
29
+
30
+ < li class ="dropdown ">
31
+ < a href ="classes.list.html " class ="dropdown-toggle " data-toggle ="dropdown "> Classes< b class ="caret "> </ b > </ a >
32
+ < ul class ="dropdown-menu ">
33
+ < li > < a href ="Activity.html "> Activity</ a > </ li > < li > < a href ="Channel.html "> Channel</ a > </ li > < li > < a href ="IncomingTransfer.html "> IncomingTransfer</ a > </ li > < li > < a href ="OutgoingTransfer.html "> OutgoingTransfer</ a > </ li > < li > < a href ="Reservation.html "> Reservation</ a > </ li > < li > < a href ="Supervisor.html "> Supervisor</ a > </ li > < li > < a href ="Task.html "> Task</ a > </ li > < li > < a href ="TaskQueue.html "> TaskQueue</ a > </ li > < li > < a href ="Transfers.html "> Transfers</ a > </ li > < li > < a href ="Worker.html "> Worker</ a > </ li > < li > < a href ="Workspace.html "> Workspace</ a > </ li >
34
+ </ ul >
35
+ </ li >
36
+
37
+ < li class ="dropdown ">
38
+ < a href ="events.list.html " class ="dropdown-toggle " data-toggle ="dropdown "> Events< b class ="caret "> </ b > </ a >
39
+ < ul class ="dropdown-menu ">
40
+ < li > < a href ="Channel.html#event:availabilityUpdated "> Channel#event:availabilityUpdated</ a > </ li > < li > < a href ="Channel.html#event:capacityUpdated "> Channel#event:capacityUpdated</ a > </ li > < li > < a href ="OutgoingTransfer.html#event:attemptFailed "> OutgoingTransfer#event:attemptFailed</ a > </ li > < li > < a href ="OutgoingTransfer.html#event:canceled "> OutgoingTransfer#event:canceled</ a > </ li > < li > < a href ="OutgoingTransfer.html#event:completed "> OutgoingTransfer#event:completed</ a > </ li > < li > < a href ="OutgoingTransfer.html#event:failed "> OutgoingTransfer#event:failed</ a > </ li > < li > < a href ="Reservation.html#event:accepted "> Reservation#event:accepted</ a > </ li > < li > < a href ="Reservation.html#event:canceled "> Reservation#event:canceled</ a > </ li > < li > < a href ="Reservation.html#event:completed "> Reservation#event:completed</ a > </ li > < li > < a href ="Reservation.html#event:rejected "> Reservation#event:rejected</ a > </ li > < li > < a href ="Reservation.html#event:rescinded "> Reservation#event:rescinded</ a > </ li > < li > < a href ="Reservation.html#event:timeout "> Reservation#event:timeout</ a > </ li > < li > < a href ="Reservation.html#event:wrapup "> Reservation#event:wrapup</ a > </ li > < li > < a href ="Supervisor.html#event:activityUpdated "> Supervisor#event:activityUpdated</ a > </ li > < li > < a href ="Supervisor.html#event:attributesUpdated "> Supervisor#event:attributesUpdated</ a > </ li > < li > < a href ="Supervisor.html#event:disconnected "> Supervisor#event:disconnected</ a > </ li > < li > < a href ="Supervisor.html#event:error "> Supervisor#event:error</ a > </ li > < li > < a href ="Supervisor.html#event:monitor "> Supervisor#event:monitor</ a > </ li > < li > < a href ="Supervisor.html#event:ready "> Supervisor#event:ready</ a > </ li > < li > < a href ="Supervisor.html#event:reservationCreated "> Supervisor#event:reservationCreated</ a > </ li > < li > < a href ="Supervisor.html#event:reservationFailed "> Supervisor#event:reservationFailed</ a > </ li > < li > < a href ="Supervisor.html#event:tokenExpired "> Supervisor#event:tokenExpired</ a > </ li > < li > < a href ="Supervisor.html#event:tokenUpdated "> Supervisor#event:tokenUpdated</ a > </ li > < li > < a href ="Task.html#event:canceled "> Task#event:canceled</ a > </ li > < li > < a href ="Task.html#event:completed "> Task#event:completed</ a > </ li > < li > < a href ="Task.html#event:transferAttemptFailed "> Task#event:transferAttemptFailed</ a > </ li > < li > < a href ="Task.html#event:transferCanceled "> Task#event:transferCanceled</ a > </ li > < li > < a href ="Task.html#event:transferCompleted "> Task#event:transferCompleted</ a > </ li > < li > < a href ="Task.html#event:transferFailed "> Task#event:transferFailed</ a > </ li > < li > < a href ="Task.html#event:transferInitiated "> Task#event:transferInitiated</ a > </ li > < li > < a href ="Task.html#event:updated "> Task#event:updated</ a > </ li > < li > < a href ="Task.html#event:wrapup "> Task#event:wrapup</ a > </ li > < li > < a href ="Worker.html#event:activityUpdated "> Worker#event:activityUpdated</ a > </ li > < li > < a href ="Worker.html#event:attributesUpdated "> Worker#event:attributesUpdated</ a > </ li > < li > < a href ="Worker.html#event:disconnected "> Worker#event:disconnected</ a > </ li > < li > < a href ="Worker.html#event:error "> Worker#event:error</ a > </ li > < li > < a href ="Worker.html#event:ready "> Worker#event:ready</ a > </ li > < li > < a href ="Worker.html#event:reservationCreated "> Worker#event:reservationCreated</ a > </ li > < li > < a href ="Worker.html#event:reservationFailed "> Worker#event:reservationFailed</ a > </ li > < li > < a href ="Worker.html#event:tokenExpired "> Worker#event:tokenExpired</ a > </ li > < li > < a href ="Worker.html#event:tokenUpdated "> Worker#event:tokenUpdated</ a > </ li >
41
+ </ ul >
42
+ </ li >
43
+
44
+ < li class ="dropdown ">
45
+ < a href ="global.html " class ="dropdown-toggle " data-toggle ="dropdown "> Global< b class ="caret "> </ b > </ a >
46
+ < ul class ="dropdown-menu ">
47
+ < li > < a href ="global.html "> Global</ a > </ li >
48
+ </ ul >
49
+ </ li >
50
+
51
+ </ ul >
52
+
53
+ < div class ="col-sm-3 col-md-3 ">
54
+ < form class ="navbar-form " role ="search ">
55
+ < div class ="input-group ">
56
+ < input type ="text " class ="form-control " placeholder ="Search " name ="q " id ="search-input ">
57
+ < div class ="input-group-btn ">
58
+ < button class ="btn btn-default " id ="search-submit "> < i class ="glyphicon glyphicon-search "> </ i > </ button >
59
+ </ div >
60
+ </ div >
61
+ </ form >
62
+ </ div >
63
+
64
+ </ div >
65
+
66
+ </ div >
67
+ </ div >
68
+
69
+
70
+ < div class ="container " id ="toc-content ">
71
+ < div class ="row ">
72
+
73
+
74
+ < div class ="col-md-8 ">
75
+
76
+ < div id ="main ">
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+ < section class ="readme-section ">
100
+ < article > < p > < a href ="https://github.com/twilio/twilio-taskrouter.js/actions/workflows/build.yml "> < img src ="https://github.com/twilio/twilio-taskrouter.js/actions/workflows/build.yml/badge.svg " alt ="build "> </ a >
101
+ < a href ="https://github.com/twilio/twilio-taskrouter.js/actions/workflows/release.yml "> < img src ="https://github.com/twilio/twilio-taskrouter.js/actions/workflows/release.yml/badge.svg " alt ="Release "> </ a >
102
+ < a href ="https://badge.fury.io/js/twilio-taskrouter "> < img src ="https://badge.fury.io/js/twilio-taskrouter.svg " alt ="npm version "> </ a > </ p >
103
+ < h1 > twilio-taskrouter.js</ h1 >
104
+ < p > < a href ="https://badge.fury.io/js/twilio-taskrouter "> < img src ="https://badge.fury.io/js/twilio-taskrouter.svg " alt ="npm version "> </ a > </ p >
105
+ < p > TaskRouter is Twilio's skills based routing system. With this library, you can manage your Workers in the browser or view the state of your Workspace.</ p >
106
+ < p > This version of TaskRouter SDK can be used with Twilio Flex and TaskRouter standalone instances.</ p >
107
+ < h2 > Installation</ h2 >
108
+ < h3 > NPM</ h3 >
109
+ < pre class ="prettyprint source "> < code > npm install twilio-taskrouter
110
+ </ code > </ pre >
111
+ < h2 > Usage</ h2 >
112
+ < p > The following is a simple example showing a Worker waiting for Reservations.
113
+ For more information, refer to the
114
+ < a href ="//twilio.github.io/twilio-taskrouter.js/index.html "> API Docs</ a > .</ p >
115
+ < pre class ="prettyprint source lang-js "> < code > const TaskRouter = require("twilio-taskrouter");
116
+ const Twilio = require("twilio");
117
+ const AccessToken = Twilio.jwt.AccessToken;
118
+ const TaskRouterGrant = AccessToken.TaskRouterGrant;
119
+
120
+ const accountSid = "";
121
+ const signingKeySid = "";
122
+ const signingKeySecret = "";
123
+ const workspaceSid = "";
124
+ const workerSid = "";
125
+
126
+ const token = createAccessToken(
127
+ accountSid,
128
+ signingKeySid,
129
+ signingKeySecret,
130
+ workspaceSid,
131
+ workerSid
132
+ );
133
+ const alice = new TaskRouter.Worker(token);
134
+
135
+ alice.on("ready", (readyAlice) => {
136
+ console.log(`Worker ${readyAlice.sid} is now ready for work`);
137
+ });
138
+
139
+ alice.on("reservationCreated", (reservation) => {
140
+ console.log(
141
+ `Reservation ${reservation.sid} has been created for ${alice.sid}`
142
+ );
143
+ console.log(`Task attributes are: ${reservation.task.attributes}`);
144
+
145
+ reservation.on("accepted", (acceptedReservation) => {
146
+ console.log(`Reservation ${acceptedReservation.sid} was accepted.`);
147
+ });
148
+
149
+ reservation
150
+ .accept()
151
+ .then((acceptedReservation) => {
152
+ console.log(`Reservation status is ${acceptedReservation.status}`);
153
+ })
154
+ .catch((err) => {
155
+ console.log(`Error: ${err}`);
156
+ });
157
+ });
158
+
159
+ function createAccessToken(
160
+ accountSid,
161
+ signingKeySid,
162
+ signingKeySecret,
163
+ workspaceSid,
164
+ workerSid
165
+ ) {
166
+ const taskRouterGrant = new TaskRouterGrant({
167
+ workerSid: workerSid,
168
+ workspaceSid: workspaceSid,
169
+ role: "worker",
170
+ });
171
+
172
+ const accessToken = new AccessToken(
173
+ accountSid,
174
+ signingKeySid,
175
+ signingKeySecret
176
+ );
177
+ accessToken.addGrant(taskRouterGrant);
178
+ accessToken.identity = "alice";
179
+
180
+ return accessToken.toJwt();
181
+ }
182
+ </ code > </ pre >
183
+ < h2 > Changelog</ h2 >
184
+ < p > See < a href ="https://github.com/twilio/twilio-taskrouter.js/blob/main/CHANGELOG.md "> CHANGELOG.md</ a > .</ p >
185
+ < h2 > License</ h2 >
186
+ < p > See < a href ="https://github.com/twilio/twilio-taskrouter.js/blob/main/LICENSE.md "> LICENSE.md</ a > .</ p >
187
+ < h2 > Building</ h2 >
188
+ < p > Fork and clone the repository. Use npm to install node 8 (other versions may run into problems).</ p >
189
+ < p > Then, install dependencies with:</ p >
190
+ < pre class ="prettyprint source "> < code > yarn install
191
+ </ code > </ pre >
192
+ < p > Then run the < code > build</ code > script:</ p >
193
+ < pre class ="prettyprint source "> < code > yarn build
194
+ </ code > </ pre >
195
+ < p > The builds and docs will be placed in the < code > dist/</ code > directory.</ p >
196
+ < p > Before commits, be sure to validate by running:</ p >
197
+ < pre class ="prettyprint source "> < code > make lint
198
+ </ code > </ pre >
199
+ < h2 > Testing</ h2 >
200
+ < ul >
201
+ < li > Create a twilio account</ li >
202
+ < li > copy ./test/integration_test_setup/.env.example to ./test/integration_test_setup/.env</ li >
203
+ < li > set ACCOUNT_SID, AUTH_TOKEN, SIGNING_KEY_SID, SIGNING_KEY_SECRET</ li >
204
+ < li > Run ./test/integration_test_setup/RunIntegrationTestLocal.sh this will create everything needed for running E2E tests and run the tests</ li >
205
+ </ ul >
206
+ < h2 > Test with Sample App</ h2 >
207
+ < ul >
208
+ < li > See < a href ="sample-app/README.md "> README.md</ a > </ li >
209
+ </ ul >
210
+ < h2 > Contributing</ h2 >
211
+ < p > Bug fixes welcome! If you're not familiar with the GitHub pull
212
+ request/contribution process, < a href ="https://gun.io/blog/how-to-github-fork-branch-and-pull-request/ "> this is a nice tutorial</ a > .</ p > </ article >
213
+ </ section >
214
+
215
+
216
+
217
+
218
+
219
+
220
+
221
+ </ div >
222
+ </ div >
223
+
224
+ < div class ="clearfix "> </ div >
225
+
226
+
227
+ < div class ="col-md-3 ">
228
+ < div id ="toc " class ="col-md-3 hidden-xs hidden-sm hidden-md "> </ div >
229
+ </ div >
230
+
231
+
232
+ </ div >
233
+ </ div >
234
+
235
+
236
+ < div class ="modal fade " id ="searchResults ">
237
+ < div class ="modal-dialog ">
238
+ < div class ="modal-content ">
239
+ < div class ="modal-header ">
240
+ < button type ="button " class ="close " data-dismiss ="modal " aria-label ="Close "> < span aria-hidden ="true "> ×</ span > </ button >
241
+ < h4 class ="modal-title "> Search results</ h4 >
242
+ </ div >
243
+ < div class ="modal-body "> </ div >
244
+ < div class ="modal-footer ">
245
+ < button type ="button " class ="btn btn-default " data-dismiss ="modal "> Close</ button >
246
+ </ div >
247
+ </ div > <!-- /.modal-content -->
248
+ </ div > <!-- /.modal-dialog -->
249
+ </ div >
250
+
251
+
252
+ < footer >
253
+
254
+
255
+ < span class ="jsdoc-message ">
256
+ Documentation generated by < a href ="https://github.com/jsdoc3/jsdoc "> JSDoc 3.6.11</ a >
257
+
258
+ on 2024-08-24T14:56:30+00:00
259
+
260
+ using the < a href ="https://github.com/docstrap/docstrap "> DocStrap template</ a > .
261
+ </ span >
262
+ </ footer >
263
+
264
+ < script src ="scripts/docstrap.lib.js "> </ script >
265
+ < script src ="scripts/toc.js "> </ script >
266
+
267
+ < script type ="text/javascript " src ="scripts/fulltext-search-ui.js "> </ script >
268
+
269
+
270
+ < script >
271
+ $ ( function ( ) {
272
+ $ ( "[id*='$']" ) . each ( function ( ) {
273
+ var $this = $ ( this ) ;
274
+
275
+ $this . attr ( "id" , $this . attr ( "id" ) . replace ( "$" , "__" ) ) ;
276
+ } ) ;
277
+
278
+ $ ( ".tutorial-section pre, .readme-section pre, pre.prettyprint.source" ) . each ( function ( ) {
279
+ var $this = $ ( this ) ;
280
+
281
+ var example = $this . find ( "code" ) ;
282
+ exampleText = example . html ( ) ;
283
+ var lang = / { @ l a n g ( .* ?) } / . exec ( exampleText ) ;
284
+ if ( lang && lang [ 1 ] ) {
285
+ exampleText = exampleText . replace ( lang [ 0 ] , "" ) ;
286
+ example . html ( exampleText ) ;
287
+ lang = lang [ 1 ] ;
288
+ } else {
289
+ var langClassMatch = example . parent ( ) [ 0 ] . className . match ( / l a n g \- ( \S + ) / ) ;
290
+ lang = langClassMatch ? langClassMatch [ 1 ] : "javascript" ;
291
+ }
292
+
293
+ if ( lang ) {
294
+
295
+ $this
296
+ . addClass ( "sunlight-highlight-" + lang )
297
+ . addClass ( "linenums" )
298
+ . html ( example . html ( ) ) ;
299
+
300
+ }
301
+ } ) ;
302
+
303
+ Sunlight . highlightAll ( {
304
+ lineNumbers : false ,
305
+ showMenu : true ,
306
+ enableDoclinks : true
307
+ } ) ;
308
+
309
+ $ . catchAnchorLinks ( {
310
+ navbarOffset : 10
311
+ } ) ;
312
+ $ ( "#toc" ) . toc ( {
313
+ anchorName : function ( i , heading , prefix ) {
314
+ return $ ( heading ) . attr ( "id" ) || ( prefix + i ) ;
315
+ } ,
316
+ selectors : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4" ,
317
+ showAndHide : false ,
318
+ smoothScrolling : true
319
+ } ) ;
320
+
321
+ $ ( "#main span[id^='toc']" ) . addClass ( "toc-shim" ) ;
322
+ $ ( '.dropdown-toggle' ) . dropdown ( ) ;
323
+
324
+ $ ( "table" ) . each ( function ( ) {
325
+ var $this = $ ( this ) ;
326
+ $this . addClass ( 'table' ) ;
327
+ } ) ;
328
+
329
+ } ) ;
330
+ </ script >
331
+
332
+
333
+
334
+ <!--Navigation and Symbol Display-->
335
+
336
+
337
+ <!--Google Analytics-->
338
+
339
+
340
+
341
+ < script type ="text/javascript ">
342
+ $ ( document ) . ready ( function ( ) {
343
+ SearcherDisplay . init ( ) ;
344
+ } ) ;
345
+ </ script >
346
+
347
+
348
+
349
+ </ body > </ html >
0 commit comments