@mypatientspace/chatbot-widget 1.0.73 → 1.0.75
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 +129 -146
- package/dist/mypatientspace-demo.es.js +7111 -6967
- package/dist/mypatientspace-demo.umd.js +343 -284
- package/dist/mypatientspace-widget.es.js +4665 -4569
- package/dist/mypatientspace-widget.umd.js +197 -138
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -8,10 +8,14 @@ A standalone chatbot widget that third-party websites can embed via a single `<s
|
|
|
8
8
|
|
|
9
9
|
- Self-contained React application bundled into a single JS file
|
|
10
10
|
- Easy integration with any website
|
|
11
|
-
-
|
|
12
|
-
- Customizable theming
|
|
11
|
+
- Embedded mode (default) or floating button mode
|
|
12
|
+
- Customizable theming with light, dark, and system color modes
|
|
13
13
|
- Style isolation (won't conflict with host site CSS)
|
|
14
14
|
- Native mobile support via WebView
|
|
15
|
+
- Voice input support
|
|
16
|
+
- Quick action buttons
|
|
17
|
+
- Survey/questionnaire support
|
|
18
|
+
- Content citations with overlay view
|
|
15
19
|
|
|
16
20
|
## Tech Stack
|
|
17
21
|
|
|
@@ -83,57 +87,6 @@ yarn build:demo # Demo only
|
|
|
83
87
|
yarn preview
|
|
84
88
|
```
|
|
85
89
|
|
|
86
|
-
## Demo Widget
|
|
87
|
-
|
|
88
|
-
An embeddable demo page with configuration panel and live preview. Useful for testing and showcasing the widget.
|
|
89
|
-
|
|
90
|
-
### Via CDN
|
|
91
|
-
|
|
92
|
-
```html
|
|
93
|
-
<div id="chatbot-demo" style="height: 600px;"></div>
|
|
94
|
-
<script src="https://unpkg.com/@mypatientspace/chatbot-widget@latest/dist/mypatientspace-demo.umd.js"></script>
|
|
95
|
-
<script>
|
|
96
|
-
ChatbotWidgetDemo.init({
|
|
97
|
-
containerSelector: '#chatbot-demo',
|
|
98
|
-
showJsonEditor: true,
|
|
99
|
-
initialConfig: {
|
|
100
|
-
apiEndpoint: 'https://your-api.com/chat',
|
|
101
|
-
token: 'your-auth-token',
|
|
102
|
-
headerTitle: 'My Healthcare Bot',
|
|
103
|
-
theme: { colors: { primary: '#007bff' } }
|
|
104
|
-
},
|
|
105
|
-
onConfigChange: (config) => console.log('Config:', config)
|
|
106
|
-
});
|
|
107
|
-
</script>
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
> **Note:** The "Use Mock API" toggle is only available in development mode (`yarn dev`). When embedding the demo in production, you must provide `apiEndpoint` and `token` in the `initialConfig`.
|
|
111
|
-
|
|
112
|
-
### Demo API
|
|
113
|
-
|
|
114
|
-
```javascript
|
|
115
|
-
ChatbotWidgetDemo.init(config); // Initialize demo
|
|
116
|
-
ChatbotWidgetDemo.destroy(); // Remove demo
|
|
117
|
-
ChatbotWidgetDemo.update(config); // Update configuration
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
### Demo Configuration
|
|
121
|
-
|
|
122
|
-
| Option | Type | Default | Description |
|
|
123
|
-
|--------|------|---------|-------------|
|
|
124
|
-
| `containerSelector` | `string` | Required | CSS selector for container |
|
|
125
|
-
| `showConfigPanel` | `boolean` | `true` | Show left config panel |
|
|
126
|
-
| `showPreviewPanel` | `boolean` | `true` | Show right preview panel |
|
|
127
|
-
| `showJsonEditor` | `boolean` | `true` | Show Form/JSON toggle |
|
|
128
|
-
| `showDisplaySettings` | `boolean` | `true` | Show display settings section |
|
|
129
|
-
| `showSessionSettings` | `boolean` | `true` | Show session settings section |
|
|
130
|
-
| `showAppearanceSettings` | `boolean` | `true` | Show appearance section |
|
|
131
|
-
| `showThemeSettings` | `boolean` | `true` | Show theme colors section |
|
|
132
|
-
| `showContentSettings` | `boolean` | `true` | Show content settings section |
|
|
133
|
-
| `showQuickActions` | `boolean` | `true` | Show quick actions section |
|
|
134
|
-
| `initialConfig` | `Partial<WidgetConfig>` | `{}` | Pre-fill widget config (including `apiEndpoint` and `token`) |
|
|
135
|
-
| `onConfigChange` | `(config) => void` | - | Called when config changes |
|
|
136
|
-
|
|
137
90
|
## Web Integration
|
|
138
91
|
|
|
139
92
|
### Minimal Setup
|
|
@@ -152,60 +105,60 @@ ChatbotWidgetDemo.update(config); // Update configuration
|
|
|
152
105
|
<script src="https://unpkg.com/@mypatientspace/chatbot-widget@latest/dist/mypatientspace-widget.umd.js"></script>
|
|
153
106
|
<script>
|
|
154
107
|
ChatbotWidget.init({
|
|
108
|
+
// API & Auth
|
|
155
109
|
apiEndpoint: 'https://your-api.com/chat',
|
|
156
110
|
token: 'your-auth-token',
|
|
111
|
+
assistantId: 'your-assistant-id',
|
|
112
|
+
|
|
113
|
+
// Display mode
|
|
114
|
+
floatingMode: true, // false = embedded (default), true = FAB button
|
|
115
|
+
position: 'bottom-left', // FAB position (default: 'bottom-right')
|
|
116
|
+
hideExpandButton: true, // Hide expand/minimize button from header
|
|
117
|
+
showCloseSlot: true, // Empty placeholder for custom close button
|
|
118
|
+
|
|
119
|
+
// Content
|
|
157
120
|
headerTitle: 'Health Support',
|
|
121
|
+
headerSubtitle: 'Online now',
|
|
158
122
|
greeting: 'Hi! How can I help?',
|
|
123
|
+
placeholder: 'Ask me anything...',
|
|
159
124
|
brandingText: 'Powered by MyCompany',
|
|
125
|
+
disclaimerText: 'AI can make mistakes. Verify important information.',
|
|
160
126
|
headerIcon: '/logo.png',
|
|
161
|
-
fabIcon: '/avatar.png',
|
|
162
|
-
placeholder: 'Ask me anything...',
|
|
163
|
-
position: 'bottom-left',
|
|
164
|
-
colorMode: 'system', // 'light', 'dark', or 'system' (auto-detect)
|
|
127
|
+
fabIcon: '/avatar.png', // Only used in floating mode
|
|
165
128
|
quickActions: ['I need help', 'Book appointment'],
|
|
129
|
+
|
|
130
|
+
// Appearance
|
|
131
|
+
colorMode: 'system', // 'light', 'dark', or 'system' (auto-detect)
|
|
166
132
|
theme: {
|
|
167
|
-
// All color properties are optional - only set what you want to change
|
|
168
133
|
colors: {
|
|
169
|
-
// Main colors
|
|
170
134
|
primary: '#ff6600', // FAB button, links, main accent
|
|
171
135
|
primaryDark: '#cc5200', // Hover states
|
|
172
136
|
secondary: '#2d3748', // Header background
|
|
173
|
-
|
|
174
|
-
accentLight: '#bee3f8', // Light accent
|
|
175
|
-
|
|
176
|
-
// Status colors
|
|
177
|
-
success: '#48bb78', // Success states
|
|
178
|
-
info: '#4299e1', // Info states
|
|
179
|
-
error: '#f56565', // Error states
|
|
180
|
-
|
|
181
|
-
// Background colors
|
|
137
|
+
headerText: '#ffffff', // Header text color
|
|
182
138
|
background: '#ffffff', // Chat window background
|
|
183
139
|
surface: '#f7fafc', // Input/card backgrounds
|
|
184
|
-
|
|
185
|
-
// Text colors
|
|
186
140
|
text: '#2d3748', // Primary text
|
|
187
141
|
textLight: '#718096', // Secondary text, timestamps
|
|
188
|
-
|
|
189
|
-
// Message bubbles
|
|
190
142
|
userBubble: '#ff6600', // User message background
|
|
191
143
|
userBubbleText: '#ffffff', // User message text
|
|
192
144
|
botBubble: '#edf2f7', // Bot message background
|
|
193
145
|
botBubbleText: '#2d3748', // Bot message text
|
|
194
|
-
|
|
195
|
-
// Borders
|
|
196
|
-
border: '#e2e8f0', // Border color
|
|
197
|
-
borderLight: '#edf2f7', // Light border
|
|
198
|
-
|
|
199
|
-
// Other
|
|
200
|
-
white: '#ffffff', // White color
|
|
201
|
-
recording: '#f56565', // Voice recording indicator
|
|
202
146
|
},
|
|
203
|
-
|
|
204
|
-
// Typography and shape
|
|
205
147
|
fontFamily: 'Inter, system-ui, sans-serif',
|
|
206
148
|
borderRadius: '8px',
|
|
207
149
|
shadow: '0 4px 12px rgba(0, 0, 0, 0.1)',
|
|
208
|
-
}
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
// Callbacks
|
|
153
|
+
onOpen: () => console.log('Chat opened'),
|
|
154
|
+
onClose: () => console.log('Chat closed'),
|
|
155
|
+
onMessageSent: (message) => console.log('Sent:', message),
|
|
156
|
+
onMessageReceived: (message) => console.log('Received:', message),
|
|
157
|
+
onQuickAction: (action) => console.log('Quick action:', action),
|
|
158
|
+
onStreamChunk: (chunk) => console.log('Chunk:', chunk),
|
|
159
|
+
onCitationClick: (citation) => console.log('Citation:', citation),
|
|
160
|
+
onNewChat: () => console.log('New chat started'),
|
|
161
|
+
onWidgetReady: (api) => console.log('Widget ready:', api),
|
|
209
162
|
});
|
|
210
163
|
</script>
|
|
211
164
|
```
|
|
@@ -221,15 +174,17 @@ ChatbotWidget.init({
|
|
|
221
174
|
|
|
222
175
|
### API Methods
|
|
223
176
|
```javascript
|
|
224
|
-
ChatbotWidget.open();
|
|
225
|
-
ChatbotWidget.close();
|
|
226
|
-
ChatbotWidget.toggle();
|
|
227
|
-
ChatbotWidget.
|
|
177
|
+
ChatbotWidget.open(); // Open chat window
|
|
178
|
+
ChatbotWidget.close(); // Close chat window
|
|
179
|
+
ChatbotWidget.toggle(); // Toggle open/close
|
|
180
|
+
ChatbotWidget.startNewChat(); // Clear session and start new chat
|
|
181
|
+
ChatbotWidget.update(config); // Update widget configuration
|
|
182
|
+
ChatbotWidget.destroy(); // Remove widget completely
|
|
228
183
|
```
|
|
229
184
|
|
|
230
185
|
## Embedded Mode
|
|
231
186
|
|
|
232
|
-
By default, the widget
|
|
187
|
+
By default, the widget is embedded inside a container element. You can enable floating mode for a FAB button popup.
|
|
233
188
|
|
|
234
189
|
### Using containerSelector
|
|
235
190
|
|
|
@@ -351,6 +306,48 @@ class ChatViewController: UIViewController {
|
|
|
351
306
|
}
|
|
352
307
|
```
|
|
353
308
|
|
|
309
|
+
### iOS (Objective-C)
|
|
310
|
+
```objc
|
|
311
|
+
#import <UIKit/UIKit.h>
|
|
312
|
+
#import <WebKit/WebKit.h>
|
|
313
|
+
|
|
314
|
+
@interface ChatViewController : UIViewController
|
|
315
|
+
@property (nonatomic, strong) WKWebView *webView;
|
|
316
|
+
@end
|
|
317
|
+
|
|
318
|
+
@implementation ChatViewController
|
|
319
|
+
|
|
320
|
+
- (void)viewDidLoad {
|
|
321
|
+
[super viewDidLoad];
|
|
322
|
+
|
|
323
|
+
WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
|
|
324
|
+
config.preferences.javaScriptEnabled = YES;
|
|
325
|
+
|
|
326
|
+
self.webView = [[WKWebView alloc] initWithFrame:self.view.bounds configuration:config];
|
|
327
|
+
self.webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
328
|
+
[self.view addSubview:self.webView];
|
|
329
|
+
|
|
330
|
+
NSString *html = @"<!DOCTYPE html>"
|
|
331
|
+
"<html>"
|
|
332
|
+
"<head>"
|
|
333
|
+
"<meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1'>"
|
|
334
|
+
"<style>body { margin: 0; padding: 0; }</style>"
|
|
335
|
+
"</head>"
|
|
336
|
+
"<body>"
|
|
337
|
+
"<script src='https://unpkg.com/@mypatientspace/chatbot-widget@latest/dist/mypatientspace-widget.umd.js'></script>"
|
|
338
|
+
"<script>"
|
|
339
|
+
"ChatbotWidget.init({ apiEndpoint: 'https://your-api.com/chat' });"
|
|
340
|
+
"ChatbotWidget.open();"
|
|
341
|
+
"</script>"
|
|
342
|
+
"</body>"
|
|
343
|
+
"</html>";
|
|
344
|
+
|
|
345
|
+
[self.webView loadHTMLString:html baseURL:[NSURL URLWithString:@"https://your-domain.com"]];
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
@end
|
|
349
|
+
```
|
|
350
|
+
|
|
354
351
|
### React Native
|
|
355
352
|
```jsx
|
|
356
353
|
import { WebView } from 'react-native-webview';
|
|
@@ -388,27 +385,32 @@ const ChatScreen = () => {
|
|
|
388
385
|
|
|
389
386
|
### All Options
|
|
390
387
|
|
|
391
|
-
| Option | Type |
|
|
392
|
-
|
|
393
|
-
| `apiEndpoint` | `string` |
|
|
394
|
-
| `token` | `string` |
|
|
395
|
-
| `sessionId` | `string` |
|
|
396
|
-
| `assistantId` | `string` |
|
|
397
|
-
| `contextPatientId` | `string` |
|
|
398
|
-
| `loadHistory` | `boolean` |
|
|
399
|
-
| `colorMode` | `'light' \| 'dark' \| 'system'` |
|
|
400
|
-
| `theme` | `ThemeConfig` |
|
|
401
|
-
| `position` | `'bottom-right' \| 'bottom-left'` |
|
|
402
|
-
| `containerSelector` | `string` |
|
|
403
|
-
| `floatingMode` | `boolean` |
|
|
404
|
-
| `
|
|
405
|
-
| `
|
|
406
|
-
| `
|
|
407
|
-
| `
|
|
408
|
-
| `
|
|
409
|
-
| `
|
|
410
|
-
| `
|
|
411
|
-
| `
|
|
388
|
+
| Option | Type | Default | Description |
|
|
389
|
+
|--------|------|---------|-------------|
|
|
390
|
+
| `apiEndpoint` | `string` | - | Chat API endpoint URL (widget offline if not set) |
|
|
391
|
+
| `token` | `string` | - | Auth token for API requests |
|
|
392
|
+
| `sessionId` | `string` | - | Existing session ID to resume |
|
|
393
|
+
| `assistantId` | `string` | - | Specific assistant ID to use |
|
|
394
|
+
| `contextPatientId` | `string` | - | Patient context for the chat |
|
|
395
|
+
| `loadHistory` | `boolean` | `true` | Load previous chat history |
|
|
396
|
+
| `colorMode` | `'light' \| 'dark' \| 'system'` | `'light'` | Color mode for the widget |
|
|
397
|
+
| `theme` | `ThemeConfig` | - | Custom theme colors, fonts, border radius, shadow |
|
|
398
|
+
| `position` | `'bottom-right' \| 'bottom-left'` | `'bottom-right'` | FAB button position |
|
|
399
|
+
| `containerSelector` | `string` | - | CSS selector for embedded container |
|
|
400
|
+
| `floatingMode` | `boolean` | `false` | Show FAB button and floating chat |
|
|
401
|
+
| `hideExpandButton` | `boolean` | `false` | Hide the expand/minimize button from header |
|
|
402
|
+
| `showCloseSlot` | `boolean` | `false` | Show empty circle placeholder for custom close button |
|
|
403
|
+
| `greeting` | `string` | From API | Initial bot greeting message |
|
|
404
|
+
| `placeholder` | `string` | From API | Input field placeholder text |
|
|
405
|
+
| `headerTitle` | `string` | From API | Chat window header title |
|
|
406
|
+
| `headerSubtitle` | `string` | From API | Chat window header subtitle |
|
|
407
|
+
| `headerIcon` | `string` | From API | Header icon image URL |
|
|
408
|
+
| `fabIcon` | `string` | From API | FAB button image URL |
|
|
409
|
+
| `brandingText` | `string` | From API | Footer branding text |
|
|
410
|
+
| `disclaimerText` | `string` | From API | Disclaimer text below input area |
|
|
411
|
+
| `quickActions` | `string[]` | From API | Predefined quick action buttons |
|
|
412
|
+
|
|
413
|
+
> **Note:** Content fields (`greeting`, `headerTitle`, `placeholder`, `brandingText`, `headerIcon`, `fabIcon`, `quickActions`, `disclaimerText`) are loaded from the assistant's API configuration by default. Setting them in the widget config overrides the API values.
|
|
412
414
|
|
|
413
415
|
### Callbacks
|
|
414
416
|
|
|
@@ -420,35 +422,14 @@ const ChatScreen = () => {
|
|
|
420
422
|
| `onMessageReceived` | `(message: Message)` | Called after bot response completes |
|
|
421
423
|
| `onQuickAction` | `(action: string)` | Called when quick action is clicked |
|
|
422
424
|
| `onStreamChunk` | `(chunk: string)` | Called for each streamed response chunk |
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
```typescript
|
|
427
|
-
interface Message {
|
|
428
|
-
id: string;
|
|
429
|
-
content: string;
|
|
430
|
-
sender: 'user' | 'bot';
|
|
431
|
-
timestamp: Date;
|
|
432
|
-
status: 'sending' | 'sent' | 'error';
|
|
433
|
-
audioUrl?: string; // Base64 audio data URL for TTS playback
|
|
434
|
-
}
|
|
435
|
-
```
|
|
436
|
-
|
|
437
|
-
### ThemeConfig Interface
|
|
438
|
-
|
|
439
|
-
```typescript
|
|
440
|
-
interface ThemeConfig {
|
|
441
|
-
colors?: Partial<ThemeColors>; // Any subset of theme colors
|
|
442
|
-
fontFamily?: string;
|
|
443
|
-
borderRadius?: string;
|
|
444
|
-
shadow?: string;
|
|
445
|
-
}
|
|
446
|
-
```
|
|
425
|
+
| `onCitationClick` | `(citation: Citation)` | Called when a content card is clicked |
|
|
426
|
+
| `onNewChat` | `()` | Called when user starts a new chat |
|
|
427
|
+
| `onWidgetReady` | `(api: WidgetApi)` | Called when widget is ready with API methods |
|
|
447
428
|
|
|
448
429
|
### Available Theme Colors
|
|
449
430
|
|
|
450
|
-
| Color | Default | Description |
|
|
451
|
-
|
|
431
|
+
| Color | Light Default | Description |
|
|
432
|
+
|-------|---------------|-------------|
|
|
452
433
|
| `primary` | `#00c2d1` | FAB button, links, main accent |
|
|
453
434
|
| `primaryDark` | `#017992` | Hover states |
|
|
454
435
|
| `secondary` | `#3c4d73` | Header background |
|
|
@@ -467,25 +448,27 @@ interface ThemeConfig {
|
|
|
467
448
|
| `border` | `#d1d5db` | Border color |
|
|
468
449
|
| `borderLight` | `#e5e7eb` | Light border |
|
|
469
450
|
| `error` | `#ef4444` | Error states |
|
|
451
|
+
| `errorBackground` | `#fef2f2` | Error background |
|
|
470
452
|
| `white` | `#ffffff` | White color |
|
|
471
453
|
| `recording` | `#ef4444` | Voice recording indicator |
|
|
454
|
+
| `headerText` | `#ffffff` | Header text and icon color |
|
|
455
|
+
| `scrollbarThumb` | `rgba(60, 77, 115, 0.2)` | Scrollbar thumb color |
|
|
456
|
+
| `scrollbarThumbHover` | `rgba(60, 77, 115, 0.3)` | Scrollbar thumb hover |
|
|
457
|
+
|
|
458
|
+
### Default Fallback Values
|
|
472
459
|
|
|
473
|
-
|
|
460
|
+
Content fields are resolved with this priority: **Config > Assistant API > Component default**
|
|
474
461
|
|
|
475
|
-
|
|
|
476
|
-
|
|
462
|
+
| Field | Component Fallback |
|
|
463
|
+
|-------|-------------------|
|
|
477
464
|
| `headerTitle` | "AI Doctor" |
|
|
478
465
|
| `greeting` | "Hello! Welcome to our healthcare support. How can I assist you today?" |
|
|
479
466
|
| `placeholder` | "Type a message..." |
|
|
480
467
|
| `brandingText` | "Developed by myPatientSpace" |
|
|
481
|
-
| `
|
|
482
|
-
| `
|
|
483
|
-
| `
|
|
484
|
-
| `
|
|
485
|
-
| `loadHistory` | true |
|
|
486
|
-
| `containerSelector` | undefined (creates container in body) |
|
|
487
|
-
| `floatingMode` | false (embedded is default) |
|
|
488
|
-
| `quickActions` | Book Appointment, Hours, Contact, Location |
|
|
468
|
+
| `disclaimerText` | "AI can make mistakes. Verify important information." |
|
|
469
|
+
| `headerIcon` | MPS logo |
|
|
470
|
+
| `fabIcon` | MPS logo |
|
|
471
|
+
| `quickActions` | Empty (from API only) |
|
|
489
472
|
|
|
490
473
|
## License
|
|
491
474
|
|