@schmitech/chatbot-widget 0.3.5 → 0.3.7

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
@@ -25,20 +25,11 @@ Add this code to your website:
25
25
 
26
26
  ```html
27
27
  <script>
28
- // Generate a unique session ID for this user
29
- function generateUUID() {
30
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
31
- const r = Math.random() * 16 | 0;
32
- const v = c === 'x' ? r : (r & 0x3 | 0x8);
33
- return v.toString(16);
34
- });
35
- }
36
-
37
28
  window.addEventListener('load', function() {
38
29
  window.initChatbotWidget({
39
30
  apiUrl: 'https://your-api-url.com', // Your chatbot API endpoint
40
31
  apiKey: 'your-api-key', // Your API key
41
- sessionId: generateUUID(), // Unique session ID
32
+ sessionId: 'optional-session-id', // Optional: Provide a custom session ID
42
33
  widgetConfig: {
43
34
  header: {
44
35
  title: "Chat Assistant"
@@ -89,6 +80,27 @@ Add this code to your website:
89
80
  </script>
90
81
  ```
91
82
 
83
+ ## Session Management
84
+
85
+ The widget now includes improved session management:
86
+
87
+ 1. **Server-Provided Session ID**: If your server provides a session ID through `window.CHATBOT_SESSION_ID`, the widget will use it automatically.
88
+
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
+ ```
98
+
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`
103
+
92
104
  ## Advanced Usage
93
105
 
94
106
  ### Custom Container
@@ -123,7 +135,7 @@ function App() {
123
135
  window.initChatbotWidget({
124
136
  apiUrl: process.env.REACT_APP_API_ENDPOINT,
125
137
  apiKey: process.env.REACT_APP_API_KEY,
126
- sessionId: generateUUID(),
138
+ sessionId: process.env.REACT_APP_SESSION_ID, // Optional: Provide custom session ID
127
139
  widgetConfig: {
128
140
  // ... your config here
129
141
  }
@@ -150,7 +162,7 @@ function App() {
150
162
 
151
163
  | Parameter | Type | Description |
152
164
  |-----------|------|-------------|
153
- | `sessionId` | string | Unique identifier for the chat session |
165
+ | `sessionId` | string | Unique identifier for the chat session. If not provided, one will be generated automatically |
154
166
  | `containerSelector` | string | CSS selector for custom container |
155
167
  | `widgetConfig` | object | Widget appearance and behavior settings |
156
168
 
@@ -229,13 +241,20 @@ To adjust the widget height, add this CSS to your website:
229
241
  - Check browser console for errors
230
242
  - Verify API URL and key are correct
231
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
232
250
 
233
- 2. **API connection issues?**
251
+ 3. **API connection issues?**
234
252
  - Verify your API endpoint is accessible
235
253
  - Check API key is valid
236
254
  - Ensure CORS is properly configured on your API
255
+ - Verify session ID is being sent with requests
237
256
 
238
- 3. **Styling conflicts?**
257
+ 4. **Styling conflicts?**
239
258
  - The widget uses scoped CSS to prevent conflicts
240
259
  - If you see styling issues, check for conflicting CSS rules
241
260