@botpress/webchat 3.0.0 → 3.1.0-beta.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.
@@ -1,21 +1,21 @@
1
1
 
2
- > @botpress/webchat@3.0.0 build /home/runner/work/genisys/genisys/packages/webchat-components
2
+ > @botpress/webchat@3.1.0-beta.0 build /home/runner/work/genisys/genisys/packages/webchat-components
3
3
  > vite build
4
4
 
5
5
  vite v5.4.8 building for production...
6
6
  transforming...
7
- ✓ 3046 modules transformed.
7
+ ✓ 3087 modules transformed.
8
8
  rendering chunks...
9
9
 
10
10
  [vite:dts] Start generate declaration files...
11
11
  computing gzip size...
12
- dist/style.css  44.76 kB │ gzip: 8.25 kB
13
- dist/index.js 776.75 kB │ gzip: 212.99 kB
12
+ dist/style.css  46.57 kB │ gzip: 8.58 kB
13
+ dist/index.js 773.33 kB │ gzip: 212.28 kB
14
14
  [vite:dts] Start rollup declaration files...
15
15
  Analysis will use the bundled TypeScript version 5.4.2
16
16
  *** The target project appears to use TypeScript 5.6.2 which is newer than the bundled compiler engine; consider upgrading API Extractor.
17
- [vite:dts] Declaration files built in 21441ms.
17
+ [vite:dts] Declaration files built in 20967ms.
18
18
 
19
- dist/style.css  44.76 kB │ gzip: 8.25 kB
20
- dist/index.umd.cjs 517.62 kB │ gzip: 174.18 kB
21
- ✓ built in 28.74s
19
+ dist/style.css  46.57 kB │ gzip: 8.58 kB
20
+ dist/index.umd.cjs 516.92 kB │ gzip: 173.66 kB
21
+ ✓ built in 28.50s
package/dist/index.d.ts CHANGED
@@ -5,9 +5,11 @@ import { ComponentProps } from 'react';
5
5
  import { ComponentPropsWithRef } from 'react';
6
6
  import { CSSProperties } from 'react';
7
7
  import * as Dialog from '@radix-ui/react-dialog';
8
+ import { EventEmitter } from '@bpinternal/shared';
8
9
  import type { FC } from 'react';
9
10
  import { ForwardRefExoticComponent } from 'react';
10
11
  import { HTMLAttributes } from 'react';
12
+ import { IntegrationError } from '@botpress/webchat-client';
11
13
  import { JSX as JSX_2 } from 'react';
12
14
  import { JSX as JSX_3 } from 'react/jsx-runtime';
13
15
  import { LatestWebchatConfig } from '@bpinternal/shared';
@@ -22,8 +24,8 @@ import { RefObject } from 'react';
22
24
  import { RotateCcw } from 'lucide-react';
23
25
  import { StoreApi } from 'zustand';
24
26
  import { UseBoundStore } from 'zustand';
27
+ import { User } from '@botpress/webchat-client';
25
28
  import { UserCredentials } from '@botpress/webchat-client';
26
- import { UserProps } from '@bpinternal/shared';
27
29
 
28
30
  declare type AnyEvent = ValueOf<{
29
31
  [K in keyof WebchatEvents]: {
@@ -66,6 +68,7 @@ export declare type BlockMessage<T = GenericBlock> = {
66
68
  conversationId?: string;
67
69
  authorId?: string;
68
70
  disableInput?: boolean;
71
+ status?: 'pending' | 'processing' | 'processed' | 'failed' | 'skipped';
69
72
  metadata?: {
70
73
  clientMessageId?: string;
71
74
  delivered?: boolean;
@@ -90,6 +93,8 @@ declare type BlockProps<T extends GenericBlock['type']> = {
90
93
  renderers?: Partial<Renderers>;
91
94
  };
92
95
 
96
+ export declare const BOT_IS_BLOCKED = "This bot is currently blocked or disabled.";
97
+
93
98
  declare type BoundWebchatClientStore = ReturnType<typeof createWebchatClientStore>;
94
99
 
95
100
  export declare type BubbleBlock = {
@@ -118,14 +123,12 @@ declare type ByType<M extends {
118
123
  }>;
119
124
  };
120
125
 
121
- declare type CallbackFn<T> = (args: T) => void;
122
-
123
126
  export declare type CarouselBlock = {
124
127
  type: 'carousel';
125
128
  blocks: GenericBlock[];
126
129
  };
127
130
 
128
- export declare const Chat: ({ connected, configuration, closeWindow, isTyping, messages, user, sendMessage, uploadFile, addMessageFeedback, isLoading, renderers, isReadOnly, disableComposer, restartConversation, allowFileUpload, ...props }: Props) => JSX_3.Element;
131
+ export declare const Chat: ({ connected, configuration, isTyping, messages, user, isLoading, renderers, isReadOnly, disableComposer, allowFileUpload, error, participants, closeWindow, sendMessage, uploadFile, addMessageFeedback, restartConversation, ...props }: Props) => JSX_3.Element;
129
132
 
130
133
  export declare type ColumnBlock = {
131
134
  type: 'column';
@@ -138,10 +141,15 @@ export declare type ColumnOf<T extends GenericBlock> = Omit<ColumnBlock, 'blocks
138
141
  blocks: T[];
139
142
  };
140
143
 
144
+ export declare const commonApiErrorMap: {
145
+ [key in 'MethodNotFound' | 'QuotaExceeded' | 'Forbidden']: WebchatError;
146
+ };
147
+
141
148
  export declare type CommonBlockProps = Pick<RichBlockMessage, 'direction' | 'sender' | 'timestamp' | 'feedback'> & {
142
149
  messageId: string;
143
150
  metadata?: Record<string, any>;
144
151
  isReadOnly?: boolean;
152
+ status?: BlockMessage['status'];
145
153
  sendMessage?: (payload: IntegrationMessage['payload']) => void;
146
154
  addMessageFeedback?: (messageId: string, feedback: Feedback) => void;
147
155
  };
@@ -152,6 +160,8 @@ declare type ComposableIntegrationMessageTypes = 'audio' | 'bloc' | 'file' | 'im
152
160
 
153
161
  export declare const Composer: MemoExoticComponent<ForwardRefExoticComponent<Omit<Props_3, "ref"> & RefAttributes<HTMLDivElement>>>;
154
162
 
163
+ export declare const CONFIG_ACCESS_DENIED = "Access denied to configuration file. Please check your credentials or your configuration URL and try again.";
164
+
155
165
  declare type configuration = ComponentProps<typeof Chat>['configuration'];
156
166
 
157
167
  export declare const Container: {
@@ -196,19 +206,25 @@ export declare type DropdownBlock = {
196
206
  }[];
197
207
  };
198
208
 
199
- declare class EventEmitter<T extends Record<string, any>> {
200
- private readonly eventMap;
201
- constructor();
202
- on<U extends keyof T>(event: U, callback: CallbackFn<T[U]>): () => void;
203
- emit<U extends keyof T>(event: U, arg?: T[U]): void;
204
- }
209
+ export declare function enrichMessage(messages: BlockMessage[], participants: User[], currentUserId: string, botName?: string, botAvatar?: string): RichBlockMessage[];
210
+
211
+ declare type ErrorProps = {
212
+ error: WebchatError;
213
+ restartConversation?: () => void;
214
+ };
215
+
216
+ export declare function ErrorState({ error, restartConversation }: ErrorProps): JSX_3.Element;
217
+
218
+ declare type EventError = Error & {
219
+ type: 'error';
220
+ };
205
221
 
206
222
  declare type Events = WebchatEvents & {
207
223
  '*': AnyEvent;
208
224
  };
209
225
 
210
226
  declare type Events_2 = {
211
- [key: string]: undefined;
227
+ [key: string]: string;
212
228
  };
213
229
 
214
230
  export declare const Fab: ForwardRefExoticComponent<Omit<ClassAttributes<HTMLDivElement> & HTMLAttributes<HTMLDivElement> & {
@@ -233,6 +249,8 @@ export declare type GenericBlock = AudioBlock | BubbleBlock | ButtonBlock | Caro
233
249
 
234
250
  export declare const getUseWebchatClientStore: typeof WebchatClientStores.getInstance;
235
251
 
252
+ export declare const handleIntegrationError: (thrown: unknown) => WebchatError;
253
+
236
254
  export declare const Header: ({ defaultOpen, closeWindow, configuration, restartConversation, ...props }: HeaderProps) => JSX_3.Element;
237
255
 
238
256
  declare type HeaderProps = {
@@ -245,6 +263,12 @@ declare type HeaderProps = {
245
263
  configuration: Pick<LatestWebchatConfig, 'email' | 'phone' | 'privacyPolicy' | 'website' | 'termsOfService' | 'botAvatar' | 'botDescription' | 'botName'>;
246
264
  };
247
265
 
266
+ export declare type HookResult<T> = {
267
+ data: Simplify<T> | undefined;
268
+ isLoading: boolean;
269
+ error: WebchatError | undefined;
270
+ };
271
+
248
272
  export declare type ImageBlock = {
249
273
  type: 'image';
250
274
  orientation?: 'portrait' | 'landscape' | 'square' | 'auto';
@@ -261,8 +285,28 @@ export declare function integrationMessageToBlockMessage(message: IntegrationMes
261
285
 
262
286
  declare type IntegrationMessageTypes = IntegrationMessage['payload']['type'];
263
287
 
288
+ export declare const INVALID_API_URL = "Invalid API URL. Please use a valid API URL.";
289
+
290
+ export declare const INVALID_BOTPRESS_URL = "Invalid URL. Please make sure your client ID and API URL are valid";
291
+
292
+ export declare const INVALID_CLIENT_ID = "Invalid Client ID. Please use a valid Botpress Client ID.";
293
+
294
+ export declare const INVALID_CONFIG_URL = "Invalid config URL. Please make sure your config URL is valid";
295
+
296
+ export declare const INVALID_CONFIGURATION = "Invalid webchat configuration, please make sure your config file is valid";
297
+
298
+ export declare const INVALID_MESSAGE_CONTENT_TYPE = "Unable to process the message. Please start a new conversation.";
299
+
300
+ export declare function isCommonApiErrorType(type: string): type is keyof typeof commonApiErrorMap;
301
+
302
+ export declare function isEventError(thrown: unknown): thrown is EventError;
303
+
264
304
  export declare const isFileType: (type: string) => type is FileType;
265
305
 
306
+ export declare function isIntegrationError(thrown: unknown): thrown is IntegrationError;
307
+
308
+ export declare function isWebhookHandlerErrorType(type: string): type is keyof typeof webhookHandlerErrorMap;
309
+
266
310
  export declare type LocationBlock = {
267
311
  type: 'location';
268
312
  latitude: number;
@@ -276,6 +320,7 @@ export declare const Message: MemoExoticComponent<ForwardRefExoticComponent<{
276
320
  sendMessage?: (payload: IntegrationMessage["payload"]) => void;
277
321
  addMessageFeedback?: (messageId: string, feedback: Feedback) => void;
278
322
  isReadOnly?: boolean;
323
+ isLastDeliveredMessage?: boolean;
279
324
  } & BlockMessage<GenericBlock> & {
280
325
  direction: "incoming" | "outgoing" | "system";
281
326
  sender: {
@@ -299,6 +344,14 @@ declare type MessageListProps = {
299
344
  showMarquee?: boolean;
300
345
  };
301
346
 
347
+ export declare const MISSING_API_URL = "The API url is required to initialize the webchat.";
348
+
349
+ export declare const MISSING_BOT_ID = "The Bot ID is required to initialize the webchat.";
350
+
351
+ export declare const MISSING_CLIENT_ID = "The Client ID is required to initialize the webchat.";
352
+
353
+ export declare const MISSING_CONFIG_URL = "No config URL provided.";
354
+
302
355
  export declare function Modal({ open, onOpenChange, children, }: {
303
356
  open?: boolean;
304
357
  onOpenChange?: (open: boolean) => void;
@@ -330,6 +383,10 @@ export declare const ModalProvider: ({ children }: {
330
383
  children: ReactNode;
331
384
  }) => JSX_3.Element;
332
385
 
386
+ export declare const NETWORK_ERROR = "Please check your internet connection and refresh the page.";
387
+
388
+ export declare const NOT_A_PARTICIPANT = "You are not a participant of this conversation, please clear your local storage.";
389
+
333
390
  export declare type Options = {
334
391
  timeout?: number;
335
392
  };
@@ -339,6 +396,7 @@ export declare type Props = {
339
396
  renderers?: Partial<Renderers>;
340
397
  configuration: LatestWebchatConfig;
341
398
  messages: BlockMessage[];
399
+ participants: User[];
342
400
  connected?: boolean;
343
401
  disableComposer?: boolean;
344
402
  isReadOnly?: boolean;
@@ -352,13 +410,14 @@ export declare type Props = {
352
410
  user?: {
353
411
  id: string;
354
412
  } & Record<string, unknown>;
355
- sendMessage?: (payload: IntegrationMessage['payload']) => void;
413
+ sendMessage?: (payload: IntegrationMessage['payload']) => Promise<void>;
356
414
  uploadFile?: (file: File) => Promise<{
357
415
  fileUrl: string;
358
416
  name: string;
359
417
  type: FileType;
360
418
  }>;
361
419
  addMessageFeedback?: (messageId: string, feedback: Feedback) => void;
420
+ error?: WebchatError;
362
421
  };
363
422
 
364
423
  declare type Props_2 = {
@@ -368,7 +427,7 @@ declare type Props_2 = {
368
427
  apiUrl?: string;
369
428
  sseTimeout?: number;
370
429
  storageKey?: string;
371
- storageLocation?: Parameters<typeof getUseWebchatClientStore>[1];
430
+ storageLocation?: StorageLocation;
372
431
  };
373
432
 
374
433
  declare type Props_3 = ComponentProps<'div'> & {
@@ -410,6 +469,8 @@ declare type Props_6 = {
410
469
 
411
470
  declare type Props_7 = Partial<LatestWebchatTheme>;
412
471
 
472
+ export declare const QUOTA_EXCEEDED = "This bot has temporarily paused. Please check back later.";
473
+
413
474
  export declare type Renderers = {
414
475
  [T in GenericBlock['type']]: FC<BlockObjects[T]>;
415
476
  };
@@ -447,9 +508,15 @@ declare type ScopedClient = {
447
508
  }>;
448
509
  addMessageFeedback: (messageId: string, feedback: Feedback) => Promise<void>;
449
510
  getUser: () => Promise<UserResponse>;
450
- updateUser: (user: User) => Promise<User>;
511
+ updateUser: (user: UserProfile) => Promise<User>;
451
512
  };
452
513
 
514
+ export declare type Simplify<T> = {
515
+ [KeyType in keyof T]: T[KeyType];
516
+ } & {};
517
+
518
+ export declare const SSE_DISCONNECTED_ERROR = "You've been disconnected from the conversation. Please refresh the page.";
519
+
453
520
  declare type StorageLocation = 'sessionStorage' | 'localStorage';
454
521
 
455
522
  export declare type StyleOptions = {
@@ -478,7 +545,7 @@ export declare type UseImageSizeResult = [Dimensions | null, {
478
545
  error: string | null;
479
546
  }];
480
547
 
481
- declare type User = UserProps;
548
+ declare type UserProfile = Omit<User, 'id' | 'createdAt' | 'updatedAt'>;
482
549
 
483
550
  declare type UserResponse = Awaited<ReturnType<Client['getUser']>>['user'];
484
551
 
@@ -494,8 +561,10 @@ declare type UseWebchatReturn = {
494
561
  isFetchingMessages: boolean;
495
562
  user?: UserCredentials;
496
563
  isTyping: boolean;
564
+ error?: WebchatError;
565
+ participants: User[];
497
566
  } | {
498
- clientState: 'connecting';
567
+ clientState: 'connecting' | 'error';
499
568
  on: EventEmitter<Events>['on'];
500
569
  client: undefined;
501
570
  messages: BlockMessage[];
@@ -504,6 +573,8 @@ declare type UseWebchatReturn = {
504
573
  isFetchingMessages: boolean;
505
574
  user: undefined;
506
575
  isTyping: undefined;
576
+ error?: WebchatError;
577
+ participants: User[];
507
578
  };
508
579
 
509
580
  export declare const useWebchatStore: UseBoundStore<Omit<StoreApi<WebchatStore>, "setState"> & {
@@ -778,6 +849,9 @@ export declare const webchatClasses: {
778
849
  readonly className: "bpMessageAvatarFallback";
779
850
  };
780
851
  };
852
+ readonly deliveryStatus: {
853
+ readonly className: "bpMessageDeliveryStatus";
854
+ };
781
855
  readonly blocks: {
782
856
  readonly text: {
783
857
  readonly heading1: {
@@ -949,6 +1023,26 @@ export declare const webchatClasses: {
949
1023
  };
950
1024
  };
951
1025
  };
1026
+ readonly error: {
1027
+ readonly container: {
1028
+ readonly className: "bpReset bpErrorContainer";
1029
+ };
1030
+ readonly header: {
1031
+ readonly className: "bpErrorHeader";
1032
+ };
1033
+ readonly content: {
1034
+ readonly className: "bpErrorContent";
1035
+ };
1036
+ readonly errorTitle: {
1037
+ readonly className: "bpErrorTitle";
1038
+ };
1039
+ readonly errorMessage: {
1040
+ readonly className: "bpErrorMessage";
1041
+ };
1042
+ readonly icon: {
1043
+ readonly className: "bpErrorIcon";
1044
+ };
1045
+ };
952
1046
  readonly typingIndicator: {
953
1047
  readonly container: {
954
1048
  readonly className: "bpTypingIndicatorContainer";
@@ -963,7 +1057,7 @@ declare type WebchatClientStore = {
963
1057
  user?: UserCredentials;
964
1058
  conversationId?: string;
965
1059
  setUser: (userId?: UserCredentials) => void;
966
- setConversationId: (conversationId?: string) => void;
1060
+ setConversationId: (conversationId: string) => void;
967
1061
  clearAll: () => void;
968
1062
  };
969
1063
 
@@ -973,6 +1067,20 @@ declare class WebchatClientStores {
973
1067
  static getInstance(name?: string, storageLocation?: StorageLocation): BoundWebchatClientStore;
974
1068
  }
975
1069
 
1070
+ export declare type WebchatError = {
1071
+ type: 'configuration';
1072
+ message: typeof MISSING_CLIENT_ID | typeof MISSING_API_URL | typeof MISSING_BOT_ID | typeof INVALID_CLIENT_ID | typeof INVALID_CONFIGURATION | typeof MISSING_CONFIG_URL;
1073
+ } | {
1074
+ type: 'bot';
1075
+ message: typeof BOT_IS_BLOCKED | typeof QUOTA_EXCEEDED | typeof NOT_A_PARTICIPANT;
1076
+ } | {
1077
+ type: 'network';
1078
+ message: typeof NETWORK_ERROR | typeof SSE_DISCONNECTED_ERROR;
1079
+ } | {
1080
+ type: string;
1081
+ message: string;
1082
+ };
1083
+
976
1084
  export declare type WebchatEvents = {
977
1085
  conversation: string | undefined;
978
1086
  message: BlockMessage;
@@ -985,6 +1093,8 @@ export declare type WebchatEvents = {
985
1093
  isTyping: boolean;
986
1094
  timeout: number;
987
1095
  };
1096
+ participantAdded: User;
1097
+ participantRemoved: User;
988
1098
  };
989
1099
 
990
1100
  declare type WebchatStore = {
@@ -993,4 +1103,8 @@ declare type WebchatStore = {
993
1103
  eventEmitter: EventEmitter<Events_2>;
994
1104
  };
995
1105
 
1106
+ export declare const webhookHandlerErrorMap: {
1107
+ [key in 'ResourceNotFound' | 'Forbidden']: WebchatError;
1108
+ };
1109
+
996
1110
  export { }