@ujet/websdk-headless 3.37.4 → 3.39.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Headless WebSDK
2
-
2
+ A prebuilt infrastructure for communicating with your CCaaS servers!
3
3
 
4
4
  ## Install
5
5
 
@@ -23,855 +23,11 @@ const client = new Client({
23
23
  tenant: "YOUR-TENANT-NAME",
24
24
  authenticate: authenticate,
25
25
  })
26
-
27
- // const company = await client.getCompany()
28
- // const menus = await client.getMenus()
29
- ```
30
-
31
- Available options for `Client` class:
32
-
33
- ```ts
34
- interface ClientOption {
35
- companyId: string;
36
- authenticate: () => Promise<TokenResponse>;
37
- tenant?: string;
38
- host?: string;
39
- lang?: string;
40
- bridge?: string;
41
- cobrowse?: {
42
- enabled: boolean;
43
- template?: string;
44
- messages?: CobrowseMessages;
45
- api?: string;
46
- license?: string;
47
- trustedOrigins?: string[];
48
- capabilities?: string[];
49
- registration?: boolean;
50
- redactedViews?: string[];
51
- unredactedViews?: string[];
52
- };
53
- }
54
- ```
55
-
56
-
57
- ## Methods
58
-
59
- All methods available for `client` instance.
60
-
61
- ### `getCompany`
62
-
63
- This method is used to get the company information.
64
-
65
- ```ts
66
- const company = await client.getCompany()
67
- ```
68
-
69
- ```ts
70
- interface CompanyResponse {
71
- name: string;
72
- subdomain: string;
73
- support_email: string;
74
- languages: LanguageOption[];
75
- action_tracking: boolean;
76
- email_transcripts: boolean;
77
- message_preview: boolean;
78
- email_enhancement: boolean;
79
- cobrowse_domain?: string;
80
- }
81
- ```
82
-
83
- ### `getAfterHourMessage`
84
-
85
- This method is used for fetching the message for after hour deflection.
86
-
87
- Request parameter:
88
-
89
- ```ts
90
- (lang?: string)
91
- ```
92
-
93
- Example:
94
-
95
- ```js
96
- const message: string = await client.getAfterHourMessage()
97
- ```
98
-
99
- ### `getMenus`
100
-
101
- This method is used to list all the menu items available for the tenant.
102
-
103
- Request parameter:
104
-
105
- ```ts
106
- (key?: string, lang?: string)
107
- ```
108
-
109
- Example:
110
-
111
- ```ts
112
- const data = await client.getMenus("direct_menu_key")
113
- console.log(data.menus)
114
- console.log(data.direct)
115
26
  ```
116
27
 
117
- Response data:
118
-
119
- ```ts
120
- interface MenuItem {
121
- id: number;
122
- name?: string;
123
- enabled: boolean;
124
- redirection?: {
125
- option: string;
126
- data: string;
127
- };
128
- children?: MenuItem[];
129
- channels: MenuChannel[];
130
- deflection?: {
131
- enabled: boolean;
132
- type: string;
133
- };
134
- }
135
-
136
- interface MenuResponse {
137
- menus: MenuItem[];
138
- direct: {
139
- key: boolean;
140
- user: boolean;
141
- };
142
- }
143
- ```
144
-
145
- ### `getTimeSlots`
146
-
147
- This method is used to get available time slots for scheduled calls.
148
-
149
- Request parameter:
150
-
151
- ```ts
152
- (menuId: number | string, lang?: string)
153
- ```
154
-
155
- Example:
156
-
157
- ```ts
158
- const slots = await client.getTimeSlots(123)
159
- ```
160
-
161
- Response data example:
162
-
163
- ```json
164
- [
165
- "2023-05-31 11:45 +0000",
166
- "2023-05-31 12:00 +0000",
167
- "2023-05-31 12:15 +0000",
168
- "2023-05-31 12:30 +0000",
169
- "2023-05-31 12:45 +0000",
170
- "2023-05-31 13:00 +0000",
171
- "2023-05-31 13:15 +0000",
172
- "2023-05-31 13:30 +0000",
173
- "2023-05-31 13:45 +0000",
174
- "2023-05-31 14:00 +0000"
175
- ]
176
- ```
177
-
178
- ### `getWaitTimes`
179
-
180
- This method is used to get the waiting time for chat channel and call channel of
181
- a menu.
182
-
183
- Request parameter:
184
-
185
- ```ts
186
- (menuId: number | string, lang?: string)
187
- ```
188
-
189
- Example:
190
-
191
- ```ts
192
- const {chat, voice_call} = await client.getWaitTimes(123)
193
- ```
194
-
195
- ### `createCall`
196
-
197
- This method is used to create an instant/scheduled call.
198
-
199
- Request parameter:
200
-
201
- ```ts
202
- interface CallRequest {
203
- phone_number: string;
204
- lang?: string;
205
- scheduled_at?: string;
206
- ticket_id?: string;
207
- email?: string;
208
- recording_permission?: "recording_permission_not_asked" | "recording_permission_granted" | "recording_permission_denied";
209
- custom_data?: {
210
- signed?: string;
211
- unsigned?: Record<string, any>;
212
- };
213
- }
214
-
215
- (menuId: number | string, data: CallRequest)
216
- ```
217
-
218
- When `scheduled_at` is set, it will create a scheduled call.
219
-
220
- 1. create an instant call:
221
-
222
- ```ts
223
- const call = await client.createCall(123, {
224
- lang: 'en',
225
- phone_number: '+12345678',
226
- })
227
- ```
228
-
229
- 2. create a scheduled call:
230
-
231
- ```ts
232
- const call = await client.createCall(123, {
233
- lang: 'en',
234
- phone_number: '+12345678',
235
- scheduled_at: '2023-05-31T11:45+0000',
236
- })
237
- ```
238
-
239
- ### `loadCall`
240
-
241
- This method is used to get the call information of the given call ID.
242
-
243
- Request parameter:
244
-
245
- ```ts
246
- (callId: number | string)
247
- ```
248
-
249
- Example:
250
-
251
- ```ts
252
- const call = await client.loadCall(1234)
253
- ```
254
-
255
- ### `cancelCall`
256
-
257
- This method is used to cancel a call, usually used for cancelling a scheduled call.
258
-
259
- Request parameter:
260
-
261
- ```ts
262
- (callId: number | string)
263
- ```
264
-
265
- Example:
266
-
267
- ```ts
268
- client.cancelCall(1234)
269
- ```
270
-
271
- ### `createChat`
272
-
273
- This method is used to create a new chat.
274
-
275
- Request parameter:
276
-
277
- ```ts
278
- interface ChatRequest {
279
- lang?: string;
280
- trigger_id?: string;
281
- ticket_id?: string;
282
- email?: string;
283
- greeting?: string;
284
- cobrowsable?: boolean;
285
- custom_data?: {
286
- signed?: string;
287
- unsigned?: Record<string, any>;
288
- };
289
- }
290
-
291
- (menuId: number | string, data: ChatRequest)
292
- ```
293
-
294
- An example:
295
-
296
- ```ts
297
- client.createChat(123, { lang: 'en' })
298
- ```
299
-
300
- ### `loadChat`
301
-
302
- This method is used to get the chat information of the given chat ID.
303
-
304
- Request parameter:
305
-
306
- ```ts
307
- (chatId: number | string)
308
-
309
- // client.loadChat(1234)
310
- ```
311
-
312
- ### `resumeChat`
313
-
314
- This method is used to resume the chat when chat is "dismissed".
315
-
316
- Request parameter:
317
-
318
- ```ts
319
- (chatId: number | string)
320
-
321
- // client.resumeChat(1234)
322
- ```
323
-
324
- ### `loadOngoingChat`
325
-
326
- This method is used to get the ongoing chat information. The client
327
- will save current ongoing chat ID in browser's localStorage, this
328
- method will try to load the ongoing chat information.
329
-
330
- ```ts
331
- const chat = await client.loadOngoingChat()
332
- ```
333
-
334
- ### `getChatDeflection`
335
-
336
- This method is used to fetch the chat deflection configuration.
337
-
338
- Example:
339
-
340
- ```ts
341
- // this method can only be used when there is a chat
342
- const deflection = await client.getChatDeflection()
343
- ```
344
-
345
- The response is `null` or:
346
-
347
- ```ts
348
- interface ChatDeflectionResponse {
349
- enabled: boolean;
350
- threshold: number;
351
- keep_waiting: boolean;
352
- }
353
- ```
354
-
355
- ### `escalateChat`
356
-
357
- This method will transfer the chat from virtual agent to human agent.
358
-
359
- ```ts
360
- client.escalateChat()
361
- ```
362
-
363
- ### `finishChat`
364
-
365
- This method will change the chat status to `finished`.
366
-
367
- ```ts
368
- client.finishChat()
369
- ```
370
-
371
- Some methods are called after `finishChat`, e.g. `sendChatSurvey`, `sendChatRate`.
372
-
373
- ### `destroyChat`
374
-
375
- This method will destroy current ongoing chat.
376
-
377
- ```ts
378
- client.destroyChat()
379
- ```
380
-
381
- ### `fetchMessages`
382
-
383
- This method is used to get all the previous messages, it is usually used
384
- together with `loadOngoingChat`. You would use this method after chat
385
- is connected.
386
-
387
- The following snippet is using a Deprecated event, please use `chat.connectedMessages` instead.
388
- ```ts
389
- client.on("chat.connected", async () => {
390
- const messages = await client.fetchMessages()
391
- })
392
- ```
393
-
394
- Additionally, you can use the `chat.connectedMessages` event and recieve a duple with the `Chat` and an array of `MessageResponse`:
395
- ```ts
396
- client.on("chat.connectedMessages", async ({chat, messages}: { chat: Chat, messages: MessageResponse[]}) => {
397
- // ...
398
- })
399
- ```
400
-
401
- ### `sendTextMessage`
402
-
403
- Send a text message:
404
-
405
- ```ts
406
- client.sendTextMessage("hello world")
407
- ```
408
-
409
- ### `sendFileMessage`
410
-
411
- Send a file message:
412
-
413
- ```ts
414
- const input = document.querySelector('input[type="file"]')
415
- const file = input.files[0]
416
- client.sendFileMessage(file)
417
- ```
418
-
419
- ### `startCobrowse`
420
-
421
- Request starging cobrowse:
422
-
423
- ```ts
424
- client.startCobrowse()
425
- ```
426
-
427
- ### `createCobrowseCode`
428
-
429
- Create cobrowse code digits:
430
-
431
- ```ts
432
- client.createCobrowseCode()
433
- ```
434
-
435
- ### `sendChatTranscripts`
436
-
437
- Send current chat transcripts to the given emails.
438
-
439
- ```ts
440
- client.sendChatTranscripts([
441
- "name1@example.com",
442
- "name2@example.com",
443
- ])
444
- ```
445
-
446
- ### `sendChatRate`
447
-
448
- This method will send user feedback for current chat, when chat is finished.
449
-
450
- Request parameter:
451
-
452
- ```ts
453
- client.sendChatRate({
454
- rating: 5,
455
- feedback: "Very good service",
456
- })
457
- ```
458
-
459
- ### `sendChatSurvey`
460
-
461
- This method will also send user feedbacks, but powerful.
462
-
463
- Request parameter:
464
-
465
- ```ts
466
- interface {
467
- [question_id: string]: number | string;
468
- }
469
- ```
470
-
471
- 1. you will need to get the survey questions:
472
-
473
- ```ts
474
- const questions = await client.getChatSurvey()
475
- /* response:
476
- {
477
- sign_off_display_text: "some text",
478
- questions: [
479
- {
480
- id: number,
481
- type: string,
482
- display_text: string,
483
- valid_answers?
484
- }
485
- ]
486
- }
487
- */
488
- ```
489
-
490
- 2. answer each questions, and call `sendChatSurvey`:
491
-
492
- ```ts
493
- client.sendChatSurvey({
494
- 123: "a",
495
- 231: "b",
496
- })
497
- ```
498
-
499
- ### `createEmail`
500
-
501
- This method will send an email:
502
-
503
- Request parameter:
504
-
505
- ```ts
506
- interface EmailRequest {
507
- name?: string;
508
- email: string;
509
- content: string;
510
- lang?: string;
511
- files?: File[];
512
- recaptcha?: string;
513
- }
514
-
515
- (menuId: number | string, data: EmailRequest)
516
- ```
517
-
518
- ```ts
519
- client.createEmail(123, {
520
- lang: "en",
521
- name: "User name",
522
- email: "name@example.com",
523
- content: "description of the question",
524
- files: input.files,
525
- })
526
- ```
527
-
528
- ## Events
529
-
530
- It is possible to add and remove event listners via `.on` and `.off`
531
- methods:
532
-
533
- ```js
534
- const handleReady = () => {
535
- console.log("**** client is ready")
536
- }
537
-
538
- client.on("ready", handleReady)
539
-
540
- // client.off("ready", handleReady)
541
- ```
542
-
543
- Here lists all the available events:
544
-
545
- ### ready
546
-
547
- Emit when client is ready for communication.
548
-
549
- ```js
550
- client.on("ready", () => {
551
- })
552
- ```
553
-
554
- ### authenticated
555
-
556
- Emit when client has authenticated with the user's token.
557
-
558
- ```js
559
- client.on("authenticated", () => {
560
- })
561
- ```
562
-
563
- ### chat.ongoing
564
-
565
- Emit when there is an ongoing chat.
566
-
567
- ```js
568
- client.on("chat.ongoing", (chat) => {
569
- console.log(chat)
570
- })
571
- ```
572
-
573
- ### chat.updated
574
-
575
- Emit when `chat` instance has updated.
576
-
577
- ```js
578
- client.on("chat.updated", (chat) => {
579
- // the `chat` property on `client` has updated
580
- console.log(chat)
581
- })
582
- ```
583
-
584
- ### chat.message
585
-
586
- Emit when there is a new message.
587
-
588
- ```js
589
- client.on("chat.message", message => {
590
- console.log(message)
591
- })
592
- ```
593
-
594
- The `message` type:
595
-
596
- ```ts
597
- interface MessageResponse {
598
- $index: number;
599
- $sid: string;
600
- $timestamp: Date;
601
- $userType: string;
602
- $userId: number;
603
- type: string;
604
- content?: string;
605
- event?: string;
606
- file?: File;
607
-
608
- // extra parameters
609
- [key: string]: unknown;
610
- }
611
- ```
612
-
613
- ### chat.memberJoined
614
-
615
- Emit when a new member joined the conversation.
616
-
617
- ```js
618
- client.on("chat.memberJoined", (identity) => {
619
- console.log(identity)
620
- })
621
- ```
622
-
623
- ### chat.memberLeft
624
-
625
- Emit when a member left the conversation.
626
-
627
- ```js
628
- client.on("chat.memberLeft", (identity) => {
629
- console.log(identity)
630
- })
631
- ```
632
-
633
- ### chat.typingStarted
634
-
635
- Emit when a member started typing.
636
-
637
- ```js
638
- client.on("chat.typingStarted", (identity) => {
639
- console.log(identity)
640
- })
641
- ```
642
-
643
- ### chat.typingEnded
644
-
645
- Emit when a member ended typing.
646
-
647
- ```js
648
- client.on("chat.typingEnded", (identity) => {
649
- console.log(identity)
650
- })
651
- ```
652
-
653
- ### chat.connected
654
-
655
- Emit when the chat is connected with conversation provider.
656
-
657
- ```js
658
- client.on("chat.connected", () => {
659
- console.log("connected")
660
- })
661
- ```
662
-
663
- ### chat.disconnected
664
-
665
- Emit when the chat is disconnected with conversation provider.
666
-
667
- ```js
668
- client.on("chat.disconnected", () => {
669
- console.log("disconnected")
670
- })
671
- ```
672
-
673
- ### chat.dismissed
674
-
675
- Emit when the chat's status is changed to `dismissed`.
676
-
677
- ```js
678
- client.on("chat.dismissed", () => {
679
- console.log("dismissed")
680
- })
681
- ```
682
-
683
- ### chat.timeout
684
-
685
- Emit when the chat is ended, and the reason is "timeout".
686
-
687
- ```js
688
- client.on("chat.timeout", () => {
689
- console.log("timeout")
690
- })
691
- ```
692
-
693
- ### chat.ended
694
-
695
- Emit when the chat is ended.
696
-
697
- ```js
698
- client.on("chat.ended", () => {
699
- console.log("ended")
700
- })
701
- ```
702
-
703
- ### chat.destroyed
704
-
705
- Emit when `destroyChat` is called.
706
-
707
- ```js
708
- client.on("chat.destroyed", () => {
709
- console.log("destroyed")
710
- })
711
- ```
712
-
713
- ### cobrowse.request
714
-
715
- Emit when end user or agent request to start cobrowse.
716
-
717
- ```js
718
- client.on("cobrowse.request", { from } => {
719
- console.log("request by", from)
720
- })
721
- ```
722
-
723
- ### cobrowse.loaded
724
-
725
- When cobrowse session is loaded.
726
-
727
- ```js
728
- client.on("cobrowse.loaded", session => {
729
- console.log("cobrowse session", session)
730
- })
731
- ```
732
-
733
- ### cobrowse.updated
734
-
735
- When cobrowse session is updated.
736
-
737
- ```js
738
- client.on("cobrowse.updated", session => {
739
- console.log("cobrowse session", session)
740
- })
741
- ```
742
-
743
- ### cobrowse.ended
744
-
745
- When cobrowse session is ended.
746
-
747
- ```js
748
- client.on("cobrowse.ended", session => {
749
- console.log("cobrowse session", session)
750
- })
751
- ```
752
-
753
- ## Cobrowse
754
-
755
- Headless WebSDK has built-in integration with Screen Share. It has a simple UI without
756
- CSS, developers SHOULD add style for it.
757
-
758
- The default template is:
759
-
760
- ```html
761
- <dialog open class="cobrowse-dialog">
762
- <h1>$title</h1>
763
- <div class="cobrowse-dialog_content">$content</div>
764
- <div class="cobrowse-dialog_footer">
765
- <button class="cobrowse-dialog_allow js-cobrowse-allow">$allow</button>
766
- <button class="cobrowse-dialog_deny js-cobrowse-deny">$deny</button>
767
- </div>
768
- </dialog>
769
- ```
770
-
771
- The template will be wrapped by a `<div>` tag:
772
-
773
- ```html
774
- <div class="cobrowse-wrapper">${template}</div>
775
- ```
776
-
777
- You can add CSS style according to the above template's class names.
778
-
779
- ### Custom template
780
-
781
- Developers can also provide a custom template with the `cobrowse.template` option, e.g.
782
-
783
- ```js
784
- const COBROWSE_CONSENT_TEMPLATE = `
785
- <div class="cobrowse">
786
- <div class="cobrowse-title">$title</div>
787
- <div class="cobrowse-content">$content</div>
788
- <div class="cobrowse-footer">
789
- <button class="cobrowse-deny js-cobrowse-deny">$deny</button>
790
- <button class="cobrowse-allow js-cobrowse-allow">$allow</button>
791
- </div>
792
- </div>
793
- `
794
- const client = new Client({
795
- companyId: "YOUR-COMPANY-ID",
796
- tenant: "YOUR-TENANT-NAME",
797
- authenticate: authenticate,
798
- cobrowse: {
799
- template: COBROWSE_CONSENT_TEMPLATE,
800
- ...
801
- },
802
- ...
803
- })
804
- ```
805
-
806
- Variables `$title`, `$content`, `$deny`, and `$allow` will be replaced automatically.
807
-
808
- **Note**: `js-cobrowse-deny` and `js-cobrowse-allow` class names are required.
809
-
810
- We also offer separated templates:
811
-
812
- ```ts
813
- const client = new Client({
814
- companyId: "YOUR-COMPANY-ID",
815
- tenant: "YOUR-TENANT-NAME",
816
- authenticate: authenticate,
817
- cobrowse: {
818
- confirmSessionTemplate: '....',
819
- confirmRemoteControlTemplate: '....',
820
- confirmFullDeviceTemplate: '....',
821
- sessionControlsTemplate: '....',
822
- ...
823
- },
824
- ...
825
- })
826
- ```
827
-
828
- You have to add `js-cobrowse-deny` and `js-cobrowse-allow` class names on buttons for:
829
-
830
- - confirmSessionTemplate
831
- - confirmRemoteControlTemplate
832
- - confirmFullDeviceTemplate
833
-
834
- And `js-cobrowse-end` for: `sessionControlsTemplate`.
835
-
836
- ### Custom messages
837
-
838
- We know `$title`, `$content`, `$deny`, and `$allow` are variables, the default (en) messages
839
- for these variables are:
840
-
841
- ```
842
- {
843
- "confirmSessionTitle": "Screen Share Session Request",
844
- "confirmSessionContent": "Do you want to share your current screen with the agent?",
845
- "endSessionText": "End Screen Share Session",
846
- "confirmRemoteControlTitle": "Remote Access Request",
847
- "confirmRemoteControlContent": "The agent would like to have access to your currently shared screen to further assist you. Do you want to allow this?",
848
- "confirmFullDeviceTitle": "Screen Share Request",
849
- "confirmFullDeviceContent": "Do you want to share your full screen with the agent? The agent will not be able to control anything on the screen.",
850
- "allowText": "Allow",
851
- "denyText": "Deny"
852
- }
853
- ```
854
-
855
- You can customize the message through option `cobrowse.messages`:
856
-
857
- ```ts
858
- const client = new Client({
859
- companyId: "YOUR-COMPANY-ID",
860
- tenant: "YOUR-TENANT-NAME",
861
- authenticate: authenticate,
862
- cobrowse: {
863
- enabled: true,
864
- messages: {
865
- confirmSessionTitle: "...",
866
- confirmSessionContent: "...",
867
- endSessionText: "...",
868
- confirmRemoteControlTitle: "...",
869
- confirmRemoteControlContent: "...",
870
- confirmFullDeviceTitle: "...",
871
- confirmFullDeviceContent: "...",
872
- allowText: "...",
873
- denyText: "...",
874
- }
875
- }
876
- })
877
- ```
28
+ ## Docs
29
+ ### [API/Methods](docs/api.md)
30
+ ### [Authentication](docs/authenticate.md)
31
+ ### [Screen Share](docs/screen-share.md)
32
+ ### [Events](docs/events.md)
33
+ ### [Configuration Options](docs/options.md)