@ujet/websdk-headless 3.44.2 → 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.
package/dist/index.d.ts CHANGED
@@ -1,119 +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
- version: string;
10
- device: 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 ClientEvent {
20
- name: string;
21
- payload: {
22
- lang: string;
23
- menu_id: number;
24
- [key: string]: unknown;
25
- };
26
- }
27
- interface MessageRequest {
28
- type: string;
29
- content?: string;
30
- [key: string]: unknown;
31
- }
32
- interface ChatRequest {
33
- lang?: string;
34
- trigger_id?: string;
35
- ticket_id?: string;
36
- email?: string;
37
- greeting?: string;
38
- cobrowsable?: boolean;
39
- custom_data?: {
40
- signed?: string;
41
- unsigned?: Record<string, any>;
42
- };
43
- }
44
- interface EscalateRequest {
45
- force_escalate: boolean;
46
- menu_id: number;
47
- lang: string;
48
- }
49
- interface CobrowseRequest {
50
- code: string;
51
- from: string;
52
- nonce: string;
53
- }
54
- interface RateRequest {
55
- rating: number;
56
- feedback: string;
57
- }
58
- interface SurveyAnswers {
59
- [id: string]: number | string;
60
- }
61
- interface ChatEndUserEventRequest {
62
- event: {
63
- name: string;
64
- payload: Record<string, string>;
65
- };
66
- end_user_name?: string;
67
- }
68
- interface CallRequest {
69
- phone_number: string;
70
- lang?: string;
71
- scheduled_at?: string;
72
- ticket_id?: string;
73
- email?: string;
74
- recording_permission?: 'recording_permission_not_asked' | 'recording_permission_granted' | 'recording_permission_denied';
75
- custom_data?: {
76
- signed?: string;
77
- unsigned?: Record<string, any>;
78
- };
79
- }
80
- interface EmailRequest {
81
- name?: string;
82
- email: string;
83
- content: string;
84
- lang?: string;
85
- files?: File[];
86
- recaptcha?: string;
87
- }
88
- interface FormData {
89
- signature: string;
90
- data: {
91
- smart_action_id: number;
92
- id: number;
93
- uri: string;
94
- };
95
- }
96
- interface ChatMessageRequest {
97
- message: {
98
- content: string;
99
- timestamp: string;
100
- };
101
- }
102
- interface CheckInVisibilityStateRequest {
103
- widget_minimized?: boolean;
104
- tab_inactive?: boolean;
105
- }
106
- interface CheckInModalStateRequest {
107
- modal_type: 'check_in';
108
- }
109
- interface CustomFormPayload {
110
- smart_action_id: number;
111
- form_response: {
112
- question_id: number;
113
- value: string | string[] | boolean;
114
- }[];
115
- }
116
-
117
1
  declare enum PostSessionStatus {
118
2
  WAITING = "waiting",
119
3
  READY = "ready",
@@ -128,6 +12,20 @@ declare enum CheckInStatus {
128
12
  SKIPPED = "skipped",
129
13
  TIMED_OUT = "timed_out"
130
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
+ }
131
29
 
132
30
  interface LanguageOption {
133
31
  lang: string;
@@ -153,6 +51,7 @@ interface MenuChannel {
153
51
  type: string;
154
52
  menu_id: number;
155
53
  collect_email: boolean;
54
+ recording_option?: RecordingOption;
156
55
  deflected?: boolean;
157
56
  deflection_type?: string;
158
57
  [key: string]: unknown;
@@ -230,11 +129,13 @@ interface ChatResponse {
230
129
  post_session_transfer_status?: string;
231
130
  check_in_status?: CheckInStatus;
232
131
  }
233
- interface CallResponse {
132
+ interface CallApiResponse {
234
133
  created_at: string;
235
134
  id: number;
236
135
  lang: string;
237
- menu_id: number;
136
+ selected_menu: {
137
+ id: number;
138
+ };
238
139
  menus: {
239
140
  id: number;
240
141
  name: string;
@@ -245,6 +146,9 @@ interface CallResponse {
245
146
  survey_enabled: boolean;
246
147
  type: string;
247
148
  }
149
+ interface CallResponse extends Omit<CallApiResponse, 'selected_menu'> {
150
+ menu_id: number;
151
+ }
248
152
  interface EmailResponse {
249
153
  attachment_count: number;
250
154
  id: number;
@@ -260,6 +164,10 @@ interface GenerateTranscriptResponse {
260
164
  chat_transcript_id: number;
261
165
  status: string;
262
166
  }
167
+ interface ChatDocumentItem {
168
+ media_id: number;
169
+ url: string;
170
+ }
263
171
  interface MessageResponse {
264
172
  $index: number;
265
173
  $sid: string;
@@ -281,6 +189,7 @@ interface MessageResponse {
281
189
  messages: string[];
282
190
  type: any;
283
191
  };
192
+ title?: string;
284
193
  type: string;
285
194
  unredacted?: string;
286
195
  signature?: string;
@@ -393,6 +302,212 @@ interface ChatMessageResponse {
393
302
  content: string;
394
303
  timestamp: string;
395
304
  }
305
+ interface ServerAuthResponse {
306
+ error?: number;
307
+ message?: any;
308
+ auth_token?: string;
309
+ log_proxy_auth_token?: string;
310
+ log_proxy_url?: string;
311
+ }
312
+ interface FeatureFlagsResponse {
313
+ 'advanced-call-scheduling': boolean;
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;
510
+ }
396
511
 
397
512
  type RequestMethod = (url: string, options: RequestInit | Record<string, any>) => Promise<RequestReturn>;
398
513
  type EventHandler = (data: any) => void;
@@ -425,6 +540,8 @@ interface ConnectOption {
425
540
  lang: string;
426
541
  cobrowse: boolean;
427
542
  bridge: string;
543
+ bridgeOrigin: string;
544
+ modules: string[];
428
545
  }
429
546
  interface ConnectRequest {
430
547
  type: string;
@@ -498,6 +615,11 @@ declare abstract class BaseProvider {
498
615
  events: EventManager;
499
616
  constructor(events: EventManager, state: ChatResponse, issueChatToken: IssueChatTokenMethod);
500
617
  ping(): void;
618
+ /**
619
+ * Cleanup audio resources by removing event listeners.
620
+ * Should be called by subclasses in their destroy() method.
621
+ */
622
+ protected cleanupAudio(): void;
501
623
  on(eventName: string, handler: EventHandler): void;
502
624
  off(eventName: string, handler: EventHandler): void;
503
625
  trackInTask(message: MessageResponse): void;
@@ -515,6 +637,10 @@ declare abstract class BaseProvider {
515
637
  }
516
638
  declare function addProviderType(Provider: typeof BaseProvider): void;
517
639
 
640
+ interface ChatHooks {
641
+ leaveChat?: () => Promise<void>;
642
+ leaveChatBeacon?: () => void;
643
+ }
518
644
  declare class Chat {
519
645
  private provider;
520
646
  private store;
@@ -525,8 +651,10 @@ declare class Chat {
525
651
  inEscalation: boolean;
526
652
  private events;
527
653
  private cachedFiles;
528
- constructor(state: ChatResponse, issueChatToken: IssueChatTokenMethod);
529
- _setGlobalEvents(events: EventManager, fetchServerMessage: GetServerMessage): void;
654
+ private hooks;
655
+ private leaveSent;
656
+ private beaconAttempted;
657
+ constructor(state: ChatResponse, issueChatToken: IssueChatTokenMethod, hooks?: ChatHooks);
530
658
  get id(): number;
531
659
  get menuId(): number;
532
660
  get channelId(): string;
@@ -562,6 +690,9 @@ declare class Chat {
562
690
  off(eventName: string, handler: EventHandler): void;
563
691
  connect(): Promise<boolean>;
564
692
  disconnect(): Promise<void>;
693
+ private sendLeave;
694
+ leaveBeacon(): void;
695
+ resetBeaconState(): void;
565
696
  sendMessage(message: MessageRequest, file?: File): Promise<number>;
566
697
  preview(text: string): Promise<void>;
567
698
  fetchMessages(): Promise<MessageResponse[]>;
@@ -570,7 +701,6 @@ declare class Chat {
570
701
  saveMedia(index: number, file: File): void;
571
702
  destroy(): Promise<void>;
572
703
  clearMediaStore(): Promise<void>;
573
- _handleChatEndedEvent(message: MessageResponse): void;
574
704
  private triggerEvent;
575
705
  private registerProviderEvents;
576
706
  private registerMessageEvents;
@@ -598,6 +728,229 @@ declare class MediaStore {
598
728
  clear(): Promise<void>;
599
729
  }
600
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
+
601
954
  declare class Client {
602
955
  VERSION: string;
603
956
  options: ClientOption;
@@ -607,16 +960,45 @@ declare class Client {
607
960
  request: RequestMethod;
608
961
  chat: Chat;
609
962
  private _cobrowse;
963
+ private _voiceCall;
964
+ private _voiceTabLock;
965
+ private redactionSendQueue;
966
+ private onPageHide?;
967
+ private onPageShow?;
610
968
  constructor(options: ClientOption);
969
+ private registerUnloadHandlers;
970
+ private unregisterUnloadHandlers;
611
971
  get deviceId(): string;
612
972
  get user(): UserProfile;
613
973
  get lang(): string;
614
974
  set lang(lang: string);
615
975
  get cobrowse(): any;
976
+ get cobrowseEnabled(): boolean;
616
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;
617
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;
618
999
  off(eventName: string, handler: EventHandler): void;
619
1000
  getCompany(): Promise<CompanyResponse>;
1001
+ getFeatureFlags(): Promise<FeatureFlagsResponse>;
620
1002
  runTrigger(cb: (trigger: TriggerItem) => void): Promise<void>;
621
1003
  trackClientEvents(events: ClientEvent[]): Promise<void>;
622
1004
  getProhibitedFileTypes(): Promise<FileTypeItem[]>;
@@ -624,7 +1006,12 @@ declare class Client {
624
1006
  getCustomFormData(formId: string): Promise<RequestReturn>;
625
1007
  submitCustomForm(payload: CustomFormPayload): Promise<RequestReturn>;
626
1008
  getAfterHourMessage(lang?: string): Promise<string>;
1009
+ getTimeSlots(menuId: number | string, options?: GetTimeSlotsRequest): Promise<string[]>;
1010
+ /**
1011
+ * @deprecated Use getTimeSlots(menuId, options) instead to avoid parameter ambiguity
1012
+ */
627
1013
  getTimeSlots(menuId: number | string, lang?: string): Promise<string[]>;
1014
+ fetchTimeSlotAvailability(menuId: number | string, lang?: string): Promise<boolean>;
628
1015
  getWaitTimes(menuId: number | string, lang?: string): Promise<WaitTimeResponse | null>;
629
1016
  verifyForm(data: FormData): Promise<boolean>;
630
1017
  createCall(menuId: number | string, data: CallRequest): Promise<CallResponse>;
@@ -635,9 +1022,63 @@ declare class Client {
635
1022
  loadChat(chatId: number | string): Promise<Chat>;
636
1023
  resumeChat(chatId: number | string): Promise<Chat>;
637
1024
  loadOngoingChat(): Promise<Chat | null>;
1025
+ restoreCobrowseSession(): Promise<void>;
638
1026
  finishChat(): Promise<void>;
639
- updatePostSession(postSessionStatus: PostSessionStatus): Promise<void>;
1027
+ updatePostSession(postSessionStatus: PostSessionStatus, optInSelection?: boolean): Promise<void>;
640
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>;
641
1082
  getChatDeflection(): Promise<ChatDeflectionResponse | null>;
642
1083
  sendChatTranscripts(emails: string[]): Promise<void>;
643
1084
  downloadChatTranscript(): Promise<GenerateTranscriptResponse>;
@@ -645,6 +1086,24 @@ declare class Client {
645
1086
  getChatSurvey(): Promise<ChatSurveyResponse | null>;
646
1087
  sendChatSurvey(answers: SurveyAnswers): Promise<void>;
647
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>;
648
1107
  escalateChat(data?: EscalateRequest): Promise<void>;
649
1108
  trackChatEscalation(escalationId: number, channel: string): Promise<void>;
650
1109
  trackChatEndUserEvent(data: ChatEndUserEventRequest): Promise<void>;
@@ -662,23 +1121,41 @@ declare class Client {
662
1121
  notifyCheckInState(data: CheckInVisibilityStateRequest): Promise<void>;
663
1122
  rejoinChat(): Promise<CheckInResponse>;
664
1123
  trackCheckInEvent(): Promise<void>;
1124
+ getLogs(): Promise<{
1125
+ bridgeLogs: LogHistoryData[];
1126
+ rootLogs: LogHistoryData[];
1127
+ }>;
1128
+ printLogs(): Promise<void>;
665
1129
  private updateCheckIn;
666
1130
  private initializeCobrowse;
667
1131
  private registerOngoingChat;
668
- _triggerEvent(eventName: string, data?: any): void;
1132
+ }
1133
+
1134
+ declare class CircularBuffer<T> {
1135
+ private buffer;
1136
+ private writeIndex;
1137
+ private size;
1138
+ private readonly capacity;
1139
+ constructor(capacity: number);
1140
+ push(item: T): void;
1141
+ toArray(): T[];
1142
+ clear(): void;
669
1143
  }
670
1144
 
671
1145
  declare class Logger {
672
- channel: string;
673
- constructor(channel: string);
1146
+ static logHandlers: LoggerHandler[];
1147
+ static logHistory: CircularBuffer<LogHistoryData>;
674
1148
  static addHandler(handler: LoggerHandler): void;
1149
+ static printLogHistoryData(log: LogHistoryData): void;
1150
+ static consoleLog(channel: string, level: string, ...args: any[]): void;
1151
+ private channel;
1152
+ constructor(channel: string);
675
1153
  debug(...args: any[]): void;
676
1154
  info(...args: any[]): void;
677
1155
  warn(...args: any[]): void;
678
1156
  error(...args: any[]): void;
679
- private _log;
1157
+ private log;
680
1158
  }
681
- declare const consoleLoggerHandler: LoggerHandler;
682
1159
 
683
1160
  declare const ENVIRONMENT: string;
684
1161
  declare const VERSION: string;
@@ -691,4 +1168,96 @@ declare const OPTIONS: {
691
1168
  version: string;
692
1169
  };
693
1170
 
694
- export { BaseProvider, type CallRequest, type CallResponse, Chat, type ChatDeflectionResponse, 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 FileTypeItem, type FormData, type GenerateTranscriptResponse, type GetServerMessage, type HumanAgent, type IssueChatTokenMethod, type LanguageOption, type LogData, 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 SurveyAnswers, type TokenResponse, type TriggerItem, type TriggerMessage, type UserProfile, VERSION, type VirtualAgent, type WaitTimeResponse, addProviderType, consoleLoggerHandler };
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 };