@schmitech/chatbot-widget 0.3.4 โ†’ 0.3.6

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,203 +1,265 @@
1
- # ๐Ÿ’ฌ Chatbot Widget
1
+ # How to Use the Chatbot Widget
2
2
 
3
- A simple, reusable chatbot widget seamlessly integrated into any website with minimal effort.
3
+ This guide will help you integrate the chatbot widget into your website with minimal effort.
4
4
 
5
- ---
5
+ ## Quick Start
6
6
 
7
- ## ๐ŸŒŸ Key Features
7
+ ### 1. Include the Widget Files
8
8
 
9
- - ๐Ÿš€ **Quick Integration:** One-line JavaScript integration
10
- - ๐Ÿ“ฑ **Responsive Design:** Mobile-friendly and adaptive layout
11
- - ๐ŸŽจ **Customizable Appearance:** Easy theme adjustments
12
- - ๐Ÿ“ **Rich Text:** Supports Markdown and automatic link formatting
13
- - ๐Ÿ–ฑ๏ธ **User-Friendly UI:** Scrollable conversation view with "scroll to top" shortcut
14
- - ๐Ÿงน **Clear Conversation:** Reset chat with a single click
9
+ Choose one of these methods to include the widget:
15
10
 
16
- ---
17
-
18
- ## ๐Ÿ› ๏ธ Installation
19
-
20
- ### โœ… Prerequisites
21
- - Node.js 18+ and npm
22
-
23
- ### ๐Ÿ“ฆ Setup Instructions
24
-
25
- 1. **Clone Repository**
26
-
27
- ```bash
28
- git https://github.com/schmitech/orbit.git
29
- cd orbit/widget
30
- ```
31
-
32
- 2. **Install & Build API**
33
-
34
- ```bash
35
- cd api
36
- npm install
37
- npm run build
38
- ```
39
-
40
- 3. **Install & Build Widget**
41
-
42
- ```bash
43
- cd ../widget
44
- npm install
45
- npm run build
46
- npm run build:bundle
47
- ```
48
-
49
- The build outputs are located in `widget/dist`:
50
- - `chatbot-widget.bundle.js` (JS + CSS combined, recommended)
51
- - `chatbot-widget.umd.js` (JS only, UMD)
52
- - `chatbot-widget.css` (CSS only)
53
-
54
- ---
55
-
56
- ## ๐ŸŽจ Customization
57
-
58
- See `demo.html` for customization examples:
59
-
60
- ```bash
61
- python3 -m http.server 8080
62
- ```
63
-
64
- ---
65
-
66
- ## ๐Ÿšข Deployment
67
-
68
- 1. Host `chatbot-widget.bundle.js` on a CDN or server.
69
- 2. Update your HTML with the script reference.
70
- 3. Ensure your chatbot API URL is accessible.
71
-
72
- ---
73
-
74
- ## โš™๏ธ Widget API Reference
75
-
76
- ### `initChatbotWidget(config)`
77
- Initializes widget configuration.
78
-
79
- | Parameter | Description | Required |
80
- |-----------|-------------|----------|
81
- | `apiUrl` | URL of chatbot API | โœ… Yes |
82
- | `apiKey` | API key for authentication | โœ… Yes |
83
- | `containerSelector` | CSS selector for widget container | โŒ No (Defaults to body) |
84
-
85
- Example configuration:
86
- ```javascript
87
- initChatbotWidget({
88
- apiUrl: 'https://your-api-url.com',
89
- apiKey: 'your-api-key',
90
- containerSelector: '#chat-container'
91
- });
11
+ **Option 1 - All-in-one bundle (Recommended):**
12
+ ```html
13
+ <script src="https://unpkg.com/@schmitech/chatbot-widget@latest/dist/chatbot-widget.bundle.js"></script>
92
14
  ```
93
15
 
94
- ---
95
-
96
- ## ๐Ÿง‘โ€๐Ÿ’ป Development Commands
97
-
98
- ```bash
99
- # Development server
100
- npm run dev
101
-
102
- # Code linting
103
- npm run lint
104
-
105
- # Production builds
106
- npm run build
107
- npm run build:bundle
108
-
109
- # Preview build
110
- npm run preview
16
+ **Option 2 - Separate files:**
17
+ ```html
18
+ <script src="https://unpkg.com/@schmitech/chatbot-widget@latest/dist/chatbot-widget.umd.js"></script>
19
+ <link rel="stylesheet" href="https://unpkg.com/@schmitech/chatbot-widget@latest/dist/chatbot-widget.css">
111
20
  ```
112
21
 
113
- ---
114
-
115
- ## ๐Ÿ“ค Publish to npm
22
+ ### 2. Initialize the Widget
116
23
 
117
- **Build package:**
24
+ Add this code to your website:
118
25
 
119
- ```bash
120
- npm run build
121
- ```
122
-
123
- **Test locally (optional):**
124
-
125
- ```bash
126
- npm pack --dry-run
26
+ ```html
27
+ <script>
28
+ window.addEventListener('load', function() {
29
+ window.initChatbotWidget({
30
+ apiUrl: 'https://your-api-url.com', // Your chatbot API endpoint
31
+ apiKey: 'your-api-key', // Your API key
32
+ sessionId: 'optional-session-id', // Optional: Provide a custom session ID
33
+ widgetConfig: {
34
+ header: {
35
+ title: "Chat Assistant"
36
+ },
37
+ welcome: {
38
+ title: "Welcome!",
39
+ description: "How can I help you today?"
40
+ },
41
+ suggestedQuestions: [
42
+ {
43
+ text: "How can you help me?",
44
+ query: "What can you do?"
45
+ },
46
+ {
47
+ text: "Contact support",
48
+ query: "How do I contact support?"
49
+ }
50
+ ],
51
+ theme: {
52
+ primary: '#2C3E50',
53
+ secondary: '#f97316',
54
+ background: '#ffffff',
55
+ text: {
56
+ primary: '#1a1a1a',
57
+ secondary: '#666666',
58
+ inverse: '#ffffff'
59
+ },
60
+ input: {
61
+ background: '#f9fafb',
62
+ border: '#e5e7eb'
63
+ },
64
+ message: {
65
+ user: '#2C3E50',
66
+ assistant: '#ffffff',
67
+ userText: '#ffffff'
68
+ },
69
+ suggestedQuestions: {
70
+ background: '#fff7ed',
71
+ hoverBackground: '#ffedd5',
72
+ text: '#2C3E50'
73
+ },
74
+ iconColor: '#f97316'
75
+ },
76
+ icon: "message-square"
77
+ }
78
+ });
79
+ });
80
+ </script>
127
81
  ```
128
82
 
129
- **Update version:**
83
+ ## Session Management
130
84
 
131
- ```bash
132
- npm version [patch|minor|major]
133
- ```
85
+ The widget now includes improved session management:
134
86
 
135
- **Publish:**
87
+ 1. **Server-Provided Session ID**: If your server provides a session ID through `window.CHATBOT_SESSION_ID`, the widget will use it automatically.
136
88
 
137
- ```bash
138
- npm publish --access public
139
- ```
89
+ 2. **Custom Session ID**: You can provide your own session ID during initialization:
90
+ ```javascript
91
+ window.initChatbotWidget({
92
+ apiUrl: 'https://your-api-url.com',
93
+ apiKey: 'your-api-key',
94
+ sessionId: 'your-custom-session-id',
95
+ // ... other config
96
+ });
97
+ ```
140
98
 
141
- Package URL: [@schmitech/chatbot-widget](https://www.npmjs.com/package/@schmitech/chatbot-widget)
99
+ 3. **Automatic Session ID**: If no session ID is provided, the widget will:
100
+ - First check for an existing session ID in `sessionStorage`
101
+ - If none exists, generate a new UUID
102
+ - Store the session ID in both `sessionStorage` and `window.CHATBOT_SESSION_ID`
142
103
 
143
- ---
104
+ ## Advanced Usage
144
105
 
145
- ## ๐Ÿ”— Usage Examples
106
+ ### Custom Container
146
107
 
147
- ### HTML Integration
108
+ To place the widget in a specific container instead of the bottom-right corner:
148
109
 
149
- **Full bundle:**
150
110
  ```html
151
- <script src="https://unpkg.com/@schmitech/chatbot-widget@0.2.0/dist/chatbot-widget.bundle.js"></script>
111
+ <div id="my-chat-container"></div>
112
+
113
+ <script>
114
+ window.initChatbotWidget({
115
+ apiUrl: 'https://your-api-url.com',
116
+ apiKey: 'your-api-key',
117
+ containerSelector: '#my-chat-container',
118
+ widgetConfig: {
119
+ // ... your config here
120
+ }
121
+ });
122
+ </script>
152
123
  ```
153
124
 
154
- **UMD + CSS separately:**
155
- ```html
156
- <script src="https://unpkg.com/@schmitech/chatbot-widget@0.2.0"></script>
157
- <link rel="stylesheet" href="https://unpkg.com/@schmitech/chatbot-widget@0.2.0/dist/chatbot-widget.css">
158
- ```
125
+ ### React/TypeScript Integration
159
126
 
160
- ### JavaScript/TypeScript
127
+ For React applications, you can integrate the widget like this:
161
128
 
162
- ```javascript
163
- import { ChatWidget } from '@schmitech/chatbot-widget';
164
- import '@schmitech/chatbot-widget/bundle';
129
+ ```tsx
130
+ import { useEffect } from 'react';
131
+
132
+ function App() {
133
+ useEffect(() => {
134
+ if (typeof window !== 'undefined' && window.initChatbotWidget) {
135
+ window.initChatbotWidget({
136
+ apiUrl: process.env.REACT_APP_API_ENDPOINT,
137
+ apiKey: process.env.REACT_APP_API_KEY,
138
+ sessionId: process.env.REACT_APP_SESSION_ID, // Optional: Provide custom session ID
139
+ widgetConfig: {
140
+ // ... your config here
141
+ }
142
+ });
143
+ }
144
+ }, []);
145
+
146
+ return (
147
+ // Your app content
148
+ );
149
+ }
165
150
  ```
166
151
 
167
- **React/TSX example:**
168
- ```tsx
169
- useEffect(() => {
170
- if (typeof window !== 'undefined' && window.initChatbotWidget) {
171
- window.initChatbotWidget({
172
- apiUrl: import.meta.env.VITE_API_ENDPOINT,
173
- apiKey: import.meta.env.VITE_API_KEY,
174
- widgetConfig: { /* widget configurations */ }
175
- });
176
- }
177
- }, []);
152
+ ## Configuration Options
153
+
154
+ ### Required Parameters
155
+
156
+ | Parameter | Type | Description |
157
+ |-----------|------|-------------|
158
+ | `apiUrl` | string | Your chatbot API endpoint URL |
159
+ | `apiKey` | string | Your API authentication key |
160
+
161
+ ### Optional Parameters
162
+
163
+ | Parameter | Type | Description |
164
+ |-----------|------|-------------|
165
+ | `sessionId` | string | Unique identifier for the chat session. If not provided, one will be generated automatically |
166
+ | `containerSelector` | string | CSS selector for custom container |
167
+ | `widgetConfig` | object | Widget appearance and behavior settings |
168
+
169
+ ### Widget Configuration
170
+
171
+ The `widgetConfig` object supports these properties:
172
+
173
+ ```typescript
174
+ {
175
+ header: {
176
+ title: string; // Widget header title
177
+ },
178
+ welcome: {
179
+ title: string; // Welcome message title
180
+ description: string; // Welcome message description
181
+ },
182
+ suggestedQuestions: [ // Array of suggested questions
183
+ {
184
+ text: string; // Button text
185
+ query: string; // Question to send
186
+ }
187
+ ],
188
+ theme: { // Theme customization
189
+ primary: string; // Primary color
190
+ secondary: string; // Secondary/accent color
191
+ background: string; // Background color
192
+ text: {
193
+ primary: string; // Primary text color
194
+ secondary: string; // Secondary text color
195
+ inverse: string; // Inverse text color
196
+ },
197
+ input: {
198
+ background: string; // Input background
199
+ border: string; // Input border color
200
+ },
201
+ message: {
202
+ user: string; // User message bubble color
203
+ assistant: string; // Assistant message bubble color
204
+ userText: string; // User message text color
205
+ },
206
+ suggestedQuestions: {
207
+ background: string; // Suggested questions background
208
+ hoverBackground: string; // Suggested questions hover background
209
+ text: string; // Suggested questions text color
210
+ },
211
+ iconColor: string; // Widget icon color
212
+ },
213
+ icon: string; // Widget icon type
214
+ }
178
215
  ```
179
216
 
180
- ---
217
+ ## Available Icons
181
218
 
182
- ## โš ๏ธ Known Issues & Troubleshooting
219
+ Choose from these built-in icons:
220
+ - `heart` โค๏ธ
221
+ - `message-square` ๐Ÿ’ฌ
222
+ - `message-circle` ๐Ÿ—จ๏ธ
223
+ - `help-circle` โ“
224
+ - `info` โ„น๏ธ
225
+ - `bot` ๐Ÿค–
226
+ - `sparkles` โœจ
183
227
 
184
- ### **Scrolling behavior:**
228
+ ## Customizing Height
185
229
 
186
- By default, widget height is `500px`. Customize with CSS:
230
+ To adjust the widget height, add this CSS to your website:
187
231
 
188
232
  ```css
189
233
  :root {
190
- --chat-container-height: 600px;
234
+ --chat-container-height: 600px; /* Default is 500px */
191
235
  }
192
236
  ```
193
237
 
194
- - Scrollbar auto-appears with long content
195
- - "Scroll to top" button shows after scrolling `200px`
196
- - Auto-scroll to bottom on new messages
197
- - Clear conversations easily from the header
238
+ ## Troubleshooting
239
+
240
+ 1. **Widget not appearing?**
241
+ - Check browser console for errors
242
+ - Verify API URL and key are correct
243
+ - Ensure all required scripts are loaded
244
+ - Check if the container element exists
245
+
246
+ 2. **Session ID issues?**
247
+ - Verify that `window.CHATBOT_SESSION_ID` is set if using server-provided sessions
248
+ - Check browser console for session-related errors
249
+ - Ensure `sessionStorage` is available and not blocked
250
+
251
+ 3. **API connection issues?**
252
+ - Verify your API endpoint is accessible
253
+ - Check API key is valid
254
+ - Ensure CORS is properly configured on your API
255
+ - Verify session ID is being sent with requests
198
256
 
199
- ---
257
+ 4. **Styling conflicts?**
258
+ - The widget uses scoped CSS to prevent conflicts
259
+ - If you see styling issues, check for conflicting CSS rules
200
260
 
201
- ## ๐Ÿ“ƒ License
261
+ ## Support
202
262
 
203
- Apache 2.0 License - See [LICENSE](LICENSE).
263
+ For more help:
264
+ - Visit our [GitHub repository](https://github.com/schmitech/orbit)
265
+ - Open an issue on GitHub for bug reports