@blumessage/react-chat 1.0.0 → 1.0.2
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 +222 -125
- 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,279 @@
|
|
|
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 install
|
|
19
|
+
npm install blumessage-react-chat-component
|
|
21
20
|
```
|
|
22
21
|
|
|
22
|
+
**Requirements**: This component uses Tailwind CSS classes and Lucide React icons. Ensure Tailwind CSS is configured in your project.
|
|
23
|
+
|
|
23
24
|
## Quick Start
|
|
24
25
|
|
|
26
|
+
### Floating Chat Widget (Default)
|
|
27
|
+
|
|
25
28
|
```tsx
|
|
26
29
|
import React from 'react';
|
|
27
|
-
import { BlumessageChat } from '
|
|
30
|
+
import { BlumessageChat } from 'blumessage-react-chat-component';
|
|
28
31
|
|
|
29
32
|
function App() {
|
|
30
33
|
return (
|
|
31
|
-
<
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
/>
|
|
37
|
-
</div>
|
|
34
|
+
<BlumessageChat
|
|
35
|
+
apiKey="your-blumessage-api-key"
|
|
36
|
+
buttonText="Chat with us"
|
|
37
|
+
buttonPosition="bottom-right"
|
|
38
|
+
/>
|
|
38
39
|
);
|
|
39
40
|
}
|
|
40
|
-
|
|
41
|
-
export default App;
|
|
42
41
|
```
|
|
43
42
|
|
|
44
|
-
|
|
43
|
+
### Embedded Chat
|
|
45
44
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
**Note:** Without a valid API key, the chat component will be disabled and an error will be logged to the console.
|
|
45
|
+
```tsx
|
|
46
|
+
import React from 'react';
|
|
47
|
+
import { BlumessageChat } from 'blumessage-react-chat-component';
|
|
51
48
|
|
|
52
|
-
|
|
49
|
+
function App() {
|
|
50
|
+
return (
|
|
51
|
+
<BlumessageChat
|
|
52
|
+
apiKey="your-blumessage-api-key"
|
|
53
|
+
floating={false}
|
|
54
|
+
width="400px"
|
|
55
|
+
height="600px"
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
```
|
|
53
60
|
|
|
54
|
-
|
|
61
|
+
## Complete Props Reference
|
|
55
62
|
|
|
56
63
|
| Prop | Type | Default | Description |
|
|
57
64
|
|------|------|---------|-------------|
|
|
58
|
-
|
|
|
59
|
-
| `
|
|
60
|
-
|
|
|
61
|
-
| `
|
|
62
|
-
| `
|
|
63
|
-
| `
|
|
65
|
+
| **Required** |
|
|
66
|
+
| `apiKey` | `string` | - | Your Blumessage API key |
|
|
67
|
+
| **Display & Content** |
|
|
68
|
+
| `name` | `string` | `"Blumessage AI"` | Display name for the AI assistant |
|
|
69
|
+
| `subtitle` | `string` | `"Online • Instant responses"` | Subtitle shown under the name |
|
|
70
|
+
| `placeholder` | `string` | `"Type your message..."` | Input placeholder text |
|
|
71
|
+
| `theme` | `'light' \| 'dark'` | `'light'` | Chat widget theme |
|
|
72
|
+
| `primaryColor` | `string` | `"linear-gradient(to right, #3b82f6,rgb(8, 98, 242))"` | Primary color/gradient |
|
|
73
|
+
| **Layout & Sizing** |
|
|
74
|
+
| `floating` | `boolean` | `true` | Show as floating widget vs embedded |
|
|
75
|
+
| `width` | `string` | `'380px'` (medium) | Custom width (overrides size) |
|
|
76
|
+
| `height` | `string` | `'500px'` (medium) | Custom height (overrides size) |
|
|
77
|
+
| `size` | `'small' \| 'medium' \| 'large'` | `'medium'` | Predefined size preset |
|
|
78
|
+
| `fullScreen` | `boolean` | `false` | Force full screen mode |
|
|
79
|
+
| **Floating Widget Options** |
|
|
80
|
+
| `buttonText` | `string` | `"Chat with us"` | Text on floating button |
|
|
81
|
+
| `buttonPosition` | `'bottom-right' \| 'bottom-left' \| 'top-right' \| 'top-left'` | `'bottom-right'` | Button position |
|
|
82
|
+
| `buttonStyle` | `React.CSSProperties` | - | Custom button styles |
|
|
83
|
+
| `defaultOpen` | `boolean` | `false` | Start with chat open |
|
|
84
|
+
| `maximizeToggleButton` | `boolean` | `true` | Show maximize/minimize button |
|
|
85
|
+
| `icon` | `string` | `'message-circle'` | Icon for button (flexible naming) |
|
|
86
|
+
| **Messages & Data** |
|
|
87
|
+
| `initialMessages` | `Message[]` | `[]` | Pre-populate with messages |
|
|
88
|
+
| `conversationId` | `string` | - | Continue specific conversation |
|
|
89
|
+
| `persistent` | `boolean` | `false` | Use localStorage vs sessionStorage |
|
|
90
|
+
| **Event Callbacks** |
|
|
91
|
+
| `onUserMessage` | `(message: Message) => void` | - | Called when user sends message |
|
|
92
|
+
| `onAssistantMessage` | `(message: Message) => void` | - | Called when assistant responds |
|
|
93
|
+
| `onConversationIdChange` | `(id: string \| null) => void` | - | Called when conversation ID changes |
|
|
94
|
+
| `onChatWidgetOpen` | `() => void` | - | Called when floating chat opens |
|
|
95
|
+
| `onChatWidgetClosed` | `() => void` | - | Called when floating chat closes |
|
|
96
|
+
| `onError` | `(error: string, context?: string) => void` | - | Called on any error |
|
|
97
|
+
|
|
98
|
+
## Advanced Usage Examples
|
|
99
|
+
|
|
100
|
+
### Dark Theme with Callbacks
|
|
64
101
|
|
|
65
|
-
|
|
102
|
+
```tsx
|
|
103
|
+
<BlumessageChat
|
|
104
|
+
apiKey="your-api-key"
|
|
105
|
+
theme="dark"
|
|
106
|
+
name="Support Bot"
|
|
107
|
+
onUserMessage={(message) => console.log('User:', message.content)}
|
|
108
|
+
onAssistantMessage={(message) => console.log('Bot:', message.content)}
|
|
109
|
+
onError={(error, context) => console.error(`Error in ${context}:`, error)}
|
|
110
|
+
/>
|
|
111
|
+
```
|
|
66
112
|
|
|
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 |
|
|
113
|
+
### Persistent Storage
|
|
76
114
|
|
|
77
|
-
|
|
115
|
+
```tsx
|
|
116
|
+
<BlumessageChat
|
|
117
|
+
apiKey="your-api-key"
|
|
118
|
+
persistent={true} // Saves to localStorage instead of sessionStorage
|
|
119
|
+
onConversationIdChange={(id) => {
|
|
120
|
+
// Optionally save ID to your own storage
|
|
121
|
+
if (id) localStorage.setItem('my-chat-id', id);
|
|
122
|
+
}}
|
|
123
|
+
/>
|
|
124
|
+
```
|
|
78
125
|
|
|
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 |
|
|
126
|
+
### Custom Styling & Size
|
|
87
127
|
|
|
88
|
-
|
|
128
|
+
```tsx
|
|
129
|
+
<BlumessageChat
|
|
130
|
+
apiKey="your-api-key"
|
|
131
|
+
size="large"
|
|
132
|
+
primaryColor="linear-gradient(45deg, #ff6b6b, #4ecdc4)"
|
|
133
|
+
buttonPosition="bottom-left"
|
|
134
|
+
buttonText="Need Help?"
|
|
135
|
+
icon="headphones"
|
|
136
|
+
maximizeToggleButton={true}
|
|
137
|
+
/>
|
|
138
|
+
```
|
|
89
139
|
|
|
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
|
|
140
|
+
### Embedded with Initial Messages
|
|
103
141
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
142
|
+
```tsx
|
|
143
|
+
const initialMessages = [
|
|
144
|
+
{
|
|
145
|
+
id: '1',
|
|
146
|
+
role: 'assistant' as const,
|
|
147
|
+
content: 'Hello! How can I help you today?',
|
|
148
|
+
timestamp: Date.now()
|
|
149
|
+
}
|
|
150
|
+
];
|
|
151
|
+
|
|
152
|
+
<BlumessageChat
|
|
153
|
+
apiKey="your-api-key"
|
|
154
|
+
floating={false}
|
|
155
|
+
width="100%"
|
|
156
|
+
height="500px"
|
|
157
|
+
initialMessages={initialMessages}
|
|
158
|
+
placeholder="Ask me anything..."
|
|
159
|
+
/>
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Icon Options
|
|
163
|
+
|
|
164
|
+
The `icon` prop accepts flexible naming patterns:
|
|
118
165
|
|
|
119
166
|
```tsx
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
167
|
+
// All of these work for message icons:
|
|
168
|
+
icon="message"
|
|
169
|
+
icon="chat"
|
|
170
|
+
icon="message-circle"
|
|
171
|
+
icon="messaging"
|
|
172
|
+
|
|
173
|
+
// Other supported patterns:
|
|
174
|
+
icon="bot" // or "robot"
|
|
175
|
+
icon="phone" // or "call"
|
|
176
|
+
icon="mail" // or "email"
|
|
177
|
+
icon="headphones" // or "support"
|
|
178
|
+
icon="users" // or "user"
|
|
179
|
+
icon="heart" // or "love"
|
|
180
|
+
icon="star" // or "favorite"
|
|
181
|
+
icon="zap" // or "lightning"
|
|
182
|
+
|
|
183
|
+
// Default fallback: MessageCircle
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Error Handling
|
|
187
|
+
|
|
188
|
+
The `onError` callback provides detailed error context:
|
|
189
|
+
|
|
190
|
+
```tsx
|
|
191
|
+
<BlumessageChat
|
|
192
|
+
apiKey="your-api-key"
|
|
193
|
+
onError={(error, context) => {
|
|
194
|
+
switch(context) {
|
|
195
|
+
case 'missing_api_key':
|
|
196
|
+
// Handle missing API key
|
|
197
|
+
break;
|
|
198
|
+
case 'api_key_validation':
|
|
199
|
+
// Handle invalid API key
|
|
200
|
+
break;
|
|
201
|
+
case 'network_error':
|
|
202
|
+
// Handle network issues
|
|
203
|
+
break;
|
|
204
|
+
case 'conversation_history':
|
|
205
|
+
// Handle history fetch errors
|
|
206
|
+
break;
|
|
207
|
+
case 'message_send':
|
|
208
|
+
// Handle message sending errors
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
}}
|
|
212
|
+
/>
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## TypeScript Support
|
|
216
|
+
|
|
217
|
+
Full TypeScript definitions included:
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
import { BlumessageChat, Message, BlumessageChatProps } from 'blumessage-react-chat-component';
|
|
125
221
|
|
|
126
222
|
interface Message {
|
|
127
223
|
id: string;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
timestamp:
|
|
131
|
-
isOwn: boolean;
|
|
224
|
+
role: 'user' | 'assistant';
|
|
225
|
+
content: string;
|
|
226
|
+
timestamp: number;
|
|
132
227
|
}
|
|
133
228
|
```
|
|
134
229
|
|
|
135
|
-
##
|
|
230
|
+
## API Integration
|
|
136
231
|
|
|
137
|
-
###
|
|
232
|
+
### Message Sending
|
|
233
|
+
```
|
|
234
|
+
POST https://api.blumessage.com/api/v1/conversations
|
|
235
|
+
Content-Type: application/json
|
|
236
|
+
Authorization: Bearer {API_KEY}
|
|
138
237
|
|
|
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
|
-
/>
|
|
238
|
+
{
|
|
239
|
+
"message": "user input",
|
|
240
|
+
"conversationId": "optional-existing-id"
|
|
241
|
+
}
|
|
150
242
|
```
|
|
151
243
|
|
|
152
|
-
###
|
|
244
|
+
### Conversation History
|
|
245
|
+
```
|
|
246
|
+
GET https://api.blumessage.com/api/v1/conversations/session/{conversationId}
|
|
247
|
+
Authorization: {API_KEY}
|
|
248
|
+
```
|
|
153
249
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
};
|
|
250
|
+
### API Key Validation
|
|
251
|
+
```
|
|
252
|
+
POST https://api.blumessage.com/api/v1/api-keys/validate
|
|
253
|
+
Content-Type: application/json
|
|
159
254
|
|
|
160
|
-
|
|
161
|
-
apiKey
|
|
162
|
-
|
|
163
|
-
currentUser={{
|
|
164
|
-
id: 'user123',
|
|
165
|
-
name: 'John Doe',
|
|
166
|
-
avatar: '👤'
|
|
167
|
-
}}
|
|
168
|
-
/>
|
|
255
|
+
{
|
|
256
|
+
"apiKey": "your-api-key"
|
|
257
|
+
}
|
|
169
258
|
```
|
|
170
259
|
|
|
171
|
-
##
|
|
260
|
+
## Storage Behavior
|
|
261
|
+
|
|
262
|
+
- **SessionStorage (default)**: Conversations persist until browser tab closes
|
|
263
|
+
- **LocalStorage (persistent=true)**: Conversations persist across browser sessions
|
|
264
|
+
- **Automatic cleanup**: Invalid conversation IDs are automatically cleared
|
|
265
|
+
- **History restoration**: Previous conversations load automatically on component mount
|
|
266
|
+
|
|
267
|
+
## Browser Support
|
|
172
268
|
|
|
269
|
+
- Modern browsers with ES2017+ support
|
|
173
270
|
- React 18+
|
|
174
|
-
- TypeScript
|
|
271
|
+
- TypeScript 4.5+
|
|
175
272
|
|
|
176
273
|
## License
|
|
177
274
|
|
|
178
|
-
|
|
275
|
+
ISC
|
|
179
276
|
|
|
180
277
|
## Support
|
|
181
278
|
|
|
182
|
-
For
|
|
279
|
+
For issues and feature requests, please visit the [GitHub repository](https://github.com/yourusername/blumessage-react-chat-component).
|