nextjs-chatbot-ui 1.0.0
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/LICENSE +21 -0
- package/README.md +317 -0
- package/components/AdminSetup.tsx +566 -0
- package/components/Chatbot.tsx +465 -0
- package/index.tsx +5 -0
- package/package.json +62 -0
- package/types/admin.ts +29 -0
- package/types/index.ts +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
# Chatbot UI Component
|
|
2
|
+
|
|
3
|
+
A beautiful, configurable chatbot UI component for Next.js applications with Tailwind CSS. Inspired by Sendbird's modern chat interface.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🎨 Modern, Sendbird-inspired UI design
|
|
8
|
+
- ⚙️ Fully configurable (labels, position, colors, backend URL)
|
|
9
|
+
- 📱 Responsive and mobile-friendly
|
|
10
|
+
- 🎯 TypeScript support
|
|
11
|
+
- 🚀 Easy to integrate
|
|
12
|
+
- 💬 Real-time messaging support
|
|
13
|
+
- 🎭 Customizable user and bot avatars
|
|
14
|
+
- ⏰ Optional timestamp display
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install nextjs-nextjs-chatbot-ui
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### Basic Setup
|
|
25
|
+
|
|
26
|
+
1. **Configure Tailwind CSS** - Make sure your `tailwind.config.js` includes the component:
|
|
27
|
+
|
|
28
|
+
```javascript
|
|
29
|
+
// tailwind.config.js
|
|
30
|
+
module.exports = {
|
|
31
|
+
content: [
|
|
32
|
+
'./node_modules/nextjs-chatbot-ui/**/*.{js,ts,jsx,tsx}',
|
|
33
|
+
'./app/**/*.{js,ts,jsx,tsx,mdx}',
|
|
34
|
+
'./pages/**/*.{js,ts,jsx,tsx,mdx}',
|
|
35
|
+
'./components/**/*.{js,ts,jsx,tsx,mdx}',
|
|
36
|
+
],
|
|
37
|
+
// ... rest of your config
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
2. **Import the component and types**:
|
|
42
|
+
|
|
43
|
+
```javascript
|
|
44
|
+
import { Chatbot } from 'nextjs-nextjs-chatbot-ui';
|
|
45
|
+
import type { ChatbotConfig } from 'nextjs-nextjs-chatbot-ui';
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
2. Configure and use the component:
|
|
49
|
+
|
|
50
|
+
```javascript
|
|
51
|
+
const config: ChatbotConfig = {
|
|
52
|
+
backendUrl: 'https://your-backend-api.com/chat',
|
|
53
|
+
labels: {
|
|
54
|
+
title: 'Support Chat',
|
|
55
|
+
placeholder: 'Type your message...',
|
|
56
|
+
sendButton: 'Send',
|
|
57
|
+
welcomeMessage: 'Hello! How can I help you?',
|
|
58
|
+
},
|
|
59
|
+
position: 'bottom-right',
|
|
60
|
+
botInfo: {
|
|
61
|
+
name: 'Support Bot',
|
|
62
|
+
avatar: 'https://example.com/bot-avatar.png',
|
|
63
|
+
},
|
|
64
|
+
userInfo: {
|
|
65
|
+
name: 'User',
|
|
66
|
+
avatar: 'https://example.com/user-avatar.png',
|
|
67
|
+
},
|
|
68
|
+
primaryColor: '#0ea5e9',
|
|
69
|
+
autoOpen: false,
|
|
70
|
+
showTimestamp: true,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export default function Page() {
|
|
74
|
+
return <Chatbot config={config} />;
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Configuration Options
|
|
79
|
+
|
|
80
|
+
#### `ChatbotConfig` Interface
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
interface ChatbotConfig {
|
|
84
|
+
// Required
|
|
85
|
+
backendUrl: string; // Your backend API endpoint for handling messages
|
|
86
|
+
|
|
87
|
+
// Optional Labels
|
|
88
|
+
labels?: {
|
|
89
|
+
title?: string; // Chat header title (default: "Chat Support")
|
|
90
|
+
placeholder?: string; // Input placeholder (default: "Type your message...")
|
|
91
|
+
sendButton?: string; // Send button text (default: "Send")
|
|
92
|
+
typingIndicator?: string; // Loading message (default: "Typing...")
|
|
93
|
+
welcomeMessage?: string; // Initial bot message (default: "Hello! How can I help you today?")
|
|
94
|
+
errorMessage?: string; // Error message (default: "Sorry, something went wrong. Please try again.")
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// Position
|
|
98
|
+
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left'; // Default: 'bottom-right'
|
|
99
|
+
|
|
100
|
+
// User Information
|
|
101
|
+
userInfo?: {
|
|
102
|
+
name?: string; // User name
|
|
103
|
+
avatar?: string; // User avatar URL
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// Bot Information
|
|
107
|
+
botInfo?: {
|
|
108
|
+
name?: string; // Bot name (default: uses title)
|
|
109
|
+
avatar?: string; // Bot avatar URL
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// Styling
|
|
113
|
+
primaryColor?: string; // Primary color (hex code)
|
|
114
|
+
backgroundColor?: string; // Chat background color (hex code)
|
|
115
|
+
|
|
116
|
+
// Behavior
|
|
117
|
+
autoOpen?: boolean; // Auto-open chat on load (default: false)
|
|
118
|
+
showTimestamp?: boolean; // Show message timestamps (default: false)
|
|
119
|
+
showDateSeparator?: boolean; // Show date separators between messages (default: false)
|
|
120
|
+
poweredByText?: string; // Footer text (e.g., "Powered by sendbird")
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Backend API Requirements
|
|
125
|
+
|
|
126
|
+
Your backend should accept POST requests with the following format:
|
|
127
|
+
|
|
128
|
+
**Request:**
|
|
129
|
+
```json
|
|
130
|
+
{
|
|
131
|
+
"message": "User's message text",
|
|
132
|
+
"userInfo": {
|
|
133
|
+
"name": "User",
|
|
134
|
+
"avatar": "https://example.com/avatar.png"
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
**Response:**
|
|
140
|
+
```json
|
|
141
|
+
{
|
|
142
|
+
"message": "Bot's response text",
|
|
143
|
+
"suggestedReplies": ["Option 1", "Option 2", "Option 3"]
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
or
|
|
148
|
+
|
|
149
|
+
```json
|
|
150
|
+
{
|
|
151
|
+
"response": "Bot's response text",
|
|
152
|
+
"suggestions": ["Option 1", "Option 2", "Option 3"]
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
**Note:** The `suggestedReplies` or `suggestions` field is optional and will display as clickable buttons below the bot's message, similar to Sendbird's interface.
|
|
157
|
+
|
|
158
|
+
### Example Implementation
|
|
159
|
+
|
|
160
|
+
```javascript
|
|
161
|
+
// pages/index.js or app/page.js
|
|
162
|
+
'use client';
|
|
163
|
+
|
|
164
|
+
import { Chatbot } from 'nextjs-nextjs-chatbot-ui';
|
|
165
|
+
import type { ChatbotConfig } from 'nextjs-nextjs-chatbot-ui';
|
|
166
|
+
|
|
167
|
+
export default function Home() {
|
|
168
|
+
const chatbotConfig: ChatbotConfig = {
|
|
169
|
+
backendUrl: 'https://api.example.com/chat',
|
|
170
|
+
labels: {
|
|
171
|
+
title: 'Customer Support',
|
|
172
|
+
placeholder: 'Ask us anything...',
|
|
173
|
+
sendButton: 'Send',
|
|
174
|
+
welcomeMessage: 'Welcome! We\'re here to help.',
|
|
175
|
+
},
|
|
176
|
+
position: 'bottom-right',
|
|
177
|
+
botInfo: {
|
|
178
|
+
name: 'Support Assistant',
|
|
179
|
+
avatar: '/bot-avatar.png',
|
|
180
|
+
},
|
|
181
|
+
userInfo: {
|
|
182
|
+
name: 'Guest User',
|
|
183
|
+
},
|
|
184
|
+
primaryColor: '#6B46C1', // Purple like Sendbird
|
|
185
|
+
autoOpen: false,
|
|
186
|
+
showTimestamp: true,
|
|
187
|
+
showDateSeparator: true,
|
|
188
|
+
poweredByText: 'Powered by nextjs-nextjs-chatbot-ui',
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
return (
|
|
192
|
+
<div>
|
|
193
|
+
<h1>My Website</h1>
|
|
194
|
+
<Chatbot config={chatbotConfig} />
|
|
195
|
+
</div>
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Tailwind CSS Setup
|
|
201
|
+
|
|
202
|
+
Make sure you have Tailwind CSS configured in your Next.js project. The component uses Tailwind classes, so ensure your `tailwind.config.js` includes the component:
|
|
203
|
+
|
|
204
|
+
```javascript
|
|
205
|
+
// tailwind.config.js
|
|
206
|
+
module.exports = {
|
|
207
|
+
content: [
|
|
208
|
+
'./node_modules/nextjs-chatbot-ui/**/*.{js,ts,jsx,tsx}',
|
|
209
|
+
// ... your other paths
|
|
210
|
+
],
|
|
211
|
+
// ... rest of your config
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## Development
|
|
216
|
+
|
|
217
|
+
To develop or modify this package:
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
# Install dependencies
|
|
221
|
+
npm install
|
|
222
|
+
|
|
223
|
+
# Run development server
|
|
224
|
+
npm run dev
|
|
225
|
+
|
|
226
|
+
# Build for production
|
|
227
|
+
npm run build
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## Admin Setup Component
|
|
231
|
+
|
|
232
|
+
The package also includes an `AdminSetup` component for configuring database connections in your admin panel.
|
|
233
|
+
|
|
234
|
+
### Usage
|
|
235
|
+
|
|
236
|
+
```javascript
|
|
237
|
+
import { AdminSetup } from 'nextjs-nextjs-chatbot-ui';
|
|
238
|
+
import type { DatabaseConfig, DatabaseConnection } from 'nextjs-nextjs-chatbot-ui';
|
|
239
|
+
|
|
240
|
+
function AdminPanel() {
|
|
241
|
+
const handleSave = (config: DatabaseConfig) => {
|
|
242
|
+
// Save configuration to your backend
|
|
243
|
+
console.log('Config:', config);
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
const handleTestConnection = async (connection: DatabaseConnection) => {
|
|
247
|
+
// Test database connection
|
|
248
|
+
const response = await fetch('/api/database/test', {
|
|
249
|
+
method: 'POST',
|
|
250
|
+
body: JSON.stringify(connection),
|
|
251
|
+
});
|
|
252
|
+
return response.ok;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
const handleFetchColumns = async (connection: DatabaseConnection) => {
|
|
256
|
+
// Fetch columns from database
|
|
257
|
+
const response = await fetch('/api/database/columns', {
|
|
258
|
+
method: 'POST',
|
|
259
|
+
body: JSON.stringify(connection),
|
|
260
|
+
});
|
|
261
|
+
const data = await response.json();
|
|
262
|
+
return data.columns || [];
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
return (
|
|
266
|
+
<aside className="sidebar">
|
|
267
|
+
<AdminSetup
|
|
268
|
+
onSave={handleSave}
|
|
269
|
+
onTestConnection={handleTestConnection}
|
|
270
|
+
onFetchColumns={handleFetchColumns}
|
|
271
|
+
/>
|
|
272
|
+
</aside>
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Features
|
|
278
|
+
|
|
279
|
+
- **Database Selection**: Choose between MongoDB and PostgreSQL
|
|
280
|
+
- **Connection Configuration**: Configure all necessary connection parameters
|
|
281
|
+
- **Connection Testing**: Test database connection before proceeding
|
|
282
|
+
- **Column Selection**: Select columns for:
|
|
283
|
+
- Embedding processing
|
|
284
|
+
- LLM processing
|
|
285
|
+
- ChromaDB storage
|
|
286
|
+
- **Modal Interface**: Clean, step-by-step modal interface
|
|
287
|
+
- **Sidebar Integration**: Ready to integrate into admin panel sidebars
|
|
288
|
+
|
|
289
|
+
### Database Configuration
|
|
290
|
+
|
|
291
|
+
The component supports:
|
|
292
|
+
- **MongoDB**: Connection string or individual fields (host, port, database, SSL)
|
|
293
|
+
- **PostgreSQL**: Host, port, database, username, password, SSL
|
|
294
|
+
|
|
295
|
+
### Backend API Requirements
|
|
296
|
+
|
|
297
|
+
Your backend should provide:
|
|
298
|
+
|
|
299
|
+
1. **Test Connection Endpoint** (`POST /api/database/test`)
|
|
300
|
+
- Accepts `DatabaseConnection` object
|
|
301
|
+
- Returns success/failure status
|
|
302
|
+
|
|
303
|
+
2. **Fetch Columns Endpoint** (`POST /api/database/columns`)
|
|
304
|
+
- Accepts `DatabaseConnection` object
|
|
305
|
+
- Returns array of column names
|
|
306
|
+
|
|
307
|
+
3. **Save Configuration Endpoint** (your implementation)
|
|
308
|
+
- Accepts `DatabaseConfig` object
|
|
309
|
+
- Saves configuration to your storage
|
|
310
|
+
|
|
311
|
+
## License
|
|
312
|
+
|
|
313
|
+
MIT
|
|
314
|
+
|
|
315
|
+
## Contributing
|
|
316
|
+
|
|
317
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|