@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 CHANGED
@@ -1,182 +1,279 @@
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 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 '@blumessage/react-chat';
30
+ import { BlumessageChat } from 'blumessage-react-chat-component';
28
31
 
29
32
  function App() {
30
33
  return (
31
- <div style={{ height: '500px' }}>
32
- <BlumessageChat
33
- apiKey="your-blumessage-api-key"
34
- headerTitle="Support Chat"
35
- primaryColor="#3b82f6"
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
- ## API Key Setup
43
+ ### Embedded Chat
45
44
 
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
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
- ## Props
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
- ### Core Props
61
+ ## Complete Props Reference
55
62
 
56
63
  | Prop | Type | Default | Description |
57
64
  |------|------|---------|-------------|
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 |
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
- ### Header Customization
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
- | 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 |
113
+ ### Persistent Storage
76
114
 
77
- ### Layout & Behavior
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
- | 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 |
126
+ ### Custom Styling & Size
87
127
 
88
- ### Colors & Styling
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
- | 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
140
+ ### Embedded with Initial Messages
103
141
 
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
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
- interface User {
121
- id: string;
122
- name: string;
123
- avatar?: string;
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
- text: string;
129
- sender: User;
130
- timestamp: Date;
131
- isOwn: boolean;
224
+ role: 'user' | 'assistant';
225
+ content: string;
226
+ timestamp: number;
132
227
  }
133
228
  ```
134
229
 
135
- ## Advanced Usage
230
+ ## API Integration
136
231
 
137
- ### Custom Styling
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
- ```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
- />
238
+ {
239
+ "message": "user input",
240
+ "conversationId": "optional-existing-id"
241
+ }
150
242
  ```
151
243
 
152
- ### Event Handling
244
+ ### Conversation History
245
+ ```
246
+ GET https://api.blumessage.com/api/v1/conversations/session/{conversationId}
247
+ Authorization: {API_KEY}
248
+ ```
153
249
 
154
- ```tsx
155
- const handleSendMessage = (message: string) => {
156
- console.log('User sent:', message);
157
- // Add your custom logic here
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
- <BlumessageChat
161
- apiKey="your-api-key"
162
- onSendMessage={handleSendMessage}
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
- ## Requirements
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 (recommended)
271
+ - TypeScript 4.5+
175
272
 
176
273
  ## License
177
274
 
178
- MIT © BlueMessage
275
+ ISC
179
276
 
180
277
  ## Support
181
278
 
182
- For support and questions, visit [blumessage.com](https://blumessage.com) or create an issue on GitHub.
279
+ For issues and feature requests, please visit the [GitHub repository](https://github.com/yourusername/blumessage-react-chat-component).