@@ -10,84 +10,99 @@ TaskRouter is Twilio's skills based routing system. With this library, you can m
1010
1111This version of TaskRouter SDK can be used with Twilio Flex and TaskRouter standalone instances.
1212
13- Installation
14- ------------
13+ ## Installation
1514
1615### NPM
1716
1817```
1918npm install twilio-taskrouter
2019```
2120
22- Usage
23- -----
21+ ## Usage
2422
2523The following is a simple example showing a Worker waiting for Reservations.
2624For more information, refer to the
2725[ API Docs] ( //twilio.github.io/twilio-taskrouter.js/index.html ) .
2826
2927``` js
30- const TaskRouter = require (' twilio-taskrouter' );
31- const Twilio = require (' twilio' );
28+ const TaskRouter = require (" twilio-taskrouter" );
29+ const Twilio = require (" twilio" );
3230const AccessToken = Twilio .jwt .AccessToken ;
3331const TaskRouterGrant = AccessToken .TaskRouterGrant ;
3432
35- const accountSid = ' ' ;
36- const signingKeySid = ' ' ;
37- const signingKeySecret = ' ' ;
38- const workspaceSid = ' ' ;
39- const workerSid = ' ' ;
40-
41- const token = createAccessToken (accountSid, signingKeySid, signingKeySecret, workspaceSid, workerSid);
33+ const accountSid = " " ;
34+ const signingKeySid = " " ;
35+ const signingKeySecret = " " ;
36+ const workspaceSid = " " ;
37+ const workerSid = " " ;
38+
39+ const token = createAccessToken (
40+ accountSid,
41+ signingKeySid,
42+ signingKeySecret,
43+ workspaceSid,
44+ workerSid
45+ );
4246const alice = new TaskRouter.Worker (token);
4347
44- alice .on (' ready' , readyAlice => {
45- console .log (` Worker ${ readyAlice .sid } is now ready for work` );
48+ alice .on (" ready" , ( readyAlice ) => {
49+ console .log (` Worker ${ readyAlice .sid } is now ready for work` );
4650});
4751
48- alice .on (' reservationCreated' , reservation => {
49- console .log (` Reservation ${ reservation .sid } has been created for ${ alice .sid } ` );
50- console .log (` Task attributes are: ${ reservation .task .attributes } ` );
52+ alice .on (" reservationCreated" , (reservation ) => {
53+ console .log (
54+ ` Reservation ${ reservation .sid } has been created for ${ alice .sid } `
55+ );
56+ console .log (` Task attributes are: ${ reservation .task .attributes } ` );
5157
52- reservation .on (' accepted' , acceptedReservation => {
53- console .log (` Reservation ${ acceptedReservation .sid } was accepted.` );
54- });
58+ reservation .on (" accepted" , ( acceptedReservation ) => {
59+ console .log (` Reservation ${ acceptedReservation .sid } was accepted.` );
60+ });
5561
56- reservation .accept ().then (acceptedReservation => {
62+ reservation
63+ .accept ()
64+ .then ((acceptedReservation ) => {
5765 console .log (` Reservation status is ${ acceptedReservation .status } ` );
58- }).catch ((err ) => {
66+ })
67+ .catch ((err ) => {
5968 console .log (` Error: ${ err} ` );
6069 });
6170});
6271
63- function createAccessToken (accountSid , signingKeySid , signingKeySecret , workspaceSid , workerSid ) {
64- const taskRouterGrant = new TaskRouterGrant ({
65- workerSid: workerSid,
66- workspaceSid: workspaceSid,
67- role: ' worker'
68- });
69-
70- const accessToken = new AccessToken (accountSid, signingKeySid, signingKeySecret);
71- accessToken .addGrant (taskRouterGrant);
72- accessToken .identity = ' alice' ;
73-
74- return accessToken .toJwt ();
72+ function createAccessToken (
73+ accountSid ,
74+ signingKeySid ,
75+ signingKeySecret ,
76+ workspaceSid ,
77+ workerSid
78+ ) {
79+ const taskRouterGrant = new TaskRouterGrant ({
80+ workerSid: workerSid,
81+ workspaceSid: workspaceSid,
82+ role: " worker" ,
83+ });
84+
85+ const accessToken = new AccessToken (
86+ accountSid,
87+ signingKeySid,
88+ signingKeySecret
89+ );
90+ accessToken .addGrant (taskRouterGrant);
91+ accessToken .identity = " alice" ;
92+
93+ return accessToken .toJwt ();
7594}
76-
7795```
7896
79- Changelog
80- ---------
97+ ## Changelog
8198
82- See [ CHANGELOG.md] ( https://github.com/twilio/twilio-taskrouter.js/blob/master /CHANGELOG.md ) .
99+ See [ CHANGELOG.md] ( https://github.com/twilio/twilio-taskrouter.js/blob/main /CHANGELOG.md ) .
83100
84- License
85- -------
101+ ## License
86102
87- See [ LICENSE.md] ( https://github.com/twilio/twilio-taskrouter.js/blob/master /LICENSE.md ) .
103+ See [ LICENSE.md] ( https://github.com/twilio/twilio-taskrouter.js/blob/main /LICENSE.md ) .
88104
89- Building
90- --------
105+ ## Building
91106
92107Fork and clone the repository. Use npm to install node 8 (other versions may run into problems).
93108
@@ -111,19 +126,18 @@ Before commits, be sure to validate by running:
111126make lint
112127```
113128
114- Testing
115- ------------
129+ ## Testing
130+
116131- Create a twilio account
117132- copy ./test/integration_test_setup/.env.example to ./test/integration_test_setup/.env
118133- set ACCOUNT_SID, AUTH_TOKEN, SIGNING_KEY_SID, SIGNING_KEY_SECRET
119134- Run ./test/integration_test_setup/RunIntegrationTestLocal.sh this will create everything needed for running E2E tests and run the tests
120135
121- Test with Sample App
122- ------------
136+ ## Test with Sample App
137+
123138- See [ README.md] ( sample-app/README.md )
124139
125- Contributing
126- ------------
140+ ## Contributing
127141
128142Bug fixes welcome! If you're not familiar with the GitHub pull
129143request/contribution process, [ this is a nice tutorial] ( https://gun.io/blog/how-to-github-fork-branch-and-pull-request/ ) .
0 commit comments