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