@developer.notchatbot/webchat 1.2.1 β†’ 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # πŸ”· WebChat Widget
2
2
 
3
- A beautiful, embeddable chatbot widget built with **React**, **TypeScript**, **Vite**, **pnpm** and **Tailwind CSS** that can be easily integrated into any website with **just one file**.
3
+ A beautiful, embeddable chatbot widget built with **React**, **TypeScript**, **Vite**, **pnpm**, and **Tailwind CSS** that can be easily integrated into any website with **just one file**.
4
4
 
5
5
  ## ✨ Features
6
6
 
@@ -64,14 +64,17 @@ interface WebChatPositionConfig {
64
64
  marginBottom?: number;
65
65
  marginSide?: number;
66
66
  }
67
+ ```
67
68
 
69
+ Example:
70
+ ```js
68
71
  WebChat.initialize({
69
72
  title: "Chat Assistant",
70
73
  placeholder: "Type your message...",
71
74
  primaryColor: "#007bff",
72
75
  apiKey: "your-chatbot-uid", // Chatbot UID from admin panel
73
76
  position: "bottom-right",
74
- initialMessage: "Β‘Hola! πŸ‘‹ Soy tu asistente virtual. ΒΏEn quΓ© puedo ayudarte hoy?",
77
+ initialMessage: "Hi! πŸ‘‹ I'm your virtual assistant. How can I help you today?",
75
78
  closeButtonIcon: "default", // or "text" or "custom"
76
79
  marginBottom: 20, // Distance from bottom edge (default: 16px)
77
80
  marginSide: 20, // Distance from side edge (default: 16px)
@@ -88,7 +91,8 @@ WebChat.initialize({
88
91
  }
89
92
  });
90
93
  ```
91
- # πŸ’¬ EmbedChat - Chat Embebido
94
+
95
+ # πŸ’¬ EmbedChat - Embedded Chat
92
96
 
93
97
  EmbedChat allows you to integrate a complete chat system directly into any element of your web page, with full control over size, position, and style.
94
98
 
@@ -132,19 +136,19 @@ const chatInstance = EmbedChatAPI.initialize({
132
136
  EmbedChatAPI.initialize({
133
137
  // REQUIRED
134
138
  elementId: "my-chat-embed", // ID of the HTML element to embed the chat
135
- apiKey: "your-api-key", // API key of the service
139
+ apiKey: "your-api-key", // API key of the service
136
140
  })
137
141
  ```
138
142
 
139
- ### Propiedades de Contenido
143
+ ### Content Properties
140
144
  ```javascript
141
145
  EmbedChatAPI.initialize({
142
- // Textos y contenido
146
+ // Texts and content
143
147
  title: "Chat Assistant", // Title shown in the header
144
- placeholder: "Type your message...", // Text placeholder of the input
148
+ placeholder: "Type your message...", // Input placeholder text
145
149
  initialMessage: "Hello! πŸ‘‹ I'm your chat assistant. How can I help you today?", // First message from the bot
146
- footerText: "Powered by NotChatBot", // Text of the footer (optional)
147
- avatar: "https://example.com/avatar.jpg", // URL of the bot's avatar
150
+ footerText: "Powered by NotChatBot", // Footer text (optional)
151
+ avatar: "https://example.com/avatar.jpg", // Bot avatar URL
148
152
  })
149
153
  ```
150
154
 
@@ -166,19 +170,19 @@ EmbedChatAPI.initialize({
166
170
  ### Appearance Properties
167
171
  ```javascript
168
172
  EmbedChatAPI.initialize({
169
- // Colores
173
+ // Colors
170
174
  primaryColor: "#3b82f6", // Primary color (header, buttons, etc.)
171
- textColor: "#333333", // Color of the text of the messages
172
- bubbleUserColor: "#3b82f6", // Color of the background of the user's messages
173
- chatBackground: "#ffffff", // Color of the chat background
174
- footerColor: "#f3f4f6", // Color of the footer background
175
+ textColor: "#333333", // Message text color
176
+ bubbleUserColor: "#3b82f6", // User message bubble background
177
+ chatBackground: "#ffffff", // Chat background color
178
+ footerColor: "#f3f4f6", // Footer background color
175
179
 
176
180
  // Borders
177
181
  borderRadius: 12, // Border radius: number (px) or string
178
182
  border: "2px solid #3b82f6", // Custom border (CSS border)
179
183
  boxShadow: "0 10px 30px rgba(0,0,0,0.2)", // Custom shadow
180
184
 
181
- chatTransparent: false, // If true, the chat background is transparent
185
+ chatTransparent: false, // If true, chat background is transparent
182
186
  })
183
187
  ```
184
188
 
@@ -194,10 +198,10 @@ EmbedChatAPI.initialize({
194
198
  ```javascript
195
199
  EmbedChatAPI.initialize({
196
200
  input: {
197
- backgroundColor: "#ffffff", // Color of the input area background
198
- inputBorder: "2px solid #e5e7eb", // Border of the input field
199
- inputBorderRadius: "8px", // Border radius of the input
200
- iconColor: "#3b82f6" // Color of the send icon
201
+ backgroundColor: "#ffffff", // Input area background color
202
+ inputBorder: "2px solid #e5e7eb", // Input field border
203
+ inputBorderRadius: "8px", // Input border radius
204
+ iconColor: "#3b82f6" // Send icon color
201
205
  }
202
206
  })
203
207
  ```
@@ -268,27 +272,199 @@ EmbedChatAPI.initialize({
268
272
  |-----------|------|-----------|---------|-------------|
269
273
  | `elementId` | `string` | βœ… | - | ID of the HTML element where the chat will be mounted |
270
274
  | `apiKey` | `string` | βœ… | - | API key for the chat service |
271
- | `title` | `string` | ❌ | `"Chat"` | Title shown in the header of the chat |
272
- | `placeholder` | `string` | ❌ | `"Type your message..."` | Text placeholder of the input field |
275
+ | `title` | `string` | ❌ | `"Chat"` | Title shown in the chat header |
276
+ | `placeholder` | `string` | ❌ | `"Type your message..."` | Input field placeholder text |
273
277
  | `primaryColor` | `string` | ❌ | `"#3b82f6"` | Primary color (header, buttons, links) |
274
- | `avatar` | `string` | ❌ | - | URL of the bot's avatar (optional) |
278
+ | `avatar` | `string` | ❌ | - | Bot avatar URL (optional) |
275
279
  | `initialMessage` | `string` | ❌ | - | First message shown by the bot |
276
- | `footerText` | `string` | ❌ | - | Text of the footer (if provided, it is shown) |
277
- | `width` | `string \| number` | ❌ | `"100%"` | Width of the chat (px or CSS units) |
278
- | `height` | `string \| number` | ❌ | `400` | Height of the chat (px or CSS units) |
279
- | `maxWidth` | `string \| number` | ❌ | `"100%"` | Maximum width of the chat |
280
- | `maxHeight` | `string \| number` | ❌ | `"100vh"` | Maximum height of the chat |
281
- | `minWidth` | `string \| number` | ❌ | `280` | Minimum width of the chat |
282
- | `minHeight` | `string \| number` | ❌ | `300` | Minimum height of the chat |
280
+ | `footerText` | `string` | ❌ | - | Footer text (if provided, it is shown) |
281
+ | `width` | `string \| number` | ❌ | `"100%"` | Chat width (px or CSS units) |
282
+ | `height` | `string \| number` | ❌ | `400` | Chat height (px or CSS units) |
283
+ | `maxWidth` | `string \| number` | ❌ | `"100%"` | Maximum chat width |
284
+ | `maxHeight` | `string \| number` | ❌ | `"100vh"` | Maximum chat height |
285
+ | `minWidth` | `string \| number` | ❌ | `280` | Minimum chat width |
286
+ | `minHeight` | `string \| number` | ❌ | `300` | Minimum chat height |
283
287
  | `showHeader` | `boolean` | ❌ | `true` | Show/hide the header |
284
288
  | `showFooter` | `boolean` | ❌ | `true` | Show/hide the footer (if footerText is provided) |
285
- | `borderRadius` | `string \| number` | ❌ | `12` | Border radius of the container |
286
- | `border` | `string` | ❌ | `"1px solid #e5e7eb"` | Border of the container (CSS border) |
287
- | `boxShadow` | `string` | ❌ | `"0 10px 25px..."` | Shadow of the container |
288
- | `chatTransparent` | `boolean` | ❌ | `false` | If true, the chat background is transparent |
289
- | `chatBackground` | `string` | ❌ | `"#ffffff"` | Color of the chat background |
290
- | `textColor` | `string` | ❌ | - | Color of the text of the messages |
291
- | `bubbleUserColor` | `string` | ❌ | - | Color of the background of the user's messages |
292
- | `footerColor` | `string` | ❌ | - | Color of the footer background |
293
- | `input` | `EmbedChatInputConfig` | ❌ | - | Specific configuration of the input |
289
+ | `borderRadius` | `string \| number` | ❌ | `12` | Container border radius |
290
+ | `border` | `string` | ❌ | `"1px solid #e5e7eb"` | Container border (CSS border) |
291
+ | `boxShadow` | `string` | ❌ | `"0 10px 25px..."` | Container shadow |
292
+ | `chatTransparent` | `boolean` | ❌ | `false` | If true, chat background is transparent |
293
+ | `chatBackground` | `string` | ❌ | `"#ffffff"` | Chat background color |
294
+ | `textColor` | `string` | ❌ | - | Message text color |
295
+ | `bubbleUserColor` | `string` | ❌ | - | User message bubble background color |
296
+ | `footerColor` | `string` | ❌ | - | Footer background color |
297
+ | `input` | `EmbedChatInputConfig` | ❌ | - | Input-specific configuration |
294
298
  | `customCSS` | `string` | ❌ | - | Custom CSS for the chat |
299
+
300
+ ---
301
+
302
+ ## πŸ› οΈ Dynamic Control via API and Events
303
+
304
+ WebChat exposes a global API and custom events to dynamically control the position, padding, and visibility of the widget from anywhere in your app or from the browser console.
305
+
306
+ ### WebChat Global Methods
307
+
308
+ ```js
309
+ window.openWebChat(); // Open the floating chat
310
+ window.closeWebChat(); // Close the floating chat
311
+ window.toggleWebChat(); // Toggle open/close
312
+ window.unmountWebChat(); // Unmount the floating chat
313
+ window.mountWebChat(); // Mount the floating chat if it was unmounted
314
+ window.hideWebChat(); // Hide the chat (display: none)
315
+ window.showWebChat(); // Show the chat if it was hidden
316
+ window.injectWebChatCSS(css); // Inject custom CSS into the shadow DOM
317
+ window.removeWebChatCSS(); // Remove custom CSS
318
+ window.setWebChatPosition(obj); // Change position/padding dynamically
319
+ ```
320
+
321
+ ### EmbedChat Global Methods
322
+
323
+ ```js
324
+ window.unmountEmbedChat(elementId); // Unmount the EmbedChat instance for the given elementId
325
+ window.mountEmbedChat(elementId); // Mount the EmbedChat instance again (with the last used config)
326
+ ```
327
+
328
+ - `window.unmountEmbedChat(elementId)`: Unmounts the EmbedChat instance from the specified element. The last configuration is saved.
329
+ - `window.mountEmbedChat(elementId)`: Remounts the EmbedChat instance in the specified element using the last configuration used for that element. If no config was previously used, a warning is shown in the console.
330
+
331
+ #### Example
332
+
333
+ ```js
334
+ window.unmountEmbedChat('embed-small'); // Unmounts the chat from the element with id 'embed-small'
335
+ window.mountEmbedChat('embed-small'); // Remounts the chat in the same element with the last config
336
+ ```
337
+
338
+ ---
339
+
340
+ ### Change position and padding dynamically (WebChat)
341
+
342
+ #### 1. Change position and margin globally (flat)
343
+ ```js
344
+ window.setWebChatPosition({
345
+ position: 'bottom-left',
346
+ marginBottom: 40,
347
+ marginSide: 30
348
+ });
349
+ ```
350
+
351
+ #### 2. Change only for mobile
352
+ ```js
353
+ window.setWebChatPosition({
354
+ mobile: {
355
+ position: 'bottom-right',
356
+ marginBottom: 100,
357
+ marginSide: 20
358
+ }
359
+ });
360
+ ```
361
+
362
+ #### 3. Change only for desktop
363
+ ```js
364
+ window.setWebChatPosition({
365
+ desktop: {
366
+ position: 'bottom-left',
367
+ marginBottom: 60,
368
+ marginSide: 40
369
+ }
370
+ });
371
+ ```
372
+
373
+ #### 4. Change using device format
374
+ ```js
375
+ window.setWebChatPosition({
376
+ device: 'mobile',
377
+ marginBottom: 120,
378
+ marginSide: 15
379
+ });
380
+ ```
381
+
382
+ ### Use custom events (addCustomPadding and open/close control)
383
+
384
+ You can dispatch events to change padding/margin or open/close the chat from anywhere in your app:
385
+
386
+ #### 1. Open, close, or toggle the floating WebChat
387
+ ```js
388
+ window.dispatchEvent(new CustomEvent('openWebChatbot'));
389
+ window.dispatchEvent(new CustomEvent('closeWebChatbot'));
390
+ window.dispatchEvent(new CustomEvent('toggleWebChatbot'));
391
+ ```
392
+
393
+ #### 2. Change padding for both devices (flat)
394
+ ```js
395
+ window.dispatchEvent(new CustomEvent('addCustomPadding', { detail: { y: 100, x: 30 } }));
396
+ ```
397
+
398
+ #### 3. Change only for mobile
399
+ ```js
400
+ window.dispatchEvent(new CustomEvent('addCustomPadding', { detail: { device: 'mobile', marginBottom: 120, marginSide: 20 } }));
401
+ ```
402
+
403
+ #### 4. Change only for desktop
404
+ ```js
405
+ window.dispatchEvent(new CustomEvent('addCustomPadding', { detail: { device: 'desktop', marginBottom: 60, marginSide: 40 } }));
406
+ ```
407
+
408
+ #### 5. Change using nested object
409
+ ```js
410
+ window.dispatchEvent(new CustomEvent('addCustomPadding', { detail: {
411
+ mobile: { marginBottom: 90, marginSide: 10 },
412
+ desktop: { marginBottom: 50, marginSide: 30 }
413
+ }}));
414
+ ```
415
+
416
+ ### Accepted object formats
417
+
418
+ - **Flat:** `{ marginBottom, marginSide, position }` (applies to both if no override in mobile/desktop)
419
+ - **By device:** `{ device: 'mobile'|'desktop', marginBottom, marginSide }`
420
+ - **Nested:** `{ mobile: { ... }, desktop: { ... } }`
421
+ - **Alias:** `{ y, x }` (`y` β†’ marginBottom, `x` β†’ marginSide)
422
+
423
+ You can combine these formats as needed.
424
+
425
+ ### Inject and remove custom CSS in WebChat
426
+
427
+ You can inject hot CSS into the floating WebChat using the global API:
428
+
429
+ ```js
430
+ // Change the header background color
431
+ window.injectWebChatCSS(`
432
+ #notchatbot-webchat-header {
433
+ background: #111 !important;
434
+ color: #fff !important;
435
+ }
436
+ `);
437
+
438
+ // Hide the floating button
439
+ window.injectWebChatCSS(`#notchatbot-webchat-button { display: none !important; }`);
440
+
441
+ // Change the chat window width
442
+ window.injectWebChatCSS(`#notchatbot-webchat-window { width: 500px !important; }`);
443
+
444
+ // Change the floating button color
445
+ window.injectWebChatCSS(`#notchatbot-webchat-button { background: #f59e0b !important; }`);
446
+
447
+ // Remove all custom styles
448
+ window.removeWebChatCSS();
449
+ ```
450
+
451
+ #### Internal element IDs for WebChat
452
+
453
+ You can use these IDs to select and style specific parts of the widget:
454
+
455
+ - `#notchatbot-webchat-button` β€” Floating chat button
456
+ - `#notchatbot-webchat-header` β€” Chat window header
457
+ - `#notchatbot-webchat-window` β€” Main chat window
458
+
459
+ Example to change the header and button color:
460
+
461
+ ```js
462
+ window.injectWebChatCSS(`
463
+ #notchatbot-webchat-header { background: #222 !important; color: #fff !important; }
464
+ #notchatbot-webchat-button { background: #f59e0b !important; }
465
+ `);
466
+ ```
467
+
468
+ You can combine these selectors to fully customize the widget.
469
+
470
+ ---
@@ -1,4 +1,6 @@
1
1
  import { default as React } from 'react';
2
2
  import { ChatBotProps } from '../types';
3
- declare const ChatBot: React.FC<ChatBotProps>;
3
+ declare const ChatBot: React.FC<ChatBotProps & {
4
+ exposeControl?: (api: any) => void;
5
+ }>;
4
6
  export default ChatBot;
package/dist/types.d.ts CHANGED
@@ -85,9 +85,9 @@ export interface EmbedChatFooterProps {
85
85
  }
86
86
  export interface EmbedChatInstance {
87
87
  destroy: () => void;
88
- updateConfig: (newConfig: Partial<EmbedChatConfig>) => void;
89
- injectCSS: (css: string) => void;
90
- removeCustomCSS: () => void;
88
+ updateConfig?: (newConfig: Partial<EmbedChatConfig>) => void;
89
+ injectCSS?: (css: string) => void;
90
+ removeCustomCSS?: () => void;
91
91
  }
92
92
  export interface Message {
93
93
  id: string;
@@ -177,6 +177,13 @@ export interface WebChatInstance {
177
177
  root: any;
178
178
  destroy: () => void;
179
179
  getConversationId: () => string | null;
180
+ setIsOpen?: (open: boolean) => void;
181
+ updateConfig?: (newConfig: Partial<WebChatConfig>) => void;
182
+ setPosition?: (pos: Partial<WebChatConfig>) => void;
183
+ hide?: () => void;
184
+ show?: () => void;
185
+ injectCSS?: (css: string) => void;
186
+ removeCustomCSS?: () => void;
180
187
  }
181
188
  export interface WebChatAPI {
182
189
  initialize: (config?: Partial<WebChatConfig>) => WebChatInstance | null;