@developer.notchatbot/webchat 1.0.8 β†’ 1.0.9

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,734 +1,734 @@
1
- # πŸ”· WebChat Widget
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**.
4
-
5
- ## ✨ Features
6
-
7
- - **πŸ“¦ Single File Bundle**: Everything in one file - no separate CSS needed!
8
- - **πŸ”· TypeScript**: Full type safety with strict typing and excellent IntelliSense
9
- - **βš›οΈ React 18**: Component-based architecture for maintainability
10
- - **🎨 Tailwind CSS**: Utility-first styling with prefixed classes (`ncb-`)
11
- - **⚑ Vite**: Lightning-fast development and optimized builds
12
- - **πŸ“¦ pnpm**: Efficient package management and faster installs
13
- - **πŸ”§ Easy Integration**: Add to any website with just one script tag
14
- - **🎨 Modern Design**: Beautiful, responsive UI that works on all devices
15
- - **πŸ› οΈ Customizable**: Configure colors, text, and behavior to match your brand
16
- - **✨ Smooth Animations**: Typing indicators and smooth transitions
17
- - **πŸ“± Mobile Responsive**: Optimized for mobile and desktop
18
- - **πŸ”Œ API Ready**: Built-in support for chat API integration
19
- - **🚫 Zero Conflicts**: Prefixed CSS classes prevent style conflicts
20
- - **πŸ›‘οΈ Type Safe**: Catch errors at compile time with TypeScript
21
-
22
- ## πŸ“¦ Quick Start
23
-
24
- ### 1. Add the widget to your website
25
-
26
- ```html
27
- <div id="webchat-component"></div>
28
-
29
- <script src="https://your-cdn.com/webchat-bundle.min.umd.cjs"></script>
30
- <script>
31
- WebChat.initialize({
32
- title: "Customer Support",
33
- placeholder: "Ask us anything...",
34
- primaryColor: "#667eea"
35
- });
36
- </script>
37
- ```
38
-
39
- ### 2. That's it! πŸŽ‰
40
-
41
- The chatbot button will appear in the bottom-right corner of your page. CSS is automatically injected!
42
-
43
- ## βš™οΈ Configuration Options
44
-
45
- ```typescript
46
- interface WebChatConfig {
47
- title?: string; // Chat window title
48
- placeholder?: string; // Input placeholder text
49
- primaryColor?: string; // Primary theme color
50
- apiKey?: string; // Your chatbot UID (required for API)
51
- position?: 'bottom-right' | 'bottom-left'; // Widget position
52
- initialMessage?: string; // Custom initial bot message
53
- closeButtonIcon?: 'default' | 'text' | 'custom'; // Close button type
54
- closeButtonText?: string; // Text for close button (when type is 'text')
55
- closeButtonCustomIcon?: string; // Custom icon SVG or URL (when type is 'custom')
56
- marginBottom?: number; // Distance from bottom edge in pixels (default: 16)
57
- marginSide?: number; // Distance from left/right edge in pixels (default: 16)
58
- mobile?: WebChatPositionConfig; // Mobile-specific position settings
59
- desktop?: WebChatPositionConfig; // Desktop-specific position settings
60
- }
61
-
62
- interface WebChatPositionConfig {
63
- position?: 'bottom-right' | 'bottom-left';
64
- marginBottom?: number;
65
- marginSide?: number;
66
- }
67
-
68
- WebChat.initialize({
69
- title: "Chat Assistant",
70
- placeholder: "Type your message...",
71
- primaryColor: "#007bff",
72
- apiKey: "your-chatbot-uid", // Chatbot UID from admin panel
73
- position: "bottom-right",
74
- initialMessage: "Β‘Hola! πŸ‘‹ Soy tu asistente virtual. ΒΏEn quΓ© puedo ayudarte hoy?",
75
- closeButtonIcon: "default", // or "text" or "custom"
76
- marginBottom: 20, // Distance from bottom edge (default: 16px)
77
- marginSide: 20, // Distance from side edge (default: 16px)
78
- // Device-specific overrides
79
- mobile: {
80
- position: "bottom-left",
81
- marginBottom: 80,
82
- marginSide: 15
83
- },
84
- desktop: {
85
- position: "bottom-right",
86
- marginBottom: 30,
87
- marginSide: 30
88
- }
89
- });
90
- ```
91
-
92
- ## 🎨 Customization
93
-
94
- ### Colors
95
- ```javascript
96
- WebChat.initialize({
97
- primaryColor: "#ff6b6b", // Custom brand color
98
- // ... other options
99
- });
100
- ```
101
-
102
- ### API Integration
103
-
104
- The WebChat widget automatically detects the environment and uses the appropriate API endpoints:
105
-
106
- - **Development** (localhost): `http://localhost:3001/api/webchat`
107
- - **Production** (any other domain): `https://next.notchatbot.com/api/webchat`
108
-
109
- ```javascript
110
- WebChat.initialize({
111
- apiKey: "your-chatbot-uid", // Chatbot UID from your Next.js admin panel
112
- // Endpoints are automatically configured based on environment
113
- // No need to specify apiEndpoint manually
114
- });
115
- ```
116
-
117
- #### Manual Endpoint Override (Advanced)
118
- If you need to override the automatic endpoint detection:
119
-
120
- ```javascript
121
- // This is handled automatically, but you can check the environment:
122
- import { getChatEndpoint, getConversationEndpoint } from './src/config/endpoints';
123
-
124
- console.log('Chat endpoint:', getChatEndpoint());
125
- console.log('Conversation endpoint:', getConversationEndpoint());
126
- ```
127
-
128
- ### πŸ’¬ Initial Message Customization
129
- Customize the first message your users see when they open the chat:
130
-
131
- ```javascript
132
- WebChat.initialize({
133
- title: "MiTienda Support",
134
- // Custom welcome message with your brand's personality
135
- initialMessage: "Β‘Hola! πŸ‘‹ Soy el asistente de MiTienda.\n\nΒΏBuscas algΓΊn producto especΓ­fico? Β‘Estoy aquΓ­ para ayudarte!\n\nPuedes preguntarme sobre:\nβ€’ Productos disponibles\nβ€’ Precios y ofertas\nβ€’ EnvΓ­os y devoluciones\nβ€’ Soporte tΓ©cnico\n\nΒΏEn quΓ© puedo ayudarte hoy? 😊",
136
- apiKey: "your-api-key"
137
- });
138
- ```
139
-
140
- ### ❌ Close Button Customization
141
- Customize the appearance of the close button in the chat header:
142
-
143
- #### Option 1: Default X Icon (SVG)
144
- ```javascript
145
- WebChat.initialize({
146
- closeButtonIcon: "default" // Standard X icon
147
- });
148
- ```
149
-
150
- #### Option 2: Custom Text
151
- ```javascript
152
- WebChat.initialize({
153
- closeButtonIcon: "text",
154
- closeButtonText: "CERRAR" // or "βœ•", "CLOSE", etc.
155
- });
156
- ```
157
-
158
- #### Option 3: Custom SVG Icon
159
- ```javascript
160
- WebChat.initialize({
161
- closeButtonIcon: "custom",
162
- closeButtonCustomIcon: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>'
163
- });
164
- ```
165
-
166
- #### Option 4: Custom Icon from URL
167
- ```javascript
168
- WebChat.initialize({
169
- closeButtonIcon: "custom",
170
- closeButtonCustomIcon: "https://yoursite.com/icons/close-icon.svg"
171
- });
172
- ```
173
-
174
- ### πŸ“ Position and Margins Customization
175
- Control where the chat widget appears on the screen and how much space it has from the edges:
176
-
177
- #### Bottom Right Position (Default)
178
- ```javascript
179
- WebChat.initialize({
180
- position: "bottom-right",
181
- marginBottom: 20, // 20px from bottom edge
182
- marginSide: 25, // 25px from right edge
183
- apiKey: "your-api-key"
184
- });
185
- ```
186
-
187
- #### Bottom Left Position
188
- ```javascript
189
- WebChat.initialize({
190
- position: "bottom-left",
191
- marginBottom: 30, // 30px from bottom edge
192
- marginSide: 20, // 20px from left edge
193
- apiKey: "your-api-key"
194
- });
195
- ```
196
-
197
- #### Position Examples for Different Layouts
198
-
199
- **E-commerce Site (avoid cart button)**
200
- ```javascript
201
- WebChat.initialize({
202
- position: "bottom-left",
203
- marginBottom: 20,
204
- marginSide: 20,
205
- apiKey: "your-api-key"
206
- });
207
- ```
208
-
209
- **Corporate Website (professional look)**
210
- ```javascript
211
- WebChat.initialize({
212
- position: "bottom-right",
213
- marginBottom: 40, // More space from bottom
214
- marginSide: 30, // More space from side
215
- apiKey: "your-api-key"
216
- });
217
- ```
218
-
219
- **Mobile-First Design (more accessible)**
220
- ```javascript
221
- WebChat.initialize({
222
- position: "bottom-right",
223
- marginBottom: 80, // Avoid mobile navigation
224
- marginSide: 15, // Less space on mobile
225
- apiKey: "your-api-key"
226
- });
227
- ```
228
-
229
- ### πŸ’° Cost Optimization
230
- The WebChat widget is optimized to minimize API costs:
231
-
232
- - **Lazy Loading**: Conversation history is only fetched when the chat is opened, not on page load
233
- - **Smart Caching**: Once loaded, conversation history is cached to avoid duplicate fetches
234
- - **Conditional Fetching**: Only fetches when a conversation actually exists
235
-
236
- This ensures users can visit your e-commerce site without triggering unnecessary API calls.
237
-
238
- ### πŸ“±πŸ’» Device-Specific Configurations
239
- Configure different positions and margins for mobile and desktop devices:
240
-
241
- #### Complete Device-Specific Setup
242
- ```javascript
243
- WebChat.initialize({
244
- title: "Customer Support",
245
- apiKey: "your-api-key",
246
-
247
- // Global fallback settings (used if device-specific not provided)
248
- position: "bottom-right",
249
- marginBottom: 20,
250
- marginSide: 20,
251
-
252
- // Desktop-specific settings
253
- desktop: {
254
- position: "bottom-right",
255
- marginBottom: 30, // More space on desktop
256
- marginSide: 40 // More space from edge
257
- },
258
-
259
- // Mobile-specific settings
260
- mobile: {
261
- position: "bottom-left", // Different position on mobile
262
- marginBottom: 80, // Avoid mobile navigation bars
263
- marginSide: 15 // Less space on smaller screens
264
- }
265
- });
266
- ```
267
-
268
- #### E-commerce Site Example
269
- ```javascript
270
- WebChat.initialize({
271
- title: "Shopping Assistant",
272
- apiKey: "your-api-key",
273
-
274
- // Desktop: bottom-right (standard)
275
- desktop: {
276
- position: "bottom-right",
277
- marginBottom: 25,
278
- marginSide: 25
279
- },
280
-
281
- // Mobile: bottom-left (avoid cart/menu buttons)
282
- mobile: {
283
- position: "bottom-left",
284
- marginBottom: 90, // Clear mobile navigation
285
- marginSide: 15
286
- }
287
- });
288
- ```
289
-
290
- #### Corporate Website Example
291
- ```javascript
292
- WebChat.initialize({
293
- title: "Business Support",
294
- apiKey: "your-api-key",
295
-
296
- // Consistent position, different margins
297
- position: "bottom-right", // Global fallback
298
-
299
- desktop: {
300
- marginBottom: 40, // Professional spacing
301
- marginSide: 50
302
- },
303
-
304
- mobile: {
305
- marginBottom: 70, // Clear mobile UI elements
306
- marginSide: 20
307
- }
308
- });
309
- ```
310
-
311
- ## πŸ‘¨β€πŸ’» Developer Guide
312
-
313
- ### πŸš€ Getting Started
314
-
315
- #### Prerequisites
316
- - **Node.js 18+** (for modern React and TypeScript)
317
- - **pnpm 8+** (recommended package manager - faster than npm/yarn)
318
- - **Git** (for version control)
319
- - **VS Code** (recommended IDE with TypeScript support)
320
-
321
- #### Initial Setup
322
- ```bash
323
- # 1. Clone the repository
324
- git clone https://github.com/your-username/webchat-widget.git
325
- cd webchat-widget
326
-
327
- # 2. Install dependencies with pnpm (much faster than npm)
328
- pnpm install
329
-
330
- # 3. Start development server
331
- pnpm dev
332
- ```
333
-
334
- The development server will start at `http://localhost:3000` and automatically open `example.html`.
335
-
336
- ### πŸ”§ Development Workflow
337
-
338
- #### 1. **Understanding the Codebase Structure**
339
- ```
340
- src/
341
- β”œβ”€β”€ components/ # React TypeScript components
342
- β”‚ β”œβ”€β”€ ChatBot.tsx # Main container component
343
- β”‚ β”œβ”€β”€ ChatButton.tsx # Floating chat button
344
- β”‚ β”œβ”€β”€ ChatWindow.tsx # Chat window container
345
- β”‚ β”œβ”€β”€ ChatHeader.tsx # Window header with close button
346
- β”‚ β”œβ”€β”€ MessageList.tsx # Scrollable message list
347
- β”‚ β”œβ”€β”€ Message.tsx # Individual message bubble
348
- β”‚ β”œβ”€β”€ MessageInput.tsx # Input field with send button
349
- β”‚ └── TypingIndicator.tsx # Animated typing dots
350
- β”œβ”€β”€ types.ts # TypeScript interfaces and types
351
- β”œβ”€β”€ index.tsx # Main entry point (exports WebChat API)
352
- β”œβ”€β”€ vite-env.d.ts # Type declarations for Vite
353
- └── styles.css # Tailwind CSS directives
354
- ```
355
-
356
- #### 2. **Adding New Features**
357
-
358
- **Step 1: Update Types** (if needed)
359
- ```typescript
360
- // src/types.ts
361
- export interface NewFeatureProps {
362
- enabled: boolean;
363
- config?: SomeConfig;
364
- }
365
- ```
366
-
367
- **Step 2: Create/Modify Components**
368
- ```typescript
369
- // src/components/NewFeature.tsx
370
- import React from 'react';
371
- import type { NewFeatureProps } from '../types';
372
-
373
- const NewFeature: React.FC<NewFeatureProps> = ({ enabled, config }) => {
374
- // Component logic here
375
- return (
376
- <div className="nbc-new-feature">
377
- {/* Use nbc- prefix for all CSS classes */}
378
- </div>
379
- );
380
- };
381
-
382
- export default NewFeature;
383
- ```
384
-
385
- **Step 3: Add to Main Component**
386
- ```typescript
387
- // src/components/ChatBot.tsx
388
- import NewFeature from './NewFeature';
389
-
390
- // Use the new component in ChatBot
391
- ```
392
-
393
- #### 3. **Styling Guidelines**
394
-
395
- - **Always use `nbc-` prefix** for CSS classes to avoid conflicts
396
- - **Use Tailwind utilities** whenever possible
397
- - **Follow the existing pattern** for consistent styling
398
-
399
- ```tsx
400
- // βœ… Good - uses nbc- prefix
401
- <div className="nbc-bg-blue-500 nbc-text-white nbc-p-4">
402
-
403
- // ❌ Bad - no prefix, will conflict with host site
404
- <div className="bg-blue-500 text-white p-4">
405
- ```
406
-
407
- #### 4. **TypeScript Best Practices**
408
-
409
- - **Define interfaces** for all component props
410
- - **Use strict typing** for functions and variables
411
- - **Leverage IntelliSense** for better development experience
412
-
413
- ```typescript
414
- // βœ… Good - strict typing
415
- const handleMessage = (message: string): void => {
416
- // Function implementation
417
- };
418
-
419
- // ❌ Bad - no typing
420
- const handleMessage = (message) => {
421
- // Function implementation
422
- };
423
- ```
424
-
425
- ### πŸ—οΈ Building & Compilation
426
-
427
- #### Development Build
428
- ```bash
429
- # Start development server with hot reload
430
- pnpm dev
431
-
432
- # Access at: http://localhost:3000
433
- # Changes are reflected immediately
434
- ```
435
-
436
- #### Production Build
437
- ```bash
438
- # Build for production (TypeScript compilation + bundling)
439
- pnpm build
440
-
441
- # Output: dist/webchat-bundle.min.umd.cjs (single file)
442
- # Size: ~159KB (50KB gzipped)
443
- ```
444
-
445
- #### Build Process Explanation
446
- 1. **TypeScript Compilation** (`tsc`) - Type checking and compilation
447
- 2. **Vite Bundling** - Bundles React, CSS, and all dependencies
448
- 3. **CSS Injection** - Inlines CSS into JavaScript for single-file output
449
- 4. **Minification** - Optimizes and compresses the output
450
-
451
- ### πŸ§ͺ Testing the Compiled Version
452
-
453
- #### Option 1: Preview Server
454
- ```bash
455
- # Build and start preview server
456
- pnpm build
457
- pnpm preview
458
-
459
- # Access at: http://localhost:4173
460
- # Tests the actual production build
461
- ```
462
-
463
- #### Option 2: Local Testing
464
- ```bash
465
- # After building, test locally
466
- pnpm build
467
-
468
- # Open example/production.html in browser
469
- # Or serve with any static file server
470
- python3 -m http.server 8000
471
- # Then visit: http://localhost:8000/example/production.html
472
- ```
473
-
474
- #### Option 3: Integration Testing
475
- Create a test HTML file:
476
- ```html
477
- <!DOCTYPE html>
478
- <html>
479
- <head>
480
- <title>Widget Test</title>
481
- </head>
482
- <body>
483
- <h1>Testing WebChat Widget</h1>
484
- <div id="chat-test"></div>
485
-
486
- <!-- Load your built widget -->
487
- <script src="./dist/webchat-bundle.min.umd.cjs"></script>
488
- <script>
489
- // Test the widget
490
- WebChat.initialize({
491
- elementId: "chat-test",
492
- title: "Test Chat",
493
- placeholder: "Test message...",
494
- primaryColor: "#007bff"
495
- });
496
- </script>
497
- </body>
498
- </html>
499
- ```
500
-
501
- ### πŸ“¦ Publishing to npm
502
-
503
- #### 1. Prepare for Publishing
504
- ```bash
505
- # 1. Update version in package.json
506
- npm version patch # or minor, major
507
-
508
- # 2. Build the production version
509
- pnpm build
510
-
511
- # 3. Test the build
512
- pnpm preview
513
- ```
514
-
515
- #### 2. Configure package.json for npm
516
- ```json
517
- {
518
- "name": "@yourorg/webchat-widget",
519
- "version": "1.0.0",
520
- "description": "Embeddable React TypeScript chatbot widget",
521
- "main": "dist/webchat-bundle.min.umd.cjs",
522
- "types": "dist/types/index.d.ts",
523
- "files": [
524
- "dist",
525
- "README.md"
526
- ],
527
- "keywords": ["chatbot", "widget", "react", "typescript", "embeddable"],
528
- "repository": {
529
- "type": "git",
530
- "url": "https://github.com/yourorg/webchat-widget.git"
531
- },
532
- "publishConfig": {
533
- "access": "public"
534
- }
535
- }
536
- ```
537
-
538
- #### 3. Publish to npm
539
- ```bash
540
- # 1. Login to npm (if not already)
541
- npm login
542
-
543
- # 2. Publish the package
544
- npm publish
545
-
546
- # 3. Verify publication
547
- npm view @yourorg/webchat-widget
548
- ```
549
-
550
- #### 4. Using Published Package
551
- ```html
552
- <!-- From npm CDN -->
553
- <script src="https://unpkg.com/@yourorg/webchat-widget/dist/webchat-bundle.min.umd.cjs"></script>
554
-
555
- <!-- Or install via npm -->
556
- npm install @yourorg/webchat-widget
557
- ```
558
-
559
- ### 🌐 Hosting on unpkg
560
-
561
- #### Automatic unpkg Hosting
562
- Once published to npm, your package is automatically available on unpkg:
563
-
564
- ```html
565
- <!-- Latest version -->
566
- <script src="https://unpkg.com/@yourorg/webchat-widget"></script>
567
-
568
- <!-- Specific version -->
569
- <script src="https://unpkg.com/@yourorg/webchat-widget@1.0.0"></script>
570
-
571
- <!-- Direct file access -->
572
- <script src="https://unpkg.com/@yourorg/webchat-widget/dist/webchat-bundle.min.umd.cjs"></script>
573
- ```
574
-
575
- #### unpkg URLs Explained
576
- - `https://unpkg.com/package-name` - Latest version, main file
577
- - `https://unpkg.com/package-name@version` - Specific version
578
- - `https://unpkg.com/package-name/file-path` - Direct file access
579
- - `https://unpkg.com/package-name@version/file-path` - Version + file
580
-
581
- #### Real-world Integration Example
582
- ```html
583
- <!DOCTYPE html>
584
- <html lang="en">
585
- <head>
586
- <meta charset="UTF-8">
587
- <title>My Website with Chat</title>
588
- </head>
589
- <body>
590
- <h1>Welcome to My Website</h1>
591
- <p>Content goes here...</p>
592
-
593
- <!-- Chat widget integration -->
594
- <div id="customer-chat"></div>
595
-
596
- <!-- Load from unpkg -->
597
- <script src="https://unpkg.com/@yourorg/webchat-widget@latest"></script>
598
- <script>
599
- WebChat.initialize({
600
- elementId: "customer-chat",
601
- title: "Customer Support",
602
- placeholder: "How can we help you?",
603
- primaryColor: "#007bff",
604
- apiEndpoint: "https://your-api.com/chat",
605
- apiKey: "your-api-key"
606
- });
607
- </script>
608
- </body>
609
- </html>
610
- ```
611
-
612
- ### πŸš€ Deployment Workflow Summary
613
-
614
- ```bash
615
- # Complete workflow from development to deployment
616
- git checkout -b feature/new-feature
617
- # ... make changes ...
618
- git commit -m "Add new feature"
619
- git push origin feature/new-feature
620
- # ... create PR, review, merge ...
621
-
622
- # Deployment
623
- git checkout main
624
- git pull origin main
625
- npm version patch
626
- pnpm build
627
- npm publish
628
- git push --tags
629
-
630
- # Your widget is now available at:
631
- # https://unpkg.com/@yourorg/webchat-widget@latest
632
- ```
633
-
634
- ### πŸ› οΈ Troubleshooting
635
-
636
- #### Common Issues
637
-
638
- **TypeScript Errors**
639
- ```bash
640
- # Check TypeScript errors
641
- pnpm build # Will show TS errors
642
-
643
- # Fix common issues:
644
- # 1. Missing types - add to src/types.ts
645
- # 2. Import errors - check file extensions (.tsx)
646
- # 3. Strict mode - follow TypeScript strict rules
647
- ```
648
-
649
- **Build Issues**
650
- ```bash
651
- # Clear cache and rebuild
652
- rm -rf node_modules dist
653
- pnpm install
654
- pnpm build
655
- ```
656
-
657
- **CSS Conflicts**
658
- ```typescript
659
- // Always use nbc- prefix in className
660
- className="nbc-bg-blue-500 nbc-text-white"
661
- ```
662
-
663
- **unpkg Caching**
664
- ```bash
665
- # Force cache refresh
666
- https://unpkg.com/@yourorg/webchat-widget?t=timestamp
667
- ```
668
-
669
- ## πŸ› οΈ Development
670
-
671
- ### Prerequisites
672
- - Node.js 18+ (for modern React and TypeScript)
673
- - pnpm 8+ (recommended package manager)
674
-
675
- ### Setup
676
- ```bash
677
- # Clone the repository
678
- git clone https://github.com/your-username/webchat-widget.git
679
- cd webchat-widget
680
-
681
- # Install dependencies with pnpm
682
- pnpm install
683
-
684
- # Start development server with hot reload
685
- pnpm dev
686
- ```
687
-
688
- ### Build for Production
689
- ```bash
690
- pnpm build
691
- ```
692
-
693
- This creates a single optimized file in the `dist/` directory:
694
- - `webchat-bundle.min.umd.cjs` (159KB / 50KB gzipped) - Complete TypeScript bundle with React, Tailwind CSS, and all functionality
695
-
696
- ### Preview Production Build
697
- ```bash
698
- pnpm preview
699
- ```
700
-
701
- ## πŸ“ Project Structure
702
-
703
- ```
704
- webchat-widget/
705
- β”œβ”€β”€ src/
706
- β”‚ β”œβ”€β”€ components/ # React TypeScript components
707
- β”‚ β”‚ β”œβ”€β”€ ChatBot.tsx # Main chatbot component
708
- β”‚ β”‚ β”œβ”€β”€ ChatButton.tsx # Toggle button
709
- β”‚ β”‚ β”œβ”€β”€ ChatWindow.tsx # Chat window container
710
- β”‚ β”‚ β”œβ”€β”€ ChatHeader.tsx # Window header
711
- β”‚ β”‚ β”œβ”€β”€ MessageList.tsx # Message list with scroll
712
- β”‚ β”‚ β”œβ”€β”€ Message.tsx # Individual message
713
- β”‚ β”‚ β”œβ”€β”€ MessageInput.tsx # Input field
714
- β”‚ β”‚ └── TypingIndicator.tsx # Typing animation
715
- β”‚ β”œβ”€β”€ types.ts # TypeScript interfaces and types
716
- β”‚ β”œβ”€β”€ index.tsx # Main entry point (auto-injects CSS)
717
- β”‚ β”œβ”€β”€ vite-env.d.ts # Vite environment types
718
- β”‚ └── styles.css # Tailwind directives
719
- β”œβ”€β”€ example.html # Development example
720
- β”œβ”€β”€ example/
721
- β”‚ └── production.html # Production example
722
- β”œβ”€β”€ dist/ # Built files
723
- β”‚ └── webchat-bundle.min.umd.cjs # Single file TypeScript bundle
724
- β”œβ”€β”€ tsconfig.json # TypeScript configuration
725
- β”œβ”€β”€ tsconfig.node.json # Node TypeScript configuration
726
- β”œβ”€β”€ tailwind.config.js # Tailwind configuration
727
- β”œβ”€β”€ postcss.config.js # PostCSS configuration
728
- β”œβ”€β”€ vite.config.js # Vite configuration
729
- └── package.json # pnpm + React + TypeScript dependencies
730
- ```
731
-
732
- ## πŸ“„ License
733
-
1
+ # πŸ”· WebChat Widget
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**.
4
+
5
+ ## ✨ Features
6
+
7
+ - **πŸ“¦ Single File Bundle**: Everything in one file - no separate CSS needed!
8
+ - **πŸ”· TypeScript**: Full type safety with strict typing and excellent IntelliSense
9
+ - **βš›οΈ React 18**: Component-based architecture for maintainability
10
+ - **🎨 Tailwind CSS**: Utility-first styling with prefixed classes (`ncb-`)
11
+ - **⚑ Vite**: Lightning-fast development and optimized builds
12
+ - **πŸ“¦ pnpm**: Efficient package management and faster installs
13
+ - **πŸ”§ Easy Integration**: Add to any website with just one script tag
14
+ - **🎨 Modern Design**: Beautiful, responsive UI that works on all devices
15
+ - **πŸ› οΈ Customizable**: Configure colors, text, and behavior to match your brand
16
+ - **✨ Smooth Animations**: Typing indicators and smooth transitions
17
+ - **πŸ“± Mobile Responsive**: Optimized for mobile and desktop
18
+ - **πŸ”Œ API Ready**: Built-in support for chat API integration
19
+ - **🚫 Zero Conflicts**: Prefixed CSS classes prevent style conflicts
20
+ - **πŸ›‘οΈ Type Safe**: Catch errors at compile time with TypeScript
21
+
22
+ ## πŸ“¦ Quick Start
23
+
24
+ ### 1. Add the widget to your website
25
+
26
+ ```html
27
+ <div id="webchat-component"></div>
28
+
29
+ <script src="https://your-cdn.com/webchat-bundle.min.umd.cjs"></script>
30
+ <script>
31
+ WebChat.initialize({
32
+ title: "Customer Support",
33
+ placeholder: "Ask us anything...",
34
+ primaryColor: "#667eea"
35
+ });
36
+ </script>
37
+ ```
38
+
39
+ ### 2. That's it! πŸŽ‰
40
+
41
+ The chatbot button will appear in the bottom-right corner of your page. CSS is automatically injected!
42
+
43
+ ## βš™οΈ Configuration Options
44
+
45
+ ```typescript
46
+ interface WebChatConfig {
47
+ title?: string; // Chat window title
48
+ placeholder?: string; // Input placeholder text
49
+ primaryColor?: string; // Primary theme color
50
+ apiKey?: string; // Your chatbot UID (required for API)
51
+ position?: 'bottom-right' | 'bottom-left'; // Widget position
52
+ initialMessage?: string; // Custom initial bot message
53
+ closeButtonIcon?: 'default' | 'text' | 'custom'; // Close button type
54
+ closeButtonText?: string; // Text for close button (when type is 'text')
55
+ closeButtonCustomIcon?: string; // Custom icon SVG or URL (when type is 'custom')
56
+ marginBottom?: number; // Distance from bottom edge in pixels (default: 16)
57
+ marginSide?: number; // Distance from left/right edge in pixels (default: 16)
58
+ mobile?: WebChatPositionConfig; // Mobile-specific position settings
59
+ desktop?: WebChatPositionConfig; // Desktop-specific position settings
60
+ }
61
+
62
+ interface WebChatPositionConfig {
63
+ position?: 'bottom-right' | 'bottom-left';
64
+ marginBottom?: number;
65
+ marginSide?: number;
66
+ }
67
+
68
+ WebChat.initialize({
69
+ title: "Chat Assistant",
70
+ placeholder: "Type your message...",
71
+ primaryColor: "#007bff",
72
+ apiKey: "your-chatbot-uid", // Chatbot UID from admin panel
73
+ position: "bottom-right",
74
+ initialMessage: "Β‘Hola! πŸ‘‹ Soy tu asistente virtual. ΒΏEn quΓ© puedo ayudarte hoy?",
75
+ closeButtonIcon: "default", // or "text" or "custom"
76
+ marginBottom: 20, // Distance from bottom edge (default: 16px)
77
+ marginSide: 20, // Distance from side edge (default: 16px)
78
+ // Device-specific overrides
79
+ mobile: {
80
+ position: "bottom-left",
81
+ marginBottom: 80,
82
+ marginSide: 15
83
+ },
84
+ desktop: {
85
+ position: "bottom-right",
86
+ marginBottom: 30,
87
+ marginSide: 30
88
+ }
89
+ });
90
+ ```
91
+
92
+ ## 🎨 Customization
93
+
94
+ ### Colors
95
+ ```javascript
96
+ WebChat.initialize({
97
+ primaryColor: "#ff6b6b", // Custom brand color
98
+ // ... other options
99
+ });
100
+ ```
101
+
102
+ ### API Integration
103
+
104
+ The WebChat widget automatically detects the environment and uses the appropriate API endpoints:
105
+
106
+ - **Development** (localhost): `http://localhost:3001/api/webchat`
107
+ - **Production** (any other domain): `https://next.notchatbot.com/api/webchat`
108
+
109
+ ```javascript
110
+ WebChat.initialize({
111
+ apiKey: "your-chatbot-uid", // Chatbot UID from your Next.js admin panel
112
+ // Endpoints are automatically configured based on environment
113
+ // No need to specify apiEndpoint manually
114
+ });
115
+ ```
116
+
117
+ #### Manual Endpoint Override (Advanced)
118
+ If you need to override the automatic endpoint detection:
119
+
120
+ ```javascript
121
+ // This is handled automatically, but you can check the environment:
122
+ import { getChatEndpoint, getConversationEndpoint } from './src/config/endpoints';
123
+
124
+ console.log('Chat endpoint:', getChatEndpoint());
125
+ console.log('Conversation endpoint:', getConversationEndpoint());
126
+ ```
127
+
128
+ ### πŸ’¬ Initial Message Customization
129
+ Customize the first message your users see when they open the chat:
130
+
131
+ ```javascript
132
+ WebChat.initialize({
133
+ title: "MiTienda Support",
134
+ // Custom welcome message with your brand's personality
135
+ initialMessage: "Β‘Hola! πŸ‘‹ Soy el asistente de MiTienda.\n\nΒΏBuscas algΓΊn producto especΓ­fico? Β‘Estoy aquΓ­ para ayudarte!\n\nPuedes preguntarme sobre:\nβ€’ Productos disponibles\nβ€’ Precios y ofertas\nβ€’ EnvΓ­os y devoluciones\nβ€’ Soporte tΓ©cnico\n\nΒΏEn quΓ© puedo ayudarte hoy? 😊",
136
+ apiKey: "your-api-key"
137
+ });
138
+ ```
139
+
140
+ ### ❌ Close Button Customization
141
+ Customize the appearance of the close button in the chat header:
142
+
143
+ #### Option 1: Default X Icon (SVG)
144
+ ```javascript
145
+ WebChat.initialize({
146
+ closeButtonIcon: "default" // Standard X icon
147
+ });
148
+ ```
149
+
150
+ #### Option 2: Custom Text
151
+ ```javascript
152
+ WebChat.initialize({
153
+ closeButtonIcon: "text",
154
+ closeButtonText: "CERRAR" // or "βœ•", "CLOSE", etc.
155
+ });
156
+ ```
157
+
158
+ #### Option 3: Custom SVG Icon
159
+ ```javascript
160
+ WebChat.initialize({
161
+ closeButtonIcon: "custom",
162
+ closeButtonCustomIcon: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>'
163
+ });
164
+ ```
165
+
166
+ #### Option 4: Custom Icon from URL
167
+ ```javascript
168
+ WebChat.initialize({
169
+ closeButtonIcon: "custom",
170
+ closeButtonCustomIcon: "https://yoursite.com/icons/close-icon.svg"
171
+ });
172
+ ```
173
+
174
+ ### πŸ“ Position and Margins Customization
175
+ Control where the chat widget appears on the screen and how much space it has from the edges:
176
+
177
+ #### Bottom Right Position (Default)
178
+ ```javascript
179
+ WebChat.initialize({
180
+ position: "bottom-right",
181
+ marginBottom: 20, // 20px from bottom edge
182
+ marginSide: 25, // 25px from right edge
183
+ apiKey: "your-api-key"
184
+ });
185
+ ```
186
+
187
+ #### Bottom Left Position
188
+ ```javascript
189
+ WebChat.initialize({
190
+ position: "bottom-left",
191
+ marginBottom: 30, // 30px from bottom edge
192
+ marginSide: 20, // 20px from left edge
193
+ apiKey: "your-api-key"
194
+ });
195
+ ```
196
+
197
+ #### Position Examples for Different Layouts
198
+
199
+ **E-commerce Site (avoid cart button)**
200
+ ```javascript
201
+ WebChat.initialize({
202
+ position: "bottom-left",
203
+ marginBottom: 20,
204
+ marginSide: 20,
205
+ apiKey: "your-api-key"
206
+ });
207
+ ```
208
+
209
+ **Corporate Website (professional look)**
210
+ ```javascript
211
+ WebChat.initialize({
212
+ position: "bottom-right",
213
+ marginBottom: 40, // More space from bottom
214
+ marginSide: 30, // More space from side
215
+ apiKey: "your-api-key"
216
+ });
217
+ ```
218
+
219
+ **Mobile-First Design (more accessible)**
220
+ ```javascript
221
+ WebChat.initialize({
222
+ position: "bottom-right",
223
+ marginBottom: 80, // Avoid mobile navigation
224
+ marginSide: 15, // Less space on mobile
225
+ apiKey: "your-api-key"
226
+ });
227
+ ```
228
+
229
+ ### πŸ’° Cost Optimization
230
+ The WebChat widget is optimized to minimize API costs:
231
+
232
+ - **Lazy Loading**: Conversation history is only fetched when the chat is opened, not on page load
233
+ - **Smart Caching**: Once loaded, conversation history is cached to avoid duplicate fetches
234
+ - **Conditional Fetching**: Only fetches when a conversation actually exists
235
+
236
+ This ensures users can visit your e-commerce site without triggering unnecessary API calls.
237
+
238
+ ### πŸ“±πŸ’» Device-Specific Configurations
239
+ Configure different positions and margins for mobile and desktop devices:
240
+
241
+ #### Complete Device-Specific Setup
242
+ ```javascript
243
+ WebChat.initialize({
244
+ title: "Customer Support",
245
+ apiKey: "your-api-key",
246
+
247
+ // Global fallback settings (used if device-specific not provided)
248
+ position: "bottom-right",
249
+ marginBottom: 20,
250
+ marginSide: 20,
251
+
252
+ // Desktop-specific settings
253
+ desktop: {
254
+ position: "bottom-right",
255
+ marginBottom: 30, // More space on desktop
256
+ marginSide: 40 // More space from edge
257
+ },
258
+
259
+ // Mobile-specific settings
260
+ mobile: {
261
+ position: "bottom-left", // Different position on mobile
262
+ marginBottom: 80, // Avoid mobile navigation bars
263
+ marginSide: 15 // Less space on smaller screens
264
+ }
265
+ });
266
+ ```
267
+
268
+ #### E-commerce Site Example
269
+ ```javascript
270
+ WebChat.initialize({
271
+ title: "Shopping Assistant",
272
+ apiKey: "your-api-key",
273
+
274
+ // Desktop: bottom-right (standard)
275
+ desktop: {
276
+ position: "bottom-right",
277
+ marginBottom: 25,
278
+ marginSide: 25
279
+ },
280
+
281
+ // Mobile: bottom-left (avoid cart/menu buttons)
282
+ mobile: {
283
+ position: "bottom-left",
284
+ marginBottom: 90, // Clear mobile navigation
285
+ marginSide: 15
286
+ }
287
+ });
288
+ ```
289
+
290
+ #### Corporate Website Example
291
+ ```javascript
292
+ WebChat.initialize({
293
+ title: "Business Support",
294
+ apiKey: "your-api-key",
295
+
296
+ // Consistent position, different margins
297
+ position: "bottom-right", // Global fallback
298
+
299
+ desktop: {
300
+ marginBottom: 40, // Professional spacing
301
+ marginSide: 50
302
+ },
303
+
304
+ mobile: {
305
+ marginBottom: 70, // Clear mobile UI elements
306
+ marginSide: 20
307
+ }
308
+ });
309
+ ```
310
+
311
+ ## πŸ‘¨β€πŸ’» Developer Guide
312
+
313
+ ### πŸš€ Getting Started
314
+
315
+ #### Prerequisites
316
+ - **Node.js 18+** (for modern React and TypeScript)
317
+ - **pnpm 8+** (recommended package manager - faster than npm/yarn)
318
+ - **Git** (for version control)
319
+ - **VS Code** (recommended IDE with TypeScript support)
320
+
321
+ #### Initial Setup
322
+ ```bash
323
+ # 1. Clone the repository
324
+ git clone https://github.com/your-username/webchat-widget.git
325
+ cd webchat-widget
326
+
327
+ # 2. Install dependencies with pnpm (much faster than npm)
328
+ pnpm install
329
+
330
+ # 3. Start development server
331
+ pnpm dev
332
+ ```
333
+
334
+ The development server will start at `http://localhost:3000` and automatically open `example.html`.
335
+
336
+ ### πŸ”§ Development Workflow
337
+
338
+ #### 1. **Understanding the Codebase Structure**
339
+ ```
340
+ src/
341
+ β”œβ”€β”€ components/ # React TypeScript components
342
+ β”‚ β”œβ”€β”€ ChatBot.tsx # Main container component
343
+ β”‚ β”œβ”€β”€ ChatButton.tsx # Floating chat button
344
+ β”‚ β”œβ”€β”€ ChatWindow.tsx # Chat window container
345
+ β”‚ β”œβ”€β”€ ChatHeader.tsx # Window header with close button
346
+ β”‚ β”œβ”€β”€ MessageList.tsx # Scrollable message list
347
+ β”‚ β”œβ”€β”€ Message.tsx # Individual message bubble
348
+ β”‚ β”œβ”€β”€ MessageInput.tsx # Input field with send button
349
+ β”‚ └── TypingIndicator.tsx # Animated typing dots
350
+ β”œβ”€β”€ types.ts # TypeScript interfaces and types
351
+ β”œβ”€β”€ index.tsx # Main entry point (exports WebChat API)
352
+ β”œβ”€β”€ vite-env.d.ts # Type declarations for Vite
353
+ └── styles.css # Tailwind CSS directives
354
+ ```
355
+
356
+ #### 2. **Adding New Features**
357
+
358
+ **Step 1: Update Types** (if needed)
359
+ ```typescript
360
+ // src/types.ts
361
+ export interface NewFeatureProps {
362
+ enabled: boolean;
363
+ config?: SomeConfig;
364
+ }
365
+ ```
366
+
367
+ **Step 2: Create/Modify Components**
368
+ ```typescript
369
+ // src/components/NewFeature.tsx
370
+ import React from 'react';
371
+ import type { NewFeatureProps } from '../types';
372
+
373
+ const NewFeature: React.FC<NewFeatureProps> = ({ enabled, config }) => {
374
+ // Component logic here
375
+ return (
376
+ <div className="nbc-new-feature">
377
+ {/* Use nbc- prefix for all CSS classes */}
378
+ </div>
379
+ );
380
+ };
381
+
382
+ export default NewFeature;
383
+ ```
384
+
385
+ **Step 3: Add to Main Component**
386
+ ```typescript
387
+ // src/components/ChatBot.tsx
388
+ import NewFeature from './NewFeature';
389
+
390
+ // Use the new component in ChatBot
391
+ ```
392
+
393
+ #### 3. **Styling Guidelines**
394
+
395
+ - **Always use `nbc-` prefix** for CSS classes to avoid conflicts
396
+ - **Use Tailwind utilities** whenever possible
397
+ - **Follow the existing pattern** for consistent styling
398
+
399
+ ```tsx
400
+ // βœ… Good - uses nbc- prefix
401
+ <div className="nbc-bg-blue-500 nbc-text-white nbc-p-4">
402
+
403
+ // ❌ Bad - no prefix, will conflict with host site
404
+ <div className="bg-blue-500 text-white p-4">
405
+ ```
406
+
407
+ #### 4. **TypeScript Best Practices**
408
+
409
+ - **Define interfaces** for all component props
410
+ - **Use strict typing** for functions and variables
411
+ - **Leverage IntelliSense** for better development experience
412
+
413
+ ```typescript
414
+ // βœ… Good - strict typing
415
+ const handleMessage = (message: string): void => {
416
+ // Function implementation
417
+ };
418
+
419
+ // ❌ Bad - no typing
420
+ const handleMessage = (message) => {
421
+ // Function implementation
422
+ };
423
+ ```
424
+
425
+ ### πŸ—οΈ Building & Compilation
426
+
427
+ #### Development Build
428
+ ```bash
429
+ # Start development server with hot reload
430
+ pnpm dev
431
+
432
+ # Access at: http://localhost:3000
433
+ # Changes are reflected immediately
434
+ ```
435
+
436
+ #### Production Build
437
+ ```bash
438
+ # Build for production (TypeScript compilation + bundling)
439
+ pnpm build
440
+
441
+ # Output: dist/webchat-bundle.min.umd.cjs (single file)
442
+ # Size: ~159KB (50KB gzipped)
443
+ ```
444
+
445
+ #### Build Process Explanation
446
+ 1. **TypeScript Compilation** (`tsc`) - Type checking and compilation
447
+ 2. **Vite Bundling** - Bundles React, CSS, and all dependencies
448
+ 3. **CSS Injection** - Inlines CSS into JavaScript for single-file output
449
+ 4. **Minification** - Optimizes and compresses the output
450
+
451
+ ### πŸ§ͺ Testing the Compiled Version
452
+
453
+ #### Option 1: Preview Server
454
+ ```bash
455
+ # Build and start preview server
456
+ pnpm build
457
+ pnpm preview
458
+
459
+ # Access at: http://localhost:4173
460
+ # Tests the actual production build
461
+ ```
462
+
463
+ #### Option 2: Local Testing
464
+ ```bash
465
+ # After building, test locally
466
+ pnpm build
467
+
468
+ # Open example/production.html in browser
469
+ # Or serve with any static file server
470
+ python3 -m http.server 8000
471
+ # Then visit: http://localhost:8000/example/production.html
472
+ ```
473
+
474
+ #### Option 3: Integration Testing
475
+ Create a test HTML file:
476
+ ```html
477
+ <!DOCTYPE html>
478
+ <html>
479
+ <head>
480
+ <title>Widget Test</title>
481
+ </head>
482
+ <body>
483
+ <h1>Testing WebChat Widget</h1>
484
+ <div id="chat-test"></div>
485
+
486
+ <!-- Load your built widget -->
487
+ <script src="./dist/webchat-bundle.min.umd.cjs"></script>
488
+ <script>
489
+ // Test the widget
490
+ WebChat.initialize({
491
+ elementId: "chat-test",
492
+ title: "Test Chat",
493
+ placeholder: "Test message...",
494
+ primaryColor: "#007bff"
495
+ });
496
+ </script>
497
+ </body>
498
+ </html>
499
+ ```
500
+
501
+ ### πŸ“¦ Publishing to npm
502
+
503
+ #### 1. Prepare for Publishing
504
+ ```bash
505
+ # 1. Update version in package.json
506
+ npm version patch # or minor, major
507
+
508
+ # 2. Build the production version
509
+ pnpm build
510
+
511
+ # 3. Test the build
512
+ pnpm preview
513
+ ```
514
+
515
+ #### 2. Configure package.json for npm
516
+ ```json
517
+ {
518
+ "name": "@yourorg/webchat-widget",
519
+ "version": "1.0.0",
520
+ "description": "Embeddable React TypeScript chatbot widget",
521
+ "main": "dist/webchat-bundle.min.umd.cjs",
522
+ "types": "dist/types/index.d.ts",
523
+ "files": [
524
+ "dist",
525
+ "README.md"
526
+ ],
527
+ "keywords": ["chatbot", "widget", "react", "typescript", "embeddable"],
528
+ "repository": {
529
+ "type": "git",
530
+ "url": "https://github.com/yourorg/webchat-widget.git"
531
+ },
532
+ "publishConfig": {
533
+ "access": "public"
534
+ }
535
+ }
536
+ ```
537
+
538
+ #### 3. Publish to npm
539
+ ```bash
540
+ # 1. Login to npm (if not already)
541
+ npm login
542
+
543
+ # 2. Publish the package
544
+ npm publish
545
+
546
+ # 3. Verify publication
547
+ npm view @yourorg/webchat-widget
548
+ ```
549
+
550
+ #### 4. Using Published Package
551
+ ```html
552
+ <!-- From npm CDN -->
553
+ <script src="https://unpkg.com/@yourorg/webchat-widget/dist/webchat-bundle.min.umd.cjs"></script>
554
+
555
+ <!-- Or install via npm -->
556
+ npm install @yourorg/webchat-widget
557
+ ```
558
+
559
+ ### 🌐 Hosting on unpkg
560
+
561
+ #### Automatic unpkg Hosting
562
+ Once published to npm, your package is automatically available on unpkg:
563
+
564
+ ```html
565
+ <!-- Latest version -->
566
+ <script src="https://unpkg.com/@yourorg/webchat-widget"></script>
567
+
568
+ <!-- Specific version -->
569
+ <script src="https://unpkg.com/@yourorg/webchat-widget@1.0.0"></script>
570
+
571
+ <!-- Direct file access -->
572
+ <script src="https://unpkg.com/@yourorg/webchat-widget/dist/webchat-bundle.min.umd.cjs"></script>
573
+ ```
574
+
575
+ #### unpkg URLs Explained
576
+ - `https://unpkg.com/package-name` - Latest version, main file
577
+ - `https://unpkg.com/package-name@version` - Specific version
578
+ - `https://unpkg.com/package-name/file-path` - Direct file access
579
+ - `https://unpkg.com/package-name@version/file-path` - Version + file
580
+
581
+ #### Real-world Integration Example
582
+ ```html
583
+ <!DOCTYPE html>
584
+ <html lang="en">
585
+ <head>
586
+ <meta charset="UTF-8">
587
+ <title>My Website with Chat</title>
588
+ </head>
589
+ <body>
590
+ <h1>Welcome to My Website</h1>
591
+ <p>Content goes here...</p>
592
+
593
+ <!-- Chat widget integration -->
594
+ <div id="customer-chat"></div>
595
+
596
+ <!-- Load from unpkg -->
597
+ <script src="https://unpkg.com/@yourorg/webchat-widget@latest"></script>
598
+ <script>
599
+ WebChat.initialize({
600
+ elementId: "customer-chat",
601
+ title: "Customer Support",
602
+ placeholder: "How can we help you?",
603
+ primaryColor: "#007bff",
604
+ apiEndpoint: "https://your-api.com/chat",
605
+ apiKey: "your-api-key"
606
+ });
607
+ </script>
608
+ </body>
609
+ </html>
610
+ ```
611
+
612
+ ### πŸš€ Deployment Workflow Summary
613
+
614
+ ```bash
615
+ # Complete workflow from development to deployment
616
+ git checkout -b feature/new-feature
617
+ # ... make changes ...
618
+ git commit -m "Add new feature"
619
+ git push origin feature/new-feature
620
+ # ... create PR, review, merge ...
621
+
622
+ # Deployment
623
+ git checkout main
624
+ git pull origin main
625
+ npm version patch
626
+ pnpm build
627
+ npm publish
628
+ git push --tags
629
+
630
+ # Your widget is now available at:
631
+ # https://unpkg.com/@yourorg/webchat-widget@latest
632
+ ```
633
+
634
+ ### πŸ› οΈ Troubleshooting
635
+
636
+ #### Common Issues
637
+
638
+ **TypeScript Errors**
639
+ ```bash
640
+ # Check TypeScript errors
641
+ pnpm build # Will show TS errors
642
+
643
+ # Fix common issues:
644
+ # 1. Missing types - add to src/types.ts
645
+ # 2. Import errors - check file extensions (.tsx)
646
+ # 3. Strict mode - follow TypeScript strict rules
647
+ ```
648
+
649
+ **Build Issues**
650
+ ```bash
651
+ # Clear cache and rebuild
652
+ rm -rf node_modules dist
653
+ pnpm install
654
+ pnpm build
655
+ ```
656
+
657
+ **CSS Conflicts**
658
+ ```typescript
659
+ // Always use nbc- prefix in className
660
+ className="nbc-bg-blue-500 nbc-text-white"
661
+ ```
662
+
663
+ **unpkg Caching**
664
+ ```bash
665
+ # Force cache refresh
666
+ https://unpkg.com/@yourorg/webchat-widget?t=timestamp
667
+ ```
668
+
669
+ ## πŸ› οΈ Development
670
+
671
+ ### Prerequisites
672
+ - Node.js 18+ (for modern React and TypeScript)
673
+ - pnpm 8+ (recommended package manager)
674
+
675
+ ### Setup
676
+ ```bash
677
+ # Clone the repository
678
+ git clone https://github.com/your-username/webchat-widget.git
679
+ cd webchat-widget
680
+
681
+ # Install dependencies with pnpm
682
+ pnpm install
683
+
684
+ # Start development server with hot reload
685
+ pnpm dev
686
+ ```
687
+
688
+ ### Build for Production
689
+ ```bash
690
+ pnpm build
691
+ ```
692
+
693
+ This creates a single optimized file in the `dist/` directory:
694
+ - `webchat-bundle.min.umd.cjs` (159KB / 50KB gzipped) - Complete TypeScript bundle with React, Tailwind CSS, and all functionality
695
+
696
+ ### Preview Production Build
697
+ ```bash
698
+ pnpm preview
699
+ ```
700
+
701
+ ## πŸ“ Project Structure
702
+
703
+ ```
704
+ webchat-widget/
705
+ β”œβ”€β”€ src/
706
+ β”‚ β”œβ”€β”€ components/ # React TypeScript components
707
+ β”‚ β”‚ β”œβ”€β”€ ChatBot.tsx # Main chatbot component
708
+ β”‚ β”‚ β”œβ”€β”€ ChatButton.tsx # Toggle button
709
+ β”‚ β”‚ β”œβ”€β”€ ChatWindow.tsx # Chat window container
710
+ β”‚ β”‚ β”œβ”€β”€ ChatHeader.tsx # Window header
711
+ β”‚ β”‚ β”œβ”€β”€ MessageList.tsx # Message list with scroll
712
+ β”‚ β”‚ β”œβ”€β”€ Message.tsx # Individual message
713
+ β”‚ β”‚ β”œβ”€β”€ MessageInput.tsx # Input field
714
+ β”‚ β”‚ └── TypingIndicator.tsx # Typing animation
715
+ β”‚ β”œβ”€β”€ types.ts # TypeScript interfaces and types
716
+ β”‚ β”œβ”€β”€ index.tsx # Main entry point (auto-injects CSS)
717
+ β”‚ β”œβ”€β”€ vite-env.d.ts # Vite environment types
718
+ β”‚ └── styles.css # Tailwind directives
719
+ β”œβ”€β”€ example.html # Development example
720
+ β”œβ”€β”€ example/
721
+ β”‚ └── production.html # Production example
722
+ β”œβ”€β”€ dist/ # Built files
723
+ β”‚ └── webchat-bundle.min.umd.cjs # Single file TypeScript bundle
724
+ β”œβ”€β”€ tsconfig.json # TypeScript configuration
725
+ β”œβ”€β”€ tsconfig.node.json # Node TypeScript configuration
726
+ β”œβ”€β”€ tailwind.config.js # Tailwind configuration
727
+ β”œβ”€β”€ postcss.config.js # PostCSS configuration
728
+ β”œβ”€β”€ vite.config.js # Vite configuration
729
+ └── package.json # pnpm + React + TypeScript dependencies
730
+ ```
731
+
732
+ ## πŸ“„ License
733
+
734
734
  MIT License - see the [LICENSE](LICENSE) file for details.