@ujet/websdk-headless 4.22.0 → 4.39.0

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.
Files changed (4) hide show
  1. package/dist/index.d.ts +636 -134
  2. package/dist/index.js +147 -133
  3. package/dist/index.mjs +27426 -20229
  4. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -1,132 +1,3 @@
1
- interface RequestReturn {
2
- headers: Record<string, string>;
3
- data: any;
4
- }
5
- interface LogData {
6
- loglevel: string;
7
- timestamp: string;
8
- application: string;
9
- sdk_version: string;
10
- device_uuid: string;
11
- tenant: string;
12
- company_id: string;
13
- location_url: string;
14
- channel: string;
15
- message: string;
16
- data: any;
17
- tracker_id?: string;
18
- }
19
- interface LogHistoryData {
20
- date: string;
21
- channel: string;
22
- level: string;
23
- args: any[];
24
- }
25
- interface ClientEvent {
26
- name: string;
27
- payload: {
28
- lang: string;
29
- menu_id: number;
30
- [key: string]: unknown;
31
- };
32
- }
33
- interface MessageRequest {
34
- type: string;
35
- content?: string;
36
- [key: string]: unknown;
37
- }
38
- interface ChatRequest {
39
- lang?: string;
40
- trigger_id?: string;
41
- ticket_id?: string;
42
- email?: string;
43
- greeting?: string;
44
- cobrowsable?: boolean;
45
- custom_data?: {
46
- signed?: string;
47
- unsigned?: Record<string, any>;
48
- };
49
- }
50
- interface EscalateRequest {
51
- force_escalate: boolean;
52
- menu_id: number;
53
- lang: string;
54
- }
55
- interface CobrowseRequest {
56
- code: string;
57
- from: string;
58
- nonce: string;
59
- }
60
- interface RateRequest {
61
- rating: number;
62
- feedback: string;
63
- }
64
- interface SurveyAnswers {
65
- [id: string]: number | string;
66
- }
67
- interface ChatEndUserEventRequest {
68
- event: {
69
- name: string;
70
- payload: Record<string, string>;
71
- };
72
- end_user_name?: string;
73
- }
74
- interface CallRequest {
75
- phone_number: string;
76
- lang?: string;
77
- scheduled_at?: string;
78
- ticket_id?: string;
79
- email?: string;
80
- recording_permission?: 'recording_permission_not_asked' | 'recording_permission_granted' | 'recording_permission_denied';
81
- custom_data?: {
82
- signed?: string;
83
- unsigned?: Record<string, any>;
84
- };
85
- reschedule_call_id?: number;
86
- use_advanced_call_scheduling?: boolean;
87
- }
88
- interface EmailRequest {
89
- name?: string;
90
- email: string;
91
- content: string;
92
- lang?: string;
93
- files?: File[];
94
- recaptcha?: string;
95
- }
96
- interface FormData {
97
- signature: string;
98
- data: {
99
- smart_action_id: number;
100
- id: number;
101
- uri: string;
102
- };
103
- }
104
- interface ChatMessageRequest {
105
- message: {
106
- content: string;
107
- timestamp: string;
108
- };
109
- }
110
- interface CheckInVisibilityStateRequest {
111
- widget_minimized?: boolean;
112
- tab_inactive?: boolean;
113
- }
114
- interface CheckInModalStateRequest {
115
- modal_type: 'check_in';
116
- }
117
- interface GetTimeSlotsRequest {
118
- lang?: string;
119
- rescheduleCallId?: number;
120
- useAdvancedCallScheduling?: boolean;
121
- }
122
- interface CustomFormPayload {
123
- smart_action_id: number;
124
- form_response: {
125
- question_id: number;
126
- value: string | string[] | boolean;
127
- }[];
128
- }
129
-
130
1
  declare enum PostSessionStatus {
131
2
  WAITING = "waiting",
132
3
  READY = "ready",
@@ -141,6 +12,20 @@ declare enum CheckInStatus {
141
12
  SKIPPED = "skipped",
142
13
  TIMED_OUT = "timed_out"
143
14
  }
15
+ declare enum ProviderType {
16
+ UJET = "ujet_conversations",
17
+ TWILIO = "twilio_conversations",
18
+ NEXMO = "nexmo_conversations",
19
+ MOCK = "mock"
20
+ }
21
+
22
+ /**
23
+ * Stable identifiers for the channel.type values returned in MenuChannel.
24
+ * Use these constants rather than raw string literals so renames are safe.
25
+ */
26
+ declare enum ChannelType {
27
+ INBOUND_CALL = "inbound_call"
28
+ }
144
29
 
145
30
  interface LanguageOption {
146
31
  lang: string;
@@ -166,6 +51,7 @@ interface MenuChannel {
166
51
  type: string;
167
52
  menu_id: number;
168
53
  collect_email: boolean;
54
+ recording_option?: RecordingOption;
169
55
  deflected?: boolean;
170
56
  deflection_type?: string;
171
57
  [key: string]: unknown;
@@ -426,6 +312,201 @@ interface ServerAuthResponse {
426
312
  interface FeatureFlagsResponse {
427
313
  'advanced-call-scheduling': boolean;
428
314
  'consumer-agent-pdf'?: boolean;
315
+ 'web-sdk-instant-voice'?: boolean;
316
+ }
317
+ type RecordingPermission = 'recording_permission_not_asked' | 'recording_permission_granted' | 'recording_permission_denied';
318
+ type RecordingOption = 'record_never' | 'record_always' | 'record_ask_user';
319
+ type ServerVoiceCallStatus = 'scheduled' | 'queued' | 'assigned' | 'connecting' | 'connected' | 'va_assigned' | 'va_connected' | 'reconnecting' | 'switching' | 'voicemail' | 'finished' | 'failed' | 'recovered' | 'canceled' | 'timeout';
320
+ type VoiceCallStatus = 'idle' | 'queued' | 'connecting' | 'connected' | 'interrupted' | 'ended' | 'error';
321
+ /** The set of smart-action types the server can request. */
322
+ type SmartActionType = 'text' | 'verification' | 'photo' | 'screenshot' | 'video' | 'cobrowse';
323
+ /**
324
+ * Media smart-action subtypes — the three `SmartActionType` values that
325
+ * route through `client.voiceCall.uploadMediaForSmartAction` (versus text /
326
+ * verification / cobrowse). Exported so consumers passing the media type
327
+ * along — for example dialog components that branch on the smart action —
328
+ * can use the union without re-declaring it.
329
+ */
330
+ type SmartActionMediaType = 'photo' | 'screenshot' | 'video';
331
+ interface SmartActionResponse {
332
+ id: number;
333
+ type: SmartActionType;
334
+ sub_type?: string;
335
+ status: string;
336
+ number_of_photos?: number | null;
337
+ }
338
+ interface VoiceCallResponse {
339
+ id: number;
340
+ status: ServerVoiceCallStatus;
341
+ type: 'WebInboundCall';
342
+ features: string[];
343
+ region?: string;
344
+ created_at: string;
345
+ fail_reason: string | null;
346
+ csat_settings: {
347
+ enabled: boolean;
348
+ post_in_crm: boolean;
349
+ feedback_enabled: boolean;
350
+ time_to_leave_feedback: number;
351
+ webhook_url: string | null;
352
+ };
353
+ recording_permitted: boolean;
354
+ survey_enabled: boolean;
355
+ agent: HumanAgent | null;
356
+ virtual_agent: VirtualAgent | null;
357
+ participants: HumanAgent[];
358
+ smart_actions?: SmartActionResponse[];
359
+ recording_permission?: RecordingPermission;
360
+ recording_option?: RecordingOption;
361
+ wait_estimation?: number;
362
+ lang: string;
363
+ menus: {
364
+ id: number;
365
+ name: string;
366
+ }[];
367
+ selected_menu: {
368
+ id: number;
369
+ name: string;
370
+ };
371
+ custom_data?: Record<string, unknown>;
372
+ }
373
+
374
+ interface RequestReturn {
375
+ headers: Record<string, string>;
376
+ data: any;
377
+ }
378
+ interface LogData {
379
+ loglevel: string;
380
+ timestamp: string;
381
+ application: string;
382
+ sdk_version: string;
383
+ device_uuid: string;
384
+ tenant: string;
385
+ company_id: string;
386
+ location_url: string;
387
+ channel: string;
388
+ message: string;
389
+ data: any;
390
+ tracker_id?: string;
391
+ }
392
+ interface LogHistoryData {
393
+ date: string;
394
+ channel: string;
395
+ level: string;
396
+ args: any[];
397
+ }
398
+ interface ClientEvent {
399
+ name: string;
400
+ payload: {
401
+ lang: string;
402
+ menu_id: number;
403
+ [key: string]: unknown;
404
+ };
405
+ }
406
+ interface MessageRequest {
407
+ type: string;
408
+ content?: string;
409
+ [key: string]: unknown;
410
+ }
411
+ interface ChatRequest {
412
+ lang?: string;
413
+ trigger_id?: string;
414
+ ticket_id?: string;
415
+ email?: string;
416
+ greeting?: string;
417
+ cobrowsable?: boolean;
418
+ custom_data?: {
419
+ signed?: string;
420
+ unsigned?: Record<string, any>;
421
+ };
422
+ }
423
+ interface EscalateRequest {
424
+ force_escalate: boolean;
425
+ menu_id: number;
426
+ lang: string;
427
+ }
428
+ interface CobrowseRequest {
429
+ code: string;
430
+ from: string;
431
+ nonce: string;
432
+ }
433
+ interface RateRequest {
434
+ rating: number;
435
+ feedback: string;
436
+ }
437
+ interface SurveyAnswers {
438
+ [id: string]: number | string;
439
+ }
440
+ interface ChatEndUserEventRequest {
441
+ event: {
442
+ name: string;
443
+ payload: Record<string, string>;
444
+ };
445
+ end_user_name?: string;
446
+ }
447
+ interface CallRequest {
448
+ phone_number: string;
449
+ lang?: string;
450
+ scheduled_at?: string;
451
+ ticket_id?: string;
452
+ email?: string;
453
+ recording_permission?: RecordingPermission;
454
+ custom_data?: {
455
+ signed?: string;
456
+ unsigned?: Record<string, any>;
457
+ };
458
+ reschedule_call_id?: number;
459
+ }
460
+ interface EmailRequest {
461
+ name?: string;
462
+ email: string;
463
+ content: string;
464
+ lang?: string;
465
+ files?: File[];
466
+ recaptcha?: string;
467
+ }
468
+ interface FormData {
469
+ signature: string;
470
+ data: {
471
+ smart_action_id: number;
472
+ id: number;
473
+ uri: string;
474
+ };
475
+ }
476
+ interface ChatMessageRequest {
477
+ message: {
478
+ content: string;
479
+ timestamp: string;
480
+ };
481
+ }
482
+ interface CheckInVisibilityStateRequest {
483
+ widget_minimized?: boolean;
484
+ tab_inactive?: boolean;
485
+ }
486
+ interface CheckInModalStateRequest {
487
+ modal_type: 'check_in';
488
+ }
489
+ interface GetTimeSlotsRequest {
490
+ lang?: string;
491
+ rescheduleCallId?: number;
492
+ }
493
+ interface CustomFormPayload {
494
+ smart_action_id: number;
495
+ form_response: {
496
+ question_id: number;
497
+ value: string | string[] | boolean;
498
+ }[];
499
+ }
500
+ interface VoiceCallRequest {
501
+ lang?: string;
502
+ ticket_id?: string;
503
+ email?: string;
504
+ recording_permission?: RecordingPermission;
505
+ custom_data?: {
506
+ signed?: string;
507
+ unsigned?: Record<string, any>;
508
+ };
509
+ cobrowsable?: boolean;
429
510
  }
430
511
 
431
512
  type RequestMethod = (url: string, options: RequestInit | Record<string, any>) => Promise<RequestReturn>;
@@ -556,6 +637,10 @@ declare abstract class BaseProvider {
556
637
  }
557
638
  declare function addProviderType(Provider: typeof BaseProvider): void;
558
639
 
640
+ interface ChatHooks {
641
+ leaveChat?: () => Promise<void>;
642
+ leaveChatBeacon?: () => void;
643
+ }
559
644
  declare class Chat {
560
645
  private provider;
561
646
  private store;
@@ -566,8 +651,10 @@ declare class Chat {
566
651
  inEscalation: boolean;
567
652
  private events;
568
653
  private cachedFiles;
569
- constructor(state: ChatResponse, issueChatToken: IssueChatTokenMethod);
570
- _setGlobalEvents(events: EventManager, fetchServerMessage: GetServerMessage): void;
654
+ private hooks;
655
+ private leaveSent;
656
+ private beaconAttempted;
657
+ constructor(state: ChatResponse, issueChatToken: IssueChatTokenMethod, hooks?: ChatHooks);
571
658
  get id(): number;
572
659
  get menuId(): number;
573
660
  get channelId(): string;
@@ -603,6 +690,9 @@ declare class Chat {
603
690
  off(eventName: string, handler: EventHandler): void;
604
691
  connect(): Promise<boolean>;
605
692
  disconnect(): Promise<void>;
693
+ private sendLeave;
694
+ leaveBeacon(): void;
695
+ resetBeaconState(): void;
606
696
  sendMessage(message: MessageRequest, file?: File): Promise<number>;
607
697
  preview(text: string): Promise<void>;
608
698
  fetchMessages(): Promise<MessageResponse[]>;
@@ -611,7 +701,6 @@ declare class Chat {
611
701
  saveMedia(index: number, file: File): void;
612
702
  destroy(): Promise<void>;
613
703
  clearMediaStore(): Promise<void>;
614
- _handleChatEndedEvent(message: MessageResponse): void;
615
704
  private triggerEvent;
616
705
  private registerProviderEvents;
617
706
  private registerMessageEvents;
@@ -639,6 +728,229 @@ declare class MediaStore {
639
728
  clear(): Promise<void>;
640
729
  }
641
730
 
731
+ /** Return type of `VoiceCall.feedbackType` — which post-call UX (if any) to show. */
732
+ type VoiceFeedbackType = 'survey' | 'rate' | 'none';
733
+ declare class VoiceCall {
734
+ /** Backing field for the read-only `state` accessor; mutated by the SDK. */
735
+ protected _state: VoiceCallResponse;
736
+ private _publicState;
737
+ private setInternalState;
738
+ /**
739
+ * Server-side call state. Exposed as `Readonly` so consumers cannot mutate
740
+ * top-level fields. Raw `status` is omitted from this view — use
741
+ * `call.status` for the curated 7-state form, or `call.serverStatus()` to
742
+ * read the raw `ServerVoiceCallStatus` explicitly.
743
+ */
744
+ get state(): Readonly<Omit<VoiceCallResponse, 'status'>>;
745
+ /**
746
+ * Raw server status escape hatch. Prefer `call.status` (curated). The raw
747
+ * value is intentionally exposed so consumers can test against the full
748
+ * `ServerVoiceCallStatus` union when curated `VoiceCallStatus` is too coarse.
749
+ */
750
+ serverStatus(): ServerVoiceCallStatus;
751
+ private keepAlive;
752
+ private stateMachine;
753
+ private handledSmartActionIds;
754
+ private smartActionQueue;
755
+ private get currentSmartActionId();
756
+ private currentCobrowseSmartActionId;
757
+ private recordingPermissionAsked;
758
+ private speakerOn;
759
+ private cobrowseStarter;
760
+ private resolveStartedAtFromState;
761
+ private setStatus;
762
+ private teardownActiveResources;
763
+ /** Server-assigned voice call id. */
764
+ get id(): number;
765
+ /** Curated lifecycle status (mapped from raw server status). */
766
+ get status(): VoiceCallStatus;
767
+ /** Current peer (human or virtual). Human takes priority once escalated. */
768
+ get agent(): HumanAgent | VirtualAgent | null;
769
+ /** Seconds elapsed since the media leg connected (server-anchored). */
770
+ get duration(): number;
771
+ /**
772
+ * Post-call feedback type configured for this call.
773
+ *
774
+ * Precedence: `'survey'` > `'rate'` > `'none'`. If both `survey_enabled`
775
+ * and `csat_settings.enabled` are true on the call, survey wins (the
776
+ * customer-configured questionnaire is richer than a numeric rating).
777
+ * `'none'` means the consumer should skip any post-call UX and return
778
+ * straight to the launcher.
779
+ */
780
+ get feedbackType(): VoiceFeedbackType;
781
+ /** Toggle mute on the local microphone. Idempotent. */
782
+ mute(on: boolean): void;
783
+ /** True when the local microphone is muted. */
784
+ isMuted(): boolean;
785
+ /**
786
+ * Returns the remote audio MediaStream (human agent or virtual agent).
787
+ * Null after the call ends or before media is connected.
788
+ */
789
+ getRemoteAudioStream(): MediaStream | null;
790
+ /**
791
+ * True when the runtime can programmatically switch the audio output (e.g.
792
+ * loudspeaker vs earpiece). iOS Safari returns false; consumers should hide
793
+ * the speaker toggle UI when this is false.
794
+ */
795
+ isSpeakerSupported(): boolean;
796
+ /** True when the call audio is currently routed to a loudspeaker output. */
797
+ isSpeakerOn(): boolean;
798
+ /**
799
+ * Switch the audio output between loudspeaker (true) and the default
800
+ * earpiece/system output (false). On platforms where output-device selection
801
+ * is not supported, only the internal flag is updated (visual-only toggle).
802
+ *
803
+ * @throws {ProviderError} when `on=true` but no loudspeaker output device is
804
+ * available on a platform that supports output-device selection.
805
+ */
806
+ setSpeakerOn(on: boolean): Promise<void>;
807
+ /** Confirm the recording-consent prompt (server records the call). */
808
+ grantRecording(): Promise<void>;
809
+ /** Decline the recording-consent prompt (server skips recording). */
810
+ denyRecording(): Promise<void>;
811
+ /**
812
+ * Generate a cobrowse code so an agent can join the user's screen for this
813
+ * voice call. Throws if cobrowse is not enabled on the Client (see the
814
+ * `cobrowse` option).
815
+ */
816
+ startCobrowse(lang?: string, from?: string): Promise<string>;
817
+ /** Submit a text response to an agent-pushed text SmartAction. */
818
+ submitTextSmartAction(smartActionId: number, text: string): Promise<void>;
819
+ /** Confirm an agent-pushed verification SmartAction (user said yes). */
820
+ confirmVerificationSmartAction(smartActionId: number): Promise<void>;
821
+ /** Cancel any active SmartAction (user dismissed the dialog). */
822
+ cancelSmartAction(smartActionId: number): Promise<void>;
823
+ /** Upload media files (photo / screenshot / video) for a SmartAction. */
824
+ uploadMediaForSmartAction(smartActionId: number, files: File[], type: 'photo' | 'screenshot' | 'video'): Promise<void>;
825
+ protected registerProviderEvents(): void;
826
+ protected fetchAndUpdateState(): Promise<void>;
827
+ private handleProviderMessage;
828
+ private handleSmartActionRequested;
829
+ private handleSmartActionResolved;
830
+ private handleStatusChanged;
831
+ private sendProviderMessage;
832
+ private markSmartActionHandled;
833
+ private resolveSmartAction;
834
+ }
835
+
836
+ /** Extract a human-readable message from an `unknown` caught value. */
837
+ declare const getErrorMessage: (err: unknown) => string;
838
+ /** Cross-realm-safe fallback for `err instanceof VoiceCallError` checks. */
839
+ declare const hasErrorCode: (err: unknown, code: VoiceErrorCode) => boolean;
840
+ /** Extract an HTTP-style numeric `status` from an `unknown` caught value. */
841
+ declare const getErrorStatus: (err: unknown) => number | undefined;
842
+ /** Base class for all voice-related errors. Carries a stable string `code`. */
843
+ declare class VoiceCallError extends Error {
844
+ readonly code: VoiceErrorCode;
845
+ constructor(message: string, code: VoiceErrorCode, cause?: unknown);
846
+ }
847
+ /** End user already has a call in progress on this device. */
848
+ declare class CallInProgressError extends VoiceCallError {
849
+ static readonly CODE = "CALL_IN_PROGRESS";
850
+ constructor(message?: string);
851
+ }
852
+ /** Inbound voice channel is disabled for this menu. */
853
+ declare class InboundDisabledError extends VoiceCallError {
854
+ static readonly CODE = "INBOUND_DISABLED";
855
+ constructor(message?: string);
856
+ }
857
+ /** Tenant is currently outside its configured operation hours. */
858
+ declare class OperationHoursError extends VoiceCallError {
859
+ static readonly CODE = "OPERATION_HOURS";
860
+ constructor(message?: string);
861
+ }
862
+ /** Inbound voice feature flag is off for this tenant. */
863
+ declare class FeatureNotEnabledError extends VoiceCallError {
864
+ static readonly CODE = "FEATURE_NOT_ENABLED";
865
+ constructor(message?: string);
866
+ }
867
+ /** Browser denied microphone access (getUserMedia rejection). */
868
+ declare class MicPermissionDeniedError extends VoiceCallError {
869
+ static readonly CODE = "MIC_PERMISSION_DENIED";
870
+ constructor(message?: string);
871
+ }
872
+ /** Caller invoked a method that requires an active voice call but none exists. */
873
+ declare class NoActiveVoiceCallError extends VoiceCallError {
874
+ static readonly CODE = "NO_ACTIVE_VOICE_CALL";
875
+ constructor(message?: string);
876
+ }
877
+ /** Another tab already holds the voice tab lock. */
878
+ declare class AnotherTabVoiceCallError extends VoiceCallError {
879
+ static readonly CODE = "ANOTHER_TAB_VOICE_CALL";
880
+ constructor(message?: string);
881
+ }
882
+ /** Underlying voice provider (e.g., Twilio Device/Call) failed. */
883
+ declare class ProviderError extends VoiceCallError {
884
+ static readonly CODE = "PROVIDER_ERROR";
885
+ constructor(message: string, cause?: unknown);
886
+ }
887
+ /** Smart action submit / cancel / update / upload failed (server error or missing client method). */
888
+ declare class SmartActionError extends VoiceCallError {
889
+ static readonly CODE = "SMART_ACTION_ERROR";
890
+ /** Server message when the agent ends a smart action before the user responds. */
891
+ static readonly ENDED_MESSAGE = "smart action is already ended";
892
+ constructor(message: string, cause?: unknown);
893
+ /** True when the underlying failure was the agent-ended-already case. */
894
+ get isAlreadyEnded(): boolean;
895
+ }
896
+ /** Unrecognized voice subsystem failure (network timeout, transient server error). */
897
+ declare class UnknownVoiceError extends VoiceCallError {
898
+ static readonly CODE = "UNKNOWN_VOICE_ERROR";
899
+ constructor(message: string, cause?: unknown);
900
+ }
901
+ /**
902
+ * True when the error indicates the call cannot start now due to tenant /
903
+ * menu / company / concurrency constraints — outside operation hours,
904
+ * inbound disabled, feature flag off, or another call in progress.
905
+ * MenuFoot uses this to show an after-hours message instead of an error UI.
906
+ */
907
+ declare const isAfterHoursError: (err: unknown) => boolean;
908
+ /** Union of all stable error codes thrown by the voice subsystem. */
909
+ type VoiceErrorCode = typeof CallInProgressError.CODE | typeof InboundDisabledError.CODE | typeof OperationHoursError.CODE | typeof FeatureNotEnabledError.CODE | typeof MicPermissionDeniedError.CODE | typeof NoActiveVoiceCallError.CODE | typeof AnotherTabVoiceCallError.CODE | typeof ProviderError.CODE | typeof SmartActionError.CODE | typeof UnknownVoiceError.CODE;
910
+
911
+ interface VoiceStatusChangedEvent {
912
+ id: number;
913
+ status: VoiceCallStatus;
914
+ prevStatus?: VoiceCallStatus;
915
+ }
916
+ interface VoiceErrorEvent {
917
+ id: number;
918
+ error: VoiceCallError;
919
+ }
920
+ /** Emitted on a non-cobrowse smart action request. `smartAction.type` is never 'cobrowse'. */
921
+ interface VoiceSmartActionRequestedEvent {
922
+ smartAction: Readonly<SmartActionResponse & {
923
+ type: Exclude<SmartActionType, 'cobrowse'>;
924
+ }>;
925
+ }
926
+ interface VoiceSmartActionResolvedEvent {
927
+ smartActionId: number;
928
+ }
929
+ /** Emitted on a cobrowse smart action request. `smartAction.type` is always 'cobrowse'. */
930
+ interface VoiceCobrowseRequestedEvent {
931
+ smartAction: Readonly<SmartActionResponse & {
932
+ type: Extract<SmartActionType, 'cobrowse'>;
933
+ }>;
934
+ }
935
+ interface VoiceCobrowseResolvedEvent {
936
+ smartActionId: number;
937
+ }
938
+ interface VoiceRecordingPermissionRequiredEvent {
939
+ id: number;
940
+ }
941
+
942
+ declare const VOICE_EVENTS: {
943
+ readonly STATUS_CHANGED: "voice.statusChanged";
944
+ readonly RECONNECTING: "voice.reconnecting";
945
+ readonly RECONNECTED: "voice.reconnected";
946
+ readonly ERROR: "voice.error";
947
+ readonly SMART_ACTION_REQUESTED: "voice.smartActionRequested";
948
+ readonly SMART_ACTION_RESOLVED: "voice.smartActionResolved";
949
+ readonly COBROWSE_REQUESTED: "voice.cobrowseRequested";
950
+ readonly COBROWSE_RESOLVED: "voice.cobrowseResolved";
951
+ readonly RECORDING_PERMISSION_REQUIRED: "voice.recordingPermissionRequired";
952
+ };
953
+
642
954
  declare class Client {
643
955
  VERSION: string;
644
956
  options: ClientOption;
@@ -648,14 +960,42 @@ declare class Client {
648
960
  request: RequestMethod;
649
961
  chat: Chat;
650
962
  private _cobrowse;
963
+ private _voiceCall;
964
+ private _voiceTabLock;
965
+ private redactionSendQueue;
966
+ private onPageHide?;
967
+ private onPageShow?;
651
968
  constructor(options: ClientOption);
969
+ private registerUnloadHandlers;
970
+ private unregisterUnloadHandlers;
652
971
  get deviceId(): string;
653
972
  get user(): UserProfile;
654
973
  get lang(): string;
655
974
  set lang(lang: string);
656
975
  get cobrowse(): any;
976
+ get cobrowseEnabled(): boolean;
657
977
  destroy(): void;
978
+ private releaseVoiceTabLock;
979
+ /** Voice event payload signatures — overloads for `client.on`/`off`. */
980
+ on(event: typeof VOICE_EVENTS.STATUS_CHANGED, handler: (payload: VoiceStatusChangedEvent) => void): void;
981
+ on(event: typeof VOICE_EVENTS.RECONNECTING, handler: () => void): void;
982
+ on(event: typeof VOICE_EVENTS.RECONNECTED, handler: () => void): void;
983
+ on(event: typeof VOICE_EVENTS.ERROR, handler: (payload: VoiceErrorEvent) => void): void;
984
+ on(event: typeof VOICE_EVENTS.SMART_ACTION_REQUESTED, handler: (payload: VoiceSmartActionRequestedEvent) => void): void;
985
+ on(event: typeof VOICE_EVENTS.SMART_ACTION_RESOLVED, handler: (payload: VoiceSmartActionResolvedEvent) => void): void;
986
+ on(event: typeof VOICE_EVENTS.COBROWSE_REQUESTED, handler: (payload: VoiceCobrowseRequestedEvent) => void): void;
987
+ on(event: typeof VOICE_EVENTS.COBROWSE_RESOLVED, handler: (payload: VoiceCobrowseResolvedEvent) => void): void;
988
+ on(event: typeof VOICE_EVENTS.RECORDING_PERMISSION_REQUIRED, handler: (payload: VoiceRecordingPermissionRequiredEvent) => void): void;
658
989
  on(eventName: string, handler: EventHandler): void;
990
+ off(event: typeof VOICE_EVENTS.STATUS_CHANGED, handler: (payload: VoiceStatusChangedEvent) => void): void;
991
+ off(event: typeof VOICE_EVENTS.RECONNECTING, handler: () => void): void;
992
+ off(event: typeof VOICE_EVENTS.RECONNECTED, handler: () => void): void;
993
+ off(event: typeof VOICE_EVENTS.ERROR, handler: (payload: VoiceErrorEvent) => void): void;
994
+ off(event: typeof VOICE_EVENTS.SMART_ACTION_REQUESTED, handler: (payload: VoiceSmartActionRequestedEvent) => void): void;
995
+ off(event: typeof VOICE_EVENTS.SMART_ACTION_RESOLVED, handler: (payload: VoiceSmartActionResolvedEvent) => void): void;
996
+ off(event: typeof VOICE_EVENTS.COBROWSE_REQUESTED, handler: (payload: VoiceCobrowseRequestedEvent) => void): void;
997
+ off(event: typeof VOICE_EVENTS.COBROWSE_RESOLVED, handler: (payload: VoiceCobrowseResolvedEvent) => void): void;
998
+ off(event: typeof VOICE_EVENTS.RECORDING_PERMISSION_REQUIRED, handler: (payload: VoiceRecordingPermissionRequiredEvent) => void): void;
659
999
  off(eventName: string, handler: EventHandler): void;
660
1000
  getCompany(): Promise<CompanyResponse>;
661
1001
  getFeatureFlags(): Promise<FeatureFlagsResponse>;
@@ -686,6 +1026,59 @@ declare class Client {
686
1026
  finishChat(): Promise<void>;
687
1027
  updatePostSession(postSessionStatus: PostSessionStatus, optInSelection?: boolean): Promise<void>;
688
1028
  destroyChat(): Promise<void>;
1029
+ /** Active voice call instance, or null when no call is in progress. */
1030
+ get voiceCall(): VoiceCall | null;
1031
+ /**
1032
+ * Returns true when localStorage holds a pending refresh-restore entry.
1033
+ * Not cached — invocation is a sync I/O check.
1034
+ */
1035
+ hasStoredVoiceCall(): boolean;
1036
+ /**
1037
+ * Start a new inbound voice call for the given menu.
1038
+ *
1039
+ * @throws CallInProgressError if another voice call is already active in
1040
+ * this session.
1041
+ * @throws MicPermissionDeniedError if the browser denies microphone access.
1042
+ * @throws AnotherTabVoiceCallError if another tab already holds the voice
1043
+ * tab lock.
1044
+ * @throws InboundDisabledError if inbound voice is disabled for the menu.
1045
+ * @throws OperationHoursError if the menu is outside its operation hours.
1046
+ * @throws FeatureNotEnabledError if the company doesn't have the voice
1047
+ * feature enabled.
1048
+ * @throws VoiceCallError (code 'UNKNOWN_VOICE_ERROR') as a generic
1049
+ * fallback for unrecognized server / transient failures.
1050
+ */
1051
+ startVoiceCall(menuId: number | string, options?: VoiceCallRequest): Promise<VoiceCall>;
1052
+ /**
1053
+ * Restore a voice call after a page refresh. Resolves to the call instance
1054
+ * when an active call exists on the server, or null when no recoverable call
1055
+ * is found (no stored entry, or the call has already terminated).
1056
+ *
1057
+ * @throws AnotherTabVoiceCallError if another tab already holds the voice
1058
+ * tab lock.
1059
+ * @throws Network/server errors are propagated; HTTP 404 is treated as
1060
+ * "no recoverable call" and resolves to null.
1061
+ */
1062
+ loadVoiceCall(callId?: number | string): Promise<VoiceCall | null>;
1063
+ /**
1064
+ * End the active call but keep the VoiceCall instance + tab lock alive
1065
+ * so the widget can show post-call UI (rate/survey). For full teardown
1066
+ * including storage cleanup, call destroyVoiceCall().
1067
+ */
1068
+ endVoiceCall(): Promise<void>;
1069
+ /**
1070
+ * Escalate the active VA voice call to a human-agent queue. Server validates
1071
+ * the transition (only valid during a VA-routed call); SDK does not gate.
1072
+ *
1073
+ * @throws NoActiveVoiceCallError if no voice call is active.
1074
+ */
1075
+ escalateVoiceCall(): Promise<void>;
1076
+ /**
1077
+ * Release all resources for the active voice call. Hangs up the call first
1078
+ * if it's still ongoing, then tears down provider, timers, and event
1079
+ * listeners, and clears the localStorage entry.
1080
+ */
1081
+ destroyVoiceCall(): Promise<void>;
689
1082
  getChatDeflection(): Promise<ChatDeflectionResponse | null>;
690
1083
  sendChatTranscripts(emails: string[]): Promise<void>;
691
1084
  downloadChatTranscript(): Promise<GenerateTranscriptResponse>;
@@ -693,6 +1086,24 @@ declare class Client {
693
1086
  getChatSurvey(): Promise<ChatSurveyResponse | null>;
694
1087
  sendChatSurvey(answers: SurveyAnswers): Promise<void>;
695
1088
  sendChatRate(data: RateRequest): Promise<void>;
1089
+ /**
1090
+ * Submit a CSAT rating for the active voice call (feedbackType === 'rate').
1091
+ *
1092
+ * @throws NoActiveVoiceCallError if no voice call is active.
1093
+ */
1094
+ rateVoiceCall(data: RateRequest): Promise<void>;
1095
+ /**
1096
+ * Fetch the post-call survey definition (feedbackType === 'survey').
1097
+ *
1098
+ * @throws NoActiveVoiceCallError if no voice call is active.
1099
+ */
1100
+ getVoiceCallSurvey(): Promise<ChatSurveyResponse | null>;
1101
+ /**
1102
+ * Submit answers to the post-call survey (feedbackType === 'survey').
1103
+ *
1104
+ * @throws NoActiveVoiceCallError if no voice call is active.
1105
+ */
1106
+ submitVoiceCallSurvey(answers: SurveyAnswers): Promise<void>;
696
1107
  escalateChat(data?: EscalateRequest): Promise<void>;
697
1108
  trackChatEscalation(escalationId: number, channel: string): Promise<void>;
698
1109
  trackChatEndUserEvent(data: ChatEndUserEventRequest): Promise<void>;
@@ -718,7 +1129,6 @@ declare class Client {
718
1129
  private updateCheckIn;
719
1130
  private initializeCobrowse;
720
1131
  private registerOngoingChat;
721
- _triggerEvent(eventName: string, data?: any): void;
722
1132
  }
723
1133
 
724
1134
  declare class CircularBuffer<T> {
@@ -758,4 +1168,96 @@ declare const OPTIONS: {
758
1168
  version: string;
759
1169
  };
760
1170
 
761
- export { BaseProvider, type CallApiResponse, type CallRequest, type CallResponse, Chat, type ChatDeflectionResponse, type ChatDocumentItem, type ChatEndUserEventRequest, type ChatHistoryItem, type ChatHistoryResponse, type ChatMessageRequest, type ChatMessageResponse, type ChatRequest, type ChatResponse, type ChatSurveyResponse, type ChatTaskMessageResponse, type CheckInModalStateRequest, type CheckInResponse, CheckInStatus, type CheckInVisibilityStateRequest, Client, type ClientEvent, type ClientOption, type CobrowseMessages, type CobrowseOption, type CobrowseRequest, type CompanyResponse, type ConnectCallback, type ConnectOption, type ConnectRequest, type ConnectResult, type CustomFormPayload, ENVIRONMENT, type EmailRequest, type EmailResponse, type EscalateRequest, type EventHandler, EventManager, type FeatureFlagsResponse, type FileTypeItem, type FormData, type GenerateTranscriptResponse, type GetServerMessage, type GetTimeSlotsRequest, type HumanAgent, type IssueChatTokenMethod, type LanguageOption, type LogData, type LogHistoryData, Logger, type LoggerHandler, MediaStore, type MenuChannel, type MenuItem, type MenuResponse, type MessageRequest, type MessageResponse, OPTIONS, type PdfStatusResponse, PostSessionStatus, type QuestionItem, type RateRequest, type RequestMethod, type RequestReturn, type ServerAuthResponse, type SurveyAnswers, type TokenResponse, type TriggerItem, type TriggerMessage, type UserProfile, VERSION, type VirtualAgent, type WaitTimeResponse, addProviderType };
1171
+ type VoiceProviderMessageType = 'smart_action_requested' | 'smart_action_resolved' | 'recording_permission_required' | 'status_changed' | 'smart_action_notified' | 'smart_action_response' | 'recording_permission';
1172
+
1173
+ type IssueVoiceTokenMethod = () => Promise<{
1174
+ token: string;
1175
+ identity: string;
1176
+ }>;
1177
+ interface VoiceProviderMessage {
1178
+ type: VoiceProviderMessageType;
1179
+ data?: Record<string, unknown>;
1180
+ }
1181
+ declare abstract class BaseVoiceProvider {
1182
+ static type: string;
1183
+ protected events: EventManager;
1184
+ protected state: VoiceCallResponse;
1185
+ protected issueVoiceToken: IssueVoiceTokenMethod;
1186
+ constructor(events: EventManager, state: VoiceCallResponse, issueVoiceToken: IssueVoiceTokenMethod);
1187
+ /**
1188
+ * Dial the carrier and prepare the media leg.
1189
+ *
1190
+ * Contract:
1191
+ * - Resolve only after the transport reaches a state where it can emit
1192
+ * `INTERNAL_VOICE_EVENTS.CONNECTED` (`'voice:internal:connected'`) on its
1193
+ * own. The CONNECTED event is what drives `VoiceCall.status` from
1194
+ * `connecting` to `connected` / `va_connected`; without it, the call
1195
+ * stays in pre-connect state forever.
1196
+ * - Emit CONNECTED no later than the carrier's handshake completes (Twilio
1197
+ * does this on `Device.connect`'s `accept` event). If your transport
1198
+ * takes longer than a few seconds to reach the bridge, surface progress
1199
+ * via your own status messages — don't delay CONNECTED past actual
1200
+ * media-leg readiness.
1201
+ * - On failure, throw a `ProviderError` (or subclass) so the SDK can route
1202
+ * it through `VOICE_EVENTS.ERROR` with a typed shape.
1203
+ */
1204
+ abstract create(): Promise<void>;
1205
+ /**
1206
+ * Fully tear down provider resources (device, listeners, audio context).
1207
+ * Called once per provider instance; subsequent calls are no-ops.
1208
+ * After destroy(), the provider MUST NOT emit further events.
1209
+ */
1210
+ abstract destroy(): Promise<void>;
1211
+ /**
1212
+ * Toggle the local microphone mute state.
1213
+ *
1214
+ * Contract:
1215
+ * - Idempotent — repeated calls with the same boolean MUST be no-ops. The
1216
+ * SDK and consumers may call `mute(true)` multiple times (focus
1217
+ * restoration, refresh re-apply); do not assume each call flips state.
1218
+ * - Synchronous. The state change MUST be observable via `isMuted()` on
1219
+ * the next event-loop tick.
1220
+ */
1221
+ abstract mute(on: boolean): void;
1222
+ abstract isMuted(): boolean;
1223
+ abstract isOutputSelectionSupported(): boolean;
1224
+ abstract getAvailableOutputDevices(): MediaDeviceInfo[];
1225
+ abstract setOutputDevice(deviceId: string): Promise<void>;
1226
+ /**
1227
+ * Disconnect the active call leg.
1228
+ * MUST emit the internal disconnected event (`'voice:internal:disconnected'`)
1229
+ * before resolving. Idempotent: calling on a non-active provider still emits it.
1230
+ *
1231
+ * @remarks The wire-format string `'voice:internal:disconnected'` IS the
1232
+ * stable contract — provider authors should emit this literal via
1233
+ * `this.events.triggerEvent(...)`. We do not export a named constant for
1234
+ * the SDK-provider boundary; the literal is intentionally the public
1235
+ * contract surface so providers don't take an import dependency on the
1236
+ * SDK's internal event-name module.
1237
+ */
1238
+ abstract hangup(): Promise<void>;
1239
+ getRemoteStream(): MediaStream | null;
1240
+ sendMessage(message: VoiceProviderMessage): string | null;
1241
+ }
1242
+ /**
1243
+ * Concrete (newable) constructor signature for provider implementations.
1244
+ * BaseVoiceProvider is abstract so `typeof BaseVoiceProvider` cannot be `new`-ed directly.
1245
+ *
1246
+ * `type` MUST be a non-empty string — it's the registry key used by
1247
+ * `addVoiceProviderType()` / `getVoiceProviderType()` to dispatch incoming
1248
+ * `voip_provider` values from the server to the right provider class.
1249
+ */
1250
+ type VoiceProviderConstructor = (new (events: EventManager, state: VoiceCallResponse, issueVoiceToken: IssueVoiceTokenMethod) => BaseVoiceProvider) & {
1251
+ type: string;
1252
+ };
1253
+ declare const addVoiceProviderType: (Provider: VoiceProviderConstructor) => void;
1254
+ declare const getVoiceProviderType: (type: string) => VoiceProviderConstructor | undefined;
1255
+
1256
+ declare const COBROWSE_EVENTS: {
1257
+ readonly LOADED: "cobrowse.loaded";
1258
+ readonly UPDATED: "cobrowse.updated";
1259
+ readonly ENDED: "cobrowse.ended";
1260
+ };
1261
+ type CobrowseEvent = (typeof COBROWSE_EVENTS)[keyof typeof COBROWSE_EVENTS];
1262
+
1263
+ export { AnotherTabVoiceCallError, BaseProvider, BaseVoiceProvider, COBROWSE_EVENTS, type CallApiResponse, CallInProgressError, type CallRequest, type CallResponse, ChannelType, Chat, type ChatDeflectionResponse, type ChatDocumentItem, type ChatEndUserEventRequest, type ChatHistoryItem, type ChatHistoryResponse, type ChatMessageRequest, type ChatMessageResponse, type ChatRequest, type ChatResponse, type ChatSurveyResponse, type ChatTaskMessageResponse, type CheckInModalStateRequest, type CheckInResponse, CheckInStatus, type CheckInVisibilityStateRequest, Client, type ClientEvent, type ClientOption, type CobrowseEvent, type CobrowseMessages, type CobrowseOption, type CobrowseRequest, type CompanyResponse, type ConnectCallback, type ConnectOption, type ConnectRequest, type ConnectResult, type CustomFormPayload, ENVIRONMENT, type EmailRequest, type EmailResponse, type EscalateRequest, type EventHandler, EventManager, type FeatureFlagsResponse, FeatureNotEnabledError, type FileTypeItem, type FormData, type GenerateTranscriptResponse, type GetServerMessage, type GetTimeSlotsRequest, type HumanAgent, InboundDisabledError, type IssueChatTokenMethod, type IssueVoiceTokenMethod, type LanguageOption, type LogData, type LogHistoryData, Logger, type LoggerHandler, MediaStore, type MenuChannel, type MenuItem, type MenuResponse, type MessageRequest, type MessageResponse, MicPermissionDeniedError, NoActiveVoiceCallError, OPTIONS, OperationHoursError, type PdfStatusResponse, PostSessionStatus, ProviderError, ProviderType, type QuestionItem, type RateRequest, type RecordingOption, type RecordingPermission, type RequestMethod, type RequestReturn, type ServerAuthResponse, type ServerVoiceCallStatus, SmartActionError, type SmartActionMediaType, type SmartActionResponse, type SmartActionType, type SurveyAnswers, type TokenResponse, type TriggerItem, type TriggerMessage, UnknownVoiceError, type UserProfile, VERSION, VOICE_EVENTS, type VirtualAgent, VoiceCall, VoiceCallError, type VoiceCallRequest, type VoiceCallResponse, type VoiceCallStatus, type VoiceCobrowseRequestedEvent, type VoiceCobrowseResolvedEvent, type VoiceErrorCode, type VoiceErrorEvent, type VoiceFeedbackType, type VoiceProviderConstructor, type VoiceProviderMessage, type VoiceProviderMessageType, type VoiceRecordingPermissionRequiredEvent, type VoiceSmartActionRequestedEvent, type VoiceSmartActionResolvedEvent, type VoiceStatusChangedEvent, type WaitTimeResponse, addProviderType, addVoiceProviderType, getErrorMessage, getErrorStatus, getVoiceProviderType, hasErrorCode, isAfterHoursError };