@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 CHANGED
@@ -1,182 +1,289 @@
1
- # @blumessage/react-chat
1
+ # Blumessage React Chat Component
2
2
 
3
- A beautiful, customizable React chat component with BlueMessage AI integration built with TypeScript and Tailwind CSS.
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
- - 💬 Real-time messaging interface with AI responses
8
- - 👤 User avatars and names
9
- - Timestamps and message status
10
- - 📱 Responsive design
11
- - 🎨 Highly customizable styling
12
- - 📝 TypeScript support
13
- - Smooth animations and transitions
14
- - 🤖 BlueMessage AI integration
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 @blumessage/react-chat
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
- <div style={{ height: '500px' }}>
32
- <BlumessageChat
33
- apiKey="your-blumessage-api-key"
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
- ## API Key Setup
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
- **Note:** Without a valid API key, the chat component will be disabled and an error will be logged to the console.
41
+ ```tsx
42
+ import React from 'react';
43
+ import { BlumessageChat } from '@blumessage/react-chat';
51
44
 
52
- ## Props
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
- ### Core Props
57
+ ## Complete Props Reference
55
58
 
56
59
  | Prop | Type | Default | Description |
57
60
  |------|------|---------|-------------|
58
- | `apiKey` | `string` | `undefined` | **Required** - BlueMessage API key for chat functionality. Use `"test"` for demo purposes |
59
- | `messages` | `Message[]` | `[]` | Array of messages to display |
60
- | `onSendMessage` | `(message: string) => void` | `undefined` | Callback when user sends a message |
61
- | `currentUser` | `User` | `{ id: 'user1', name: 'You' }` | Current user information |
62
- | `inputPlaceholder` | `string` | `'Type a message...'` | Input placeholder text |
63
- | `className` | `string` | `''` | Additional CSS classes |
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
- ### Header Customization
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
- | Prop | Type | Default | Description |
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
- ### Layout & Behavior
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
- | Prop | Type | Default | Description |
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
- ### Colors & Styling
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
- | Prop | Type | Default | Description |
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
- | Prop | Type | Default | Description |
105
- |------|------|---------|-------------|
106
- | `messageTimestamps` | `boolean` | `true` | Show message timestamps |
107
- | `messageUserAvatarVisibility` | `boolean` | `false` | Show user avatars |
108
- | `messageUserAvatarIcon` | `string` | `'mdi:account'` | User avatar icon |
109
- | `messageUserAvatarColor` | `string` | `'#3b82f6'` | User avatar background color |
110
- | `messageAssistantAvatarVisibility` | `boolean` | `false` | Show assistant avatars |
111
- | `messageAssistantAvatarIcon` | `string` | `'mdi:robot'` | Assistant avatar icon |
112
- | `messageAssistantAvatarColor` | `string` | `'#6b7280'` | Assistant avatar background color |
113
- | `messageUserName` | `string \| null` | `null` | Display name for user messages |
114
- | `messageAssistantName` | `string \| null` | `null` | Display name for assistant messages |
115
- | `sendButtonIcon` | `string` | `'mdi:send'` | Send button icon |
116
-
117
- ## Types
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
- interface User {
121
- id: string;
122
- name: string;
123
- avatar?: string;
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
- text: string;
129
- sender: User;
130
- timestamp: Date;
131
- isOwn: boolean;
234
+ role: 'user' | 'assistant';
235
+ content: string;
236
+ timestamp: number;
132
237
  }
133
238
  ```
134
239
 
135
- ## Advanced Usage
240
+ ## API Integration
136
241
 
137
- ### Custom Styling
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
- ```tsx
140
- <BlumessageChat
141
- apiKey="your-api-key"
142
- primaryColor="#10b981"
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
- ### Event Handling
254
+ ### Conversation History
255
+ ```
256
+ GET https://api.blumessage.com/api/v1/conversations/session/{conversationId}
257
+ Authorization: {API_KEY}
258
+ ```
153
259
 
154
- ```tsx
155
- const handleSendMessage = (message: string) => {
156
- console.log('User sent:', message);
157
- // Add your custom logic here
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
- <BlumessageChat
161
- apiKey="your-api-key"
162
- onSendMessage={handleSendMessage}
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
- ## Requirements
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 (recommended)
281
+ - TypeScript 4.5+
175
282
 
176
283
  ## License
177
284
 
178
- MIT © BlueMessage
285
+ ISC
179
286
 
180
287
  ## Support
181
288
 
182
- For support and questions, visit [blumessage.com](https://blumessage.com) or create an issue on GitHub.
289
+ For issues and feature requests, please visit the [GitHub repository](https://github.com/Blumessage/react-chat).