@enjoys/react-chatbot-plugin 1.4.0 → 1.5.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
@@ -12,14 +12,64 @@ export declare interface ActionContext {
12
12
  }
13
13
 
14
14
  /**
15
- * Analytics Plugin — tracks message counts, form completions, drop-offs
15
+ * Agent Plugin — enables live human agent takeover of the chat
16
+ */
17
+ export declare function agentPlugin(options: {
18
+ socketUrl?: string;
19
+ onAgentConnect?: (ctx: PluginContext) => void;
20
+ onAgentDisconnect?: (ctx: PluginContext) => void;
21
+ onAgentMessage?: (text: string, ctx: PluginContext) => void;
22
+ connectMessage?: string;
23
+ disconnectMessage?: string;
24
+ }): ChatPlugin;
25
+
26
+ /**
27
+ * AI Plugin — generates bot responses using external AI providers (OpenAI, Anthropic, custom)
28
+ */
29
+ export declare function aiPlugin(options: {
30
+ provider?: 'openai' | 'anthropic' | 'custom';
31
+ endpoint?: string;
32
+ apiKey?: string;
33
+ model?: string;
34
+ systemPrompt?: string;
35
+ headers?: Record<string, string>;
36
+ shouldRespond?: (text: string) => boolean;
37
+ parseResponse?: (response: unknown) => string;
38
+ timeout?: number;
39
+ }): ChatPlugin;
40
+
41
+ /**
42
+ * Analytics Plugin — tracks sessions, messages, forms, timing, and step progression
16
43
  */
17
44
  export declare function analyticsPlugin(options?: {
18
45
  onTrack?: (event: string, data?: unknown) => void;
46
+ sessionId?: string;
19
47
  }): ChatPlugin;
20
48
 
21
49
  export declare const AttachmentIcon: default_2.FC<IconProps>;
22
50
 
51
+ /**
52
+ * Auth Plugin — manages user authentication and identity
53
+ */
54
+ export declare function authPlugin(options: {
55
+ type?: 'jwt' | 'session' | 'custom';
56
+ tokenKey?: string;
57
+ storage?: 'local' | 'session';
58
+ onAuth?: (token: string, ctx: PluginContext) => void;
59
+ onAuthExpired?: (ctx: PluginContext) => void;
60
+ validateToken?: (token: string) => boolean;
61
+ }): ChatPlugin;
62
+
63
+ /**
64
+ * Auto Reply Plugin — sends automated replies when user is inactive
65
+ */
66
+ export declare function autoReplyPlugin(options?: {
67
+ timeout?: number;
68
+ message?: string;
69
+ maxReplies?: number;
70
+ onlyWhenOpen?: boolean;
71
+ }): ChatPlugin;
72
+
23
73
  export declare const Branding: default_2.FC<BrandingProps>;
24
74
 
25
75
  export declare interface BrandingConfig {
@@ -4376,6 +4426,22 @@ export declare function buildStyles(theme: Required<ChatTheme>, overrides?: Chat
4376
4426
  };
4377
4427
  };
4378
4428
 
4429
+ declare interface CampaignConfig {
4430
+ trigger: TriggerType;
4431
+ message: string;
4432
+ delay?: number;
4433
+ maxShows?: number;
4434
+ flowStep?: string;
4435
+ }
4436
+
4437
+ /**
4438
+ * Campaign Plugin — starts flows or shows messages based on user behavior triggers
4439
+ */
4440
+ export declare function campaignPlugin(options: {
4441
+ campaigns: CampaignConfig[];
4442
+ onTrigger?: (campaign: CampaignConfig, ctx: PluginContext) => void;
4443
+ }): ChatPlugin;
4444
+
4379
4445
  declare type ChatAction = {
4380
4446
  type: 'TOGGLE_OPEN';
4381
4447
  } | {
@@ -4630,6 +4696,54 @@ export declare interface CheckboxFieldRenderProps {
4630
4696
 
4631
4697
  export declare const CloseIcon: default_2.FC<IconProps>;
4632
4698
 
4699
+ /**
4700
+ * Component Plugin — injects custom component messages into chat via events
4701
+ */
4702
+ export declare function componentPlugin(options?: {
4703
+ components?: Record<string, string>;
4704
+ onRender?: (componentKey: string, ctx: PluginContext) => void;
4705
+ }): ChatPlugin;
4706
+
4707
+ /**
4708
+ * CRM Plugin — pushes user/lead data to CRM systems
4709
+ */
4710
+ export declare function crmPlugin(options: {
4711
+ endpoint: string;
4712
+ provider?: string;
4713
+ headers?: Record<string, string>;
4714
+ mapFields?: (data: Record<string, unknown>) => Record<string, unknown>;
4715
+ events?: ('submit' | 'flowEnd' | 'login')[];
4716
+ }): ChatPlugin;
4717
+
4718
+ /**
4719
+ * Debug Plugin — exposes internal state and flow progression for debugging
4720
+ */
4721
+ export declare function debugPlugin(options?: {
4722
+ logState?: boolean;
4723
+ logEvents?: boolean;
4724
+ logMessages?: boolean;
4725
+ groupName?: string;
4726
+ }): ChatPlugin;
4727
+
4728
+ /**
4729
+ * DevTools Plugin — provides a visual debugging panel overlay
4730
+ */
4731
+ export declare function devtoolsPlugin(options?: {
4732
+ position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
4733
+ shortcutKey?: string;
4734
+ onStateUpdate?: (state: DevToolsState) => void;
4735
+ }): ChatPlugin;
4736
+
4737
+ declare interface DevToolsState {
4738
+ messages: number;
4739
+ events: Array<{
4740
+ type: string;
4741
+ time: number;
4742
+ }>;
4743
+ data: Record<string, unknown>;
4744
+ currentStep: string | null;
4745
+ }
4746
+
4633
4747
  export declare const DynamicForm: default_2.FC<DynamicFormProps>;
4634
4748
 
4635
4749
  declare interface DynamicFormProps {
@@ -4639,6 +4753,17 @@ declare interface DynamicFormProps {
4639
4753
  renderFormField?: FormFieldRenderMap;
4640
4754
  }
4641
4755
 
4756
+ /**
4757
+ * Email Plugin — triggers emails via external API when chat events occur
4758
+ */
4759
+ export declare function emailPlugin(options: {
4760
+ endpoint: string;
4761
+ template?: string;
4762
+ headers?: Record<string, string>;
4763
+ triggers?: ('submit' | 'flowEnd' | 'login')[];
4764
+ mapPayload?: (data: Record<string, unknown>) => Record<string, unknown>;
4765
+ }): ChatPlugin;
4766
+
4642
4767
  export declare const EmojiIcon: default_2.FC<IconProps>;
4643
4768
 
4644
4769
  export declare const EmojiPicker: default_2.FC<EmojiPickerProps>;
@@ -4881,6 +5006,16 @@ export declare interface HeaderConfig {
4881
5006
  showRestart?: boolean;
4882
5007
  }
4883
5008
 
5009
+ /**
5010
+ * i18n Plugin — supports multiple languages with dynamic switching
5011
+ */
5012
+ export declare function i18nPlugin(options: {
5013
+ defaultLocale?: string;
5014
+ translations: Translations;
5015
+ storageKey?: string;
5016
+ onLocaleChange?: (locale: string, ctx: PluginContext) => void;
5017
+ }): ChatPlugin;
5018
+
4884
5019
  declare interface IconProps {
4885
5020
  size?: number;
4886
5021
  color?: string;
@@ -4889,6 +5024,21 @@ declare interface IconProps {
4889
5024
 
4890
5025
  export declare const ImageIcon: default_2.FC<IconProps>;
4891
5026
 
5027
+ /**
5028
+ * Intent Plugin — detects user intent from text and emits intent events for dynamic routing
5029
+ */
5030
+ export declare function intentPlugin(options?: {
5031
+ rules?: IntentRule[];
5032
+ onIntentDetected?: (intent: string, text: string, ctx: PluginContext) => void;
5033
+ fallbackIntent?: string;
5034
+ }): ChatPlugin;
5035
+
5036
+ declare interface IntentRule {
5037
+ intent: string;
5038
+ patterns: string[];
5039
+ matchType?: 'contains' | 'exact' | 'regex';
5040
+ }
5041
+
4892
5042
  /** Route configuration for keyword-based text matching */
4893
5043
  export declare interface KeywordRoute {
4894
5044
  /** Patterns to match against user text */
@@ -4917,6 +5067,26 @@ declare interface LauncherProps {
4917
5067
  zIndex?: number;
4918
5068
  }
4919
5069
 
5070
+ /**
5071
+ * Lead Plugin — captures and stores user information as leads
5072
+ */
5073
+ export declare function leadPlugin(options: {
5074
+ fields?: string[];
5075
+ endpoint?: string;
5076
+ headers?: Record<string, string>;
5077
+ storageKey?: string;
5078
+ onLeadCaptured?: (lead: Record<string, unknown>, ctx: PluginContext) => void;
5079
+ }): ChatPlugin;
5080
+
5081
+ /**
5082
+ * Logger Plugin — logs all chatbot events for debugging or auditing
5083
+ */
5084
+ export declare function loggerPlugin(options?: {
5085
+ level?: LogLevel;
5086
+ prefix?: string;
5087
+ logger?: Pick<Console, 'debug' | 'info' | 'warn' | 'error'>;
5088
+ }): ChatPlugin;
5089
+
4920
5090
  export declare const LoginScreen: default_2.FC<LoginScreenProps>;
4921
5091
 
4922
5092
  declare interface LoginScreenProps {
@@ -4926,6 +5096,29 @@ declare interface LoginScreenProps {
4926
5096
  renderFormField?: FormFieldRenderMap;
4927
5097
  }
4928
5098
 
5099
+ declare type LogLevel = 'debug' | 'info' | 'warn' | 'error';
5100
+
5101
+ /**
5102
+ * Markdown Plugin — transforms markdown syntax in bot messages to HTML
5103
+ * Lightweight built-in renderer, no external dependencies.
5104
+ */
5105
+ export declare function markdownPlugin(options?: {
5106
+ enableBold?: boolean;
5107
+ enableItalic?: boolean;
5108
+ enableCode?: boolean;
5109
+ enableLinks?: boolean;
5110
+ enableLists?: boolean;
5111
+ enableLineBreaks?: boolean;
5112
+ }): ChatPlugin;
5113
+
5114
+ /**
5115
+ * Media Plugin — adds support for rich media messages (images, videos, cards)
5116
+ */
5117
+ export declare function mediaPlugin(options?: {
5118
+ allowedTypes?: ('image' | 'video' | 'audio' | 'card')[];
5119
+ onMediaRender?: (type: string, url: string) => void;
5120
+ }): ChatPlugin;
5121
+
4929
5122
  export declare interface MessageAttachment {
4930
5123
  name: string;
4931
5124
  url: string;
@@ -4967,11 +5160,13 @@ export declare type MessageSender = 'bot' | 'user' | 'system';
4967
5160
  export declare const MinimizeIcon: default_2.FC<IconProps>;
4968
5161
 
4969
5162
  /**
4970
- * Persistence Plugin — saves/restores chat history via localStorage
5163
+ * Persistence Plugin — saves/restores full chat history via browser storage
4971
5164
  */
4972
5165
  export declare function persistencePlugin(options?: {
4973
5166
  storageKey?: string;
4974
5167
  storage?: 'local' | 'session';
5168
+ maxMessages?: number;
5169
+ ttl?: number;
4975
5170
  }): ChatPlugin;
4976
5171
 
4977
5172
  export declare interface PluginContext {
@@ -5001,15 +5196,28 @@ export declare class PluginManager {
5001
5196
  private eventHandlers;
5002
5197
  register(plugins: ChatPlugin[]): void;
5003
5198
  setContext(ctx: Omit<PluginContext, 'on' | 'emit'>): void;
5199
+ getContext(): PluginContext | null;
5004
5200
  private on;
5005
5201
  private emit;
5006
5202
  init(): Promise<void>;
5007
5203
  onMessage(message: ChatMessage): Promise<ChatMessage>;
5008
5204
  onSubmit(data: Record<string, unknown>): Promise<void>;
5205
+ /** Emit a lifecycle event to all plugins (open, close, flowEnd, stepChange, quickReply, etc.) */
5206
+ emitEvent(type: string, payload?: unknown): void;
5009
5207
  destroy(): Promise<void>;
5010
5208
  private dispatchEvent;
5011
5209
  }
5012
5210
 
5211
+ /**
5212
+ * Push Plugin — sends browser push notifications for new messages
5213
+ */
5214
+ export declare function pushPlugin(options?: {
5215
+ title?: string;
5216
+ icon?: string;
5217
+ onlyWhenHidden?: boolean;
5218
+ requestPermission?: boolean;
5219
+ }): ChatPlugin;
5220
+
5013
5221
  export declare const QuickReplies: default_2.FC<QuickRepliesProps>;
5014
5222
 
5015
5223
  declare interface QuickRepliesProps {
@@ -5036,12 +5244,49 @@ export declare interface RadioFieldRenderProps {
5036
5244
  error?: string;
5037
5245
  }
5038
5246
 
5247
+ /**
5248
+ * Rate Limit Plugin — prevents spam by limiting message frequency
5249
+ */
5250
+ export declare function rateLimitPlugin(options?: {
5251
+ limit?: number;
5252
+ window?: number;
5253
+ onLimited?: (remaining: number) => void;
5254
+ warningMessage?: string;
5255
+ }): ChatPlugin;
5256
+
5257
+ /**
5258
+ * Reminder Plugin — sends reminder messages to users after configured delays
5259
+ */
5260
+ export declare function reminderPlugin(options?: {
5261
+ reminders?: Array<{
5262
+ message: string;
5263
+ delay: number;
5264
+ condition?: string;
5265
+ }>;
5266
+ onReminder?: (message: string) => void;
5267
+ }): ChatPlugin;
5268
+
5039
5269
  export declare const RemoveIcon: default_2.FC<IconProps>;
5040
5270
 
5041
5271
  export declare function resolveTheme(theme?: ChatTheme): Required<ChatTheme>;
5042
5272
 
5043
5273
  export declare const RestartIcon: default_2.FC<IconProps>;
5044
5274
 
5275
+ declare interface ScheduledMessage {
5276
+ message: string;
5277
+ delay: number;
5278
+ repeat?: boolean;
5279
+ interval?: number;
5280
+ }
5281
+
5282
+ /**
5283
+ * Scheduler Plugin — triggers bot messages at scheduled times or intervals
5284
+ */
5285
+ export declare function schedulerPlugin(options: {
5286
+ messages?: ScheduledMessage[];
5287
+ onScheduledMessage?: (message: string) => void;
5288
+ }): ChatPlugin;
5289
+
5045
5290
  export declare const SelectField: default_2.FC<SelectFieldProps>;
5046
5291
 
5047
5292
  declare interface SelectFieldProps {
@@ -5062,6 +5307,15 @@ export declare interface SelectFieldRenderProps {
5062
5307
 
5063
5308
  export declare const SendIcon: default_2.FC<IconProps>;
5064
5309
 
5310
+ /**
5311
+ * Sound Plugin — plays sound on new bot messages
5312
+ */
5313
+ export declare function soundPlugin(options?: {
5314
+ src?: string;
5315
+ volume?: number;
5316
+ onlyWhenHidden?: boolean;
5317
+ }): ChatPlugin;
5318
+
5065
5319
  /** Props passed to custom components rendered in flow steps */
5066
5320
  export declare interface StepComponentProps {
5067
5321
  /** The step ID that owns this component */
@@ -5072,6 +5326,16 @@ export declare interface StepComponentProps {
5072
5326
  onComplete: (result?: FlowActionResult) => void;
5073
5327
  }
5074
5328
 
5329
+ /**
5330
+ * Sync Plugin — syncs chat data with a backend endpoint
5331
+ */
5332
+ export declare function syncPlugin(options: {
5333
+ endpoint: string;
5334
+ headers?: Record<string, string>;
5335
+ syncInterval?: number;
5336
+ sessionKey?: string;
5337
+ }): ChatPlugin;
5338
+
5075
5339
  export declare const TextField: default_2.FC<TextFieldProps>;
5076
5340
 
5077
5341
  declare interface TextFieldProps {
@@ -5090,12 +5354,69 @@ export declare interface TextFieldRenderProps {
5090
5354
  error?: string;
5091
5355
  }
5092
5356
 
5357
+ /**
5358
+ * Theme Plugin — switches themes dynamically and persists preference
5359
+ */
5360
+ export declare function themePlugin(options?: {
5361
+ defaultMode?: 'light' | 'dark';
5362
+ storageKey?: string;
5363
+ onThemeChange?: (mode: string, ctx: PluginContext) => void;
5364
+ cssVariable?: string;
5365
+ }): ChatPlugin;
5366
+
5367
+ /**
5368
+ * Transfer Plugin — transfers chat to different departments/agents via API
5369
+ */
5370
+ export declare function transferPlugin(options: {
5371
+ endpoint: string;
5372
+ headers?: Record<string, string>;
5373
+ departments?: string[];
5374
+ onTransfer?: (department: string, ctx: PluginContext) => void;
5375
+ onTransferComplete?: (result: unknown, ctx: PluginContext) => void;
5376
+ transferMessage?: string;
5377
+ }): ChatPlugin;
5378
+
5379
+ declare type Translations = Record<string, Record<string, string>>;
5380
+
5381
+ declare type TriggerType = 'exitIntent' | 'idle' | 'scroll' | 'pageLoad' | 'custom';
5382
+
5093
5383
  export declare const TypingIndicator: default_2.FC<TypingIndicatorProps>;
5094
5384
 
5095
5385
  declare interface TypingIndicatorProps {
5096
5386
  color: string;
5097
5387
  }
5098
5388
 
5389
+ /**
5390
+ * Typing Plugin — adds configurable typing delay before bot messages are shown
5391
+ */
5392
+ export declare function typingPlugin(options?: {
5393
+ delay?: number;
5394
+ onTypingStart?: () => void;
5395
+ onTypingEnd?: () => void;
5396
+ }): ChatPlugin;
5397
+
5398
+ /**
5399
+ * Upload Plugin — handles file uploads to external storage (S3, etc.)
5400
+ */
5401
+ export declare function uploadPlugin(options: {
5402
+ endpoint: string;
5403
+ storage?: 's3' | 'gcs' | 'azure' | 'custom';
5404
+ headers?: Record<string, string>;
5405
+ maxSize?: number;
5406
+ allowedTypes?: string[];
5407
+ onUploadStart?: (file: {
5408
+ name: string;
5409
+ size: number;
5410
+ }) => void;
5411
+ onUploadComplete?: (file: {
5412
+ name: string;
5413
+ url: string;
5414
+ }) => void;
5415
+ onUploadError?: (file: {
5416
+ name: string;
5417
+ }, error: Error) => void;
5418
+ }): ChatPlugin;
5419
+
5099
5420
  export declare function useChat(): {
5100
5421
  state: ChatState;
5101
5422
  sendMessage: (text: string) => Promise<void>;
@@ -5115,12 +5436,28 @@ export declare function useChat(): {
5115
5436
  export declare function useChatContext(): ChatContextValue;
5116
5437
 
5117
5438
  /**
5118
- * Webhook Plugin — sends messages/submissions to an external endpoint
5439
+ * Validation Plugin — adds advanced validation rules for user inputs
5440
+ */
5441
+ export declare function validationPlugin(options?: {
5442
+ validators?: Record<string, Validator>;
5443
+ sanitize?: boolean;
5444
+ blockProfanity?: boolean;
5445
+ profanityList?: string[];
5446
+ onValidationFail?: (text: string, error: string) => void;
5447
+ }): ChatPlugin;
5448
+
5449
+ declare type Validator = (text: string) => string | null;
5450
+
5451
+ declare type WebhookEventType = 'message' | 'submit' | 'init' | 'destroy' | 'open' | 'close' | 'flowEnd' | 'stepChange' | 'quickReply' | 'login';
5452
+
5453
+ /**
5454
+ * Webhook Plugin — sends messages/submissions/lifecycle events to an external endpoint
5119
5455
  */
5120
5456
  export declare function webhookPlugin(options: {
5121
5457
  url: string;
5122
5458
  headers?: Record<string, string>;
5123
- events?: ('message' | 'submit' | 'init' | 'destroy')[];
5459
+ events?: WebhookEventType[];
5460
+ timeout?: number;
5124
5461
  }): ChatPlugin;
5125
5462
 
5126
5463
  export declare const WelcomeScreen: default_2.FC<WelcomeScreenProps>;