@blumessage/react-chat 1.0.0 → 1.0.3
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 +231 -124
- package/dist/BlumessageChat.js +624 -0
- package/dist/index.js +1 -2291
- package/dist/types/BlumessageChat.d.ts +48 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +53 -40
- package/dist/components/ChatComponent.d.ts +0 -61
- package/dist/components/ChatComponent.d.ts.map +0 -1
- package/dist/index.esm.js +0 -2289
- package/dist/index.esm.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/index.d.ts +0 -2
- package/dist/lib/index.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,182 +1,289 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Blumessage React Chat Component
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A React TypeScript chat widget component with floating button, theming, and Blumessage API integration. Features real-time messaging, conversation persistence, error handling, and a modern UI built with Tailwind CSS.
|
|
4
4
|
|
|
5
|
-
## Features
|
|
5
|
+
## ✨ Features
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
- 🔧 Extensive customization options
|
|
7
|
+
- 🎈 **Floating Chat Widget** - Appears as a button, expands to full chat
|
|
8
|
+
- 🎨 **Light/Dark Themes** - Built-in theme support
|
|
9
|
+
- 💾 **Persistent Storage** - Save conversations to localStorage or sessionStorage
|
|
10
|
+
- 🔄 **Real-time Messaging** - Instant API integration with Blumessage
|
|
11
|
+
- 📱 **Responsive Design** - Works on desktop and mobile
|
|
12
|
+
- 🎯 **Flexible Icons** - Supports various icon patterns
|
|
13
|
+
- ⚡ **Error Handling** - Comprehensive error callbacks
|
|
14
|
+
- 🔧 **Highly Customizable** - Extensive prop options
|
|
16
15
|
|
|
17
16
|
## Installation
|
|
18
17
|
|
|
19
18
|
```bash
|
|
20
|
-
npm
|
|
19
|
+
npm i @blumessage/react-chat
|
|
21
20
|
```
|
|
22
21
|
|
|
23
22
|
## Quick Start
|
|
24
23
|
|
|
24
|
+
### Floating Chat Widget (Default)
|
|
25
|
+
|
|
25
26
|
```tsx
|
|
26
27
|
import React from 'react';
|
|
27
28
|
import { BlumessageChat } from '@blumessage/react-chat';
|
|
28
29
|
|
|
29
30
|
function App() {
|
|
30
31
|
return (
|
|
31
|
-
<
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
headerTitle="Support Chat"
|
|
35
|
-
primaryColor="#3b82f6"
|
|
36
|
-
/>
|
|
37
|
-
</div>
|
|
32
|
+
<BlumessageChat
|
|
33
|
+
apiKey="your-blumessage-api-key"
|
|
34
|
+
/>
|
|
38
35
|
);
|
|
39
36
|
}
|
|
40
|
-
|
|
41
|
-
export default App;
|
|
42
37
|
```
|
|
43
38
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
1. Sign up for a BlueMessage API key at [blumessage.com](https://blumessage.com)
|
|
47
|
-
2. Pass your API key to the `apiKey` prop
|
|
48
|
-
3. For testing purposes, you can use `apiKey="test"` to enable demo mode
|
|
39
|
+
### Embedded Chat
|
|
49
40
|
|
|
50
|
-
|
|
41
|
+
```tsx
|
|
42
|
+
import React from 'react';
|
|
43
|
+
import { BlumessageChat } from '@blumessage/react-chat';
|
|
51
44
|
|
|
52
|
-
|
|
45
|
+
function App() {
|
|
46
|
+
return (
|
|
47
|
+
<BlumessageChat
|
|
48
|
+
apiKey="your-blumessage-api-key"
|
|
49
|
+
floating={false}
|
|
50
|
+
width="400px"
|
|
51
|
+
height="600px"
|
|
52
|
+
/>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
```
|
|
53
56
|
|
|
54
|
-
|
|
57
|
+
## Complete Props Reference
|
|
55
58
|
|
|
56
59
|
| Prop | Type | Default | Description |
|
|
57
60
|
|------|------|---------|-------------|
|
|
58
|
-
|
|
|
59
|
-
| `
|
|
60
|
-
|
|
|
61
|
-
| `
|
|
62
|
-
| `
|
|
63
|
-
| `
|
|
61
|
+
| **Required** |
|
|
62
|
+
| `apiKey` | `string` | - | Your Blumessage API key |
|
|
63
|
+
| **Display & Content** |
|
|
64
|
+
| `name` | `string` | `"Blumessage AI"` | Display name for the AI assistant |
|
|
65
|
+
| `subtitle` | `string` | `"Online • Instant responses"` | Subtitle shown under the name |
|
|
66
|
+
| `placeholder` | `string` | `"Type your message..."` | Input placeholder text |
|
|
67
|
+
| `theme` | `'light' \| 'dark'` | `'light'` | Chat widget theme |
|
|
68
|
+
| `primaryColor` | `string` | `"linear-gradient(to right, #3b82f6,rgb(8, 98, 242))"` | Primary color/gradient |
|
|
69
|
+
| **Layout & Sizing** |
|
|
70
|
+
| `floating` | `boolean` | `true` | Show as floating widget vs embedded |
|
|
71
|
+
| `width` | `string` | `'380px'` (medium) | Custom width (overrides size) |
|
|
72
|
+
| `height` | `string` | `'500px'` (medium) | Custom height (overrides size) |
|
|
73
|
+
| `size` | `'small' \| 'medium' \| 'large'` | `'medium'` | Predefined size preset |
|
|
74
|
+
| `fullScreen` | `boolean` | `false` | Force full screen mode |
|
|
75
|
+
| **Floating Widget Options** |
|
|
76
|
+
| `buttonText` | `string` | `"Chat with us"` | Text on floating button |
|
|
77
|
+
| `buttonPosition` | `'bottom-right' \| 'bottom-left' \| 'top-right' \| 'top-left'` | `'bottom-right'` | Button position |
|
|
78
|
+
| `buttonStyle` | `React.CSSProperties` | - | Custom button styles |
|
|
79
|
+
| `defaultOpen` | `boolean` | `false` | Start with chat open |
|
|
80
|
+
| `maximizeToggleButton` | `boolean` | `true` | Show maximize/minimize button |
|
|
81
|
+
| `icon` | `string` | `'message-circle'` | Icon for button (flexible naming) |
|
|
82
|
+
| **Messages & Data** |
|
|
83
|
+
| `initialMessages` | `Message[]` | `[]` | Pre-populate with messages |
|
|
84
|
+
| `conversationId` | `string` | - | Continue specific conversation |
|
|
85
|
+
| `persistent` | `boolean` | `false` | Use localStorage vs sessionStorage |
|
|
86
|
+
| **Event Callbacks** |
|
|
87
|
+
| `onUserMessage` | `(message: Message) => void` | - | Called when user sends message |
|
|
88
|
+
| `onAssistantMessage` | `(message: Message) => void` | - | Called when assistant responds |
|
|
89
|
+
| `onConversationIdChange` | `(id: string \| null) => void` | - | Called when conversation ID changes |
|
|
90
|
+
| `onChatWidgetOpen` | `() => void` | - | Called when floating chat opens |
|
|
91
|
+
| `onChatWidgetClosed` | `() => void` | - | Called when floating chat closes |
|
|
92
|
+
| `onError` | `(error: string, context?: string) => void` | - | Called on any error |
|
|
93
|
+
|
|
94
|
+
## Advanced Usage Examples
|
|
95
|
+
|
|
96
|
+
### Dark Theme with Callbacks
|
|
64
97
|
|
|
65
|
-
|
|
98
|
+
```tsx
|
|
99
|
+
<BlumessageChat
|
|
100
|
+
apiKey="your-api-key"
|
|
101
|
+
theme="dark"
|
|
102
|
+
name="Support Bot"
|
|
103
|
+
onUserMessage={(message) => console.log('User:', message.content)}
|
|
104
|
+
onAssistantMessage={(message) => console.log('Bot:', message.content)}
|
|
105
|
+
onError={(error, context) => console.error(`Error in ${context}:`, error)}
|
|
106
|
+
/>
|
|
107
|
+
```
|
|
66
108
|
|
|
67
|
-
|
|
68
|
-
|------|------|---------|-------------|
|
|
69
|
-
| `headerTitle` | `string` | `'BlueMessage AI'` | Chat header title |
|
|
70
|
-
| `headerDescription` | `string` | `'Online • Instant responses'` | Subtitle text in header |
|
|
71
|
-
| `headerColor` | `string` | `undefined` | Header background color (uses primaryColor if not set) |
|
|
72
|
-
| `headerIcon` | `string` | `'mdi:message-text'` | Iconify icon name for header |
|
|
73
|
-
| `headerIconColor` | `string` | `'white'` | Header icon color |
|
|
74
|
-
| `headerIconHide` | `boolean` | `false` | Hide header icon |
|
|
75
|
-
| `headerAvatarColor` | `string` | `'rgba(255, 255, 255, 0.2)'` | Header avatar background color |
|
|
109
|
+
### Persistent Storage
|
|
76
110
|
|
|
77
|
-
|
|
111
|
+
```tsx
|
|
112
|
+
<BlumessageChat
|
|
113
|
+
apiKey="your-api-key"
|
|
114
|
+
persistent={true} // Saves to localStorage instead of sessionStorage
|
|
115
|
+
onConversationIdChange={(id) => {
|
|
116
|
+
// Optionally save ID to your own storage
|
|
117
|
+
if (id) localStorage.setItem('my-chat-id', id);
|
|
118
|
+
}}
|
|
119
|
+
/>
|
|
120
|
+
```
|
|
78
121
|
|
|
79
|
-
|
|
80
|
-
|------|------|---------|-------------|
|
|
81
|
-
| `size` | `'xsmall' \| 'small' \| 'medium' \| 'large' \| 'xlarge'` | `'medium'` | Chat window size |
|
|
82
|
-
| `floatingButtonPosition` | `'top-right' \| 'top-left' \| 'bottom-left' \| 'bottom-right'` | `'bottom-right'` | Position of floating chat button |
|
|
83
|
-
| `autoOpen` | `boolean` | `false` | Auto-open chat on load |
|
|
84
|
-
| `forceOpen` | `boolean` | `false` | Force chat to stay open (removes close button) |
|
|
85
|
-
| `maximize` | `boolean` | `false` | Start maximized |
|
|
86
|
-
| `maximizeToggle` | `boolean` | `true` | Show maximize/minimize button |
|
|
122
|
+
### Custom Styling & Size
|
|
87
123
|
|
|
88
|
-
|
|
124
|
+
```tsx
|
|
125
|
+
<BlumessageChat
|
|
126
|
+
apiKey="your-api-key"
|
|
127
|
+
size="large"
|
|
128
|
+
primaryColor="linear-gradient(45deg, #ff6b6b, #4ecdc4)"
|
|
129
|
+
buttonPosition="bottom-left"
|
|
130
|
+
buttonText="Need Help?"
|
|
131
|
+
icon="headphones"
|
|
132
|
+
maximizeToggleButton={true}
|
|
133
|
+
/>
|
|
134
|
+
```
|
|
89
135
|
|
|
90
|
-
|
|
91
|
-
|------|------|---------|-------------|
|
|
92
|
-
| `primaryColor` | `string` | `'#3b82f6'` | Main theme color |
|
|
93
|
-
| `secondaryColor` | `string` | `'#2563eb'` | Secondary theme color |
|
|
94
|
-
| `messageUserColor` | `string` | `undefined` | User message background (uses gradient if not set) |
|
|
95
|
-
| `messageAssistantColor` | `string` | `'#f3f4f6'` | Assistant message background |
|
|
96
|
-
| `sendButtonColor` | `string` | `undefined` | Send button color (uses gradient if not set) |
|
|
97
|
-
| `inputOutlineColor` | `string` | `'#3b82f6'` | Input focus border color |
|
|
98
|
-
| `floatingButtonBackgroundColor` | `string` | `undefined` | Floating button background |
|
|
99
|
-
| `floatingButtonIcon` | `string` | `undefined` | Floating button icon (uses headerIcon if not set) |
|
|
100
|
-
| `floatingButtonIconColor` | `string` | `'white'` | Floating button icon color |
|
|
101
|
-
|
|
102
|
-
### Message Customization
|
|
136
|
+
### Embedded with Initial Messages
|
|
103
137
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
138
|
+
```tsx
|
|
139
|
+
const initialMessages = [
|
|
140
|
+
{
|
|
141
|
+
id: '1',
|
|
142
|
+
role: 'assistant' as const,
|
|
143
|
+
content: 'Hello! How can I help you today?',
|
|
144
|
+
timestamp: Date.now()
|
|
145
|
+
}
|
|
146
|
+
];
|
|
147
|
+
|
|
148
|
+
<BlumessageChat
|
|
149
|
+
apiKey="your-api-key"
|
|
150
|
+
floating={false}
|
|
151
|
+
width="100%"
|
|
152
|
+
height="500px"
|
|
153
|
+
initialMessages={initialMessages}
|
|
154
|
+
placeholder="Ask me anything..."
|
|
155
|
+
/>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Icon Options
|
|
159
|
+
|
|
160
|
+
The `icon` prop accepts **any lucide-react icon name** with flexible naming patterns. The component intelligently matches your input to the appropriate lucide-react icon:
|
|
118
161
|
|
|
119
162
|
```tsx
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
163
|
+
// ✅ Any lucide-react icon works:
|
|
164
|
+
icon="message-circle" // MessageCircle
|
|
165
|
+
icon="phone" // Phone
|
|
166
|
+
icon="mail" // Mail
|
|
167
|
+
icon="headphones" // Headphones
|
|
168
|
+
icon="bot" // Bot
|
|
169
|
+
icon="users" // Users
|
|
170
|
+
icon="heart" // Heart
|
|
171
|
+
icon="star" // Star
|
|
172
|
+
icon="zap" // Zap
|
|
173
|
+
icon="settings" // Settings
|
|
174
|
+
icon="help-circle" // HelpCircle
|
|
175
|
+
icon="info" // Info
|
|
176
|
+
icon="alert-triangle" // AlertTriangle
|
|
177
|
+
|
|
178
|
+
// ✅ Flexible naming patterns (case-insensitive, ignores hyphens/underscores):
|
|
179
|
+
icon="MessageCircle" // → MessageCircle
|
|
180
|
+
icon="message_circle" // → MessageCircle
|
|
181
|
+
icon="message circle" // → MessageCircle
|
|
182
|
+
icon="chat" // → MessageCircle (smart matching)
|
|
183
|
+
icon="messaging" // → MessageCircle (smart matching)
|
|
184
|
+
icon="support" // → Headphones (smart matching)
|
|
185
|
+
icon="email" // → Mail (smart matching)
|
|
186
|
+
icon="call" // → Phone (smart matching)
|
|
187
|
+
|
|
188
|
+
// ✅ Default fallback: MessageCircle (if no match found)
|
|
189
|
+
icon="unknown-icon" // → MessageCircle
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
**Browse all available icons at:** [lucide.dev/icons](https://lucide.dev/icons)
|
|
193
|
+
|
|
194
|
+
Simply use the icon name from lucide-react, and the component will handle the rest!
|
|
195
|
+
|
|
196
|
+
## Error Handling
|
|
197
|
+
|
|
198
|
+
The `onError` callback provides detailed error context:
|
|
199
|
+
|
|
200
|
+
```tsx
|
|
201
|
+
<BlumessageChat
|
|
202
|
+
apiKey="your-api-key"
|
|
203
|
+
onError={(error, context) => {
|
|
204
|
+
switch(context) {
|
|
205
|
+
case 'missing_api_key':
|
|
206
|
+
// Handle missing API key
|
|
207
|
+
break;
|
|
208
|
+
case 'api_key_validation':
|
|
209
|
+
// Handle invalid API key
|
|
210
|
+
break;
|
|
211
|
+
case 'network_error':
|
|
212
|
+
// Handle network issues
|
|
213
|
+
break;
|
|
214
|
+
case 'conversation_history':
|
|
215
|
+
// Handle history fetch errors
|
|
216
|
+
break;
|
|
217
|
+
case 'message_send':
|
|
218
|
+
// Handle message sending errors
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
}}
|
|
222
|
+
/>
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## TypeScript Support
|
|
226
|
+
|
|
227
|
+
Full TypeScript definitions included:
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
import { BlumessageChat, Message, BlumessageChatProps } from '@blumessage/react-chat';
|
|
125
231
|
|
|
126
232
|
interface Message {
|
|
127
233
|
id: string;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
timestamp:
|
|
131
|
-
isOwn: boolean;
|
|
234
|
+
role: 'user' | 'assistant';
|
|
235
|
+
content: string;
|
|
236
|
+
timestamp: number;
|
|
132
237
|
}
|
|
133
238
|
```
|
|
134
239
|
|
|
135
|
-
##
|
|
240
|
+
## API Integration
|
|
136
241
|
|
|
137
|
-
###
|
|
242
|
+
### Message Sending
|
|
243
|
+
```
|
|
244
|
+
POST https://api.blumessage.com/api/v1/conversations
|
|
245
|
+
Content-Type: application/json
|
|
246
|
+
Authorization: Bearer {API_KEY}
|
|
138
247
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
secondaryColor="#059669"
|
|
144
|
-
headerTitle="Customer Support"
|
|
145
|
-
headerDescription="We're here to help!"
|
|
146
|
-
size="large"
|
|
147
|
-
messageTimestamps={true}
|
|
148
|
-
messageAssistantAvatarVisibility={true}
|
|
149
|
-
/>
|
|
248
|
+
{
|
|
249
|
+
"message": "user input",
|
|
250
|
+
"conversationId": "optional-existing-id"
|
|
251
|
+
}
|
|
150
252
|
```
|
|
151
253
|
|
|
152
|
-
###
|
|
254
|
+
### Conversation History
|
|
255
|
+
```
|
|
256
|
+
GET https://api.blumessage.com/api/v1/conversations/session/{conversationId}
|
|
257
|
+
Authorization: {API_KEY}
|
|
258
|
+
```
|
|
153
259
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
};
|
|
260
|
+
### API Key Validation
|
|
261
|
+
```
|
|
262
|
+
POST https://api.blumessage.com/api/v1/api-keys/validate
|
|
263
|
+
Content-Type: application/json
|
|
159
264
|
|
|
160
|
-
|
|
161
|
-
apiKey
|
|
162
|
-
|
|
163
|
-
currentUser={{
|
|
164
|
-
id: 'user123',
|
|
165
|
-
name: 'John Doe',
|
|
166
|
-
avatar: '👤'
|
|
167
|
-
}}
|
|
168
|
-
/>
|
|
265
|
+
{
|
|
266
|
+
"apiKey": "your-api-key"
|
|
267
|
+
}
|
|
169
268
|
```
|
|
170
269
|
|
|
171
|
-
##
|
|
270
|
+
## Storage Behavior
|
|
271
|
+
|
|
272
|
+
- **SessionStorage (default)**: Conversations persist until browser tab closes
|
|
273
|
+
- **LocalStorage (persistent=true)**: Conversations persist across browser sessions
|
|
274
|
+
- **Automatic cleanup**: Invalid conversation IDs are automatically cleared
|
|
275
|
+
- **History restoration**: Previous conversations load automatically on component mount
|
|
276
|
+
|
|
277
|
+
## Browser Support
|
|
172
278
|
|
|
279
|
+
- Modern browsers with ES2017+ support
|
|
173
280
|
- React 18+
|
|
174
|
-
- TypeScript
|
|
281
|
+
- TypeScript 4.5+
|
|
175
282
|
|
|
176
283
|
## License
|
|
177
284
|
|
|
178
|
-
|
|
285
|
+
ISC
|
|
179
286
|
|
|
180
287
|
## Support
|
|
181
288
|
|
|
182
|
-
For
|
|
289
|
+
For issues and feature requests, please visit the [GitHub repository](https://github.com/Blumessage/react-chat).
|