@a.izzuddin/ai-chat 0.2.23 → 0.2.25-beta.1
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 +346 -346
- package/README.npm.md +293 -293
- package/custom-elements.json +13 -13
- package/dist/index.js +147 -58
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +147 -58
- package/dist/index.mjs.map +1 -1
- package/global.d.ts +24 -24
- package/package.json +88 -88
package/README.md
CHANGED
|
@@ -1,346 +1,346 @@
|
|
|
1
|
-
# AI Chat Widget
|
|
2
|
-
|
|
3
|
-
A modern, customizable chat widget built with Lit web components. Features a clean UI, responsive design, and extensive theming options.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- 🎨 **Fully Customizable Theme** - Change colors, backgrounds, and styles
|
|
8
|
-
- 📱 **Responsive Design** - Works seamlessly on desktop, tablet, and mobile
|
|
9
|
-
- 🌓 **Dark Mode Support** - Built-in light and dark themes
|
|
10
|
-
- 📦 **Two Display Modes** - Fullscreen or floating widget
|
|
11
|
-
- 🔧 **Easy Integration** - Simple HTML attributes for configuration
|
|
12
|
-
- ⚡ **Built with Lit** - Fast, lightweight web component
|
|
13
|
-
- 🎯 **TypeScript Support** - Full type safety
|
|
14
|
-
- 📝 **List Formatting** - Automatic rendering of bulleted and numbered lists
|
|
15
|
-
- 💡 **Suggested Questions** - Clickable follow-up questions for better UX
|
|
16
|
-
<!-- - 🔗 **Related FAQs** - Display related FAQ references (commented out) -->
|
|
17
|
-
- 👋 **Customizable Welcome Message** - Set custom greeting with optional subtitle
|
|
18
|
-
|
|
19
|
-
## Quick Start
|
|
20
|
-
|
|
21
|
-
### Installation
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
npm install @a.izzuddin/ai-chat
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
### Basic Usage
|
|
28
|
-
|
|
29
|
-
**HTML:**
|
|
30
|
-
```html
|
|
31
|
-
<script type="module">
|
|
32
|
-
import '@a.izzuddin/ai-chat';
|
|
33
|
-
</script>
|
|
34
|
-
|
|
35
|
-
<ai-chat
|
|
36
|
-
api-url="https://your-api-endpoint.com"
|
|
37
|
-
session-id="user-123"
|
|
38
|
-
title="AI Assistant">
|
|
39
|
-
</ai-chat>
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
**React:**
|
|
43
|
-
```jsx
|
|
44
|
-
import '@a.izzuddin/ai-chat';
|
|
45
|
-
|
|
46
|
-
function App() {
|
|
47
|
-
return (
|
|
48
|
-
<ai-chat
|
|
49
|
-
api-url="https://your-api-endpoint.com"
|
|
50
|
-
session-id="user-123"
|
|
51
|
-
title="AI Assistant"
|
|
52
|
-
/>
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
**Vue:**
|
|
58
|
-
```vue
|
|
59
|
-
<template>
|
|
60
|
-
<ai-chat
|
|
61
|
-
api-url="https://your-api-endpoint.com"
|
|
62
|
-
session-id="user-123"
|
|
63
|
-
title="AI Assistant">
|
|
64
|
-
</ai-chat>
|
|
65
|
-
</template>
|
|
66
|
-
|
|
67
|
-
<script setup>
|
|
68
|
-
import '@a.izzuddin/ai-chat';
|
|
69
|
-
</script>
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
## Configuration
|
|
73
|
-
|
|
74
|
-
### Display Modes
|
|
75
|
-
|
|
76
|
-
#### Fullscreen Mode (Default)
|
|
77
|
-
```html
|
|
78
|
-
<ai-chat
|
|
79
|
-
api-url="https://api.example.com"
|
|
80
|
-
session-id="user-123"
|
|
81
|
-
title="AI Assistant"
|
|
82
|
-
mode="fullscreen">
|
|
83
|
-
</ai-chat>
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
#### Widget Mode
|
|
87
|
-
```html
|
|
88
|
-
<ai-chat
|
|
89
|
-
api-url="https://api.example.com"
|
|
90
|
-
session-id="user-123"
|
|
91
|
-
title="AI Assistant"
|
|
92
|
-
mode="widget"
|
|
93
|
-
widget-width="400px"
|
|
94
|
-
widget-height="650px">
|
|
95
|
-
</ai-chat>
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
### Theme Customization
|
|
99
|
-
|
|
100
|
-
#### Custom Colors
|
|
101
|
-
```html
|
|
102
|
-
<ai-chat
|
|
103
|
-
api-url="https://api.example.com"
|
|
104
|
-
session-id="user-123"
|
|
105
|
-
title="AI Assistant"
|
|
106
|
-
primary-color="#10B981"
|
|
107
|
-
primary-color-hover="#059669"
|
|
108
|
-
user-message-bg="#D1FAE5"
|
|
109
|
-
bot-message-bg="#F3F4F6">
|
|
110
|
-
</ai-chat>
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
#### Custom Avatars and Background
|
|
114
|
-
```html
|
|
115
|
-
<ai-chat
|
|
116
|
-
api-url="https://api.example.com"
|
|
117
|
-
session-id="user-123"
|
|
118
|
-
title="AI Assistant"
|
|
119
|
-
bot-avatar-url="/path/to/avatar.png"
|
|
120
|
-
widget-icon-url="/path/to/widget-icon.png"
|
|
121
|
-
background-image-url="/path/to/background.png">
|
|
122
|
-
</ai-chat>
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
**Note:** The `widget-icon-url` sets a custom icon for the floating widget button (only applies in widget mode).
|
|
126
|
-
|
|
127
|
-
#### Custom Welcome Message
|
|
128
|
-
The welcome message appears as the first assistant message in the chat instead of a large empty state.
|
|
129
|
-
|
|
130
|
-
```html
|
|
131
|
-
<ai-chat
|
|
132
|
-
api-url="https://api.example.com"
|
|
133
|
-
session-id="user-123"
|
|
134
|
-
title="AI Assistant"
|
|
135
|
-
welcome-message="Hai, bagaimana saya boleh bantu?"
|
|
136
|
-
welcome-subtitle="Sila tanya tentang permohonan atau apa-apa berkaitan MySTI">
|
|
137
|
-
</ai-chat>
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
The welcome message and subtitle will be combined and displayed as a regular chat message from the assistant.
|
|
141
|
-
|
|
142
|
-
### Dark Mode
|
|
143
|
-
```html
|
|
144
|
-
<ai-chat
|
|
145
|
-
api-url="https://api.example.com"
|
|
146
|
-
session-id="user-123"
|
|
147
|
-
title="AI Assistant"
|
|
148
|
-
theme="dark">
|
|
149
|
-
</ai-chat>
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
## Available Attributes
|
|
153
|
-
|
|
154
|
-
| Attribute | Type | Default | Description |
|
|
155
|
-
|-----------|------|---------|-------------|
|
|
156
|
-
| `api-url` | string | '' | API endpoint URL for chat backend |
|
|
157
|
-
| `session-id` | string | 'default-session' | Unique session identifier |
|
|
158
|
-
| `title` | string | 'My AI Agent' | Chat widget title |
|
|
159
|
-
| `theme` | 'light' or 'dark' | 'light' | Color theme |
|
|
160
|
-
| `mode` | 'fullscreen' or 'widget' | 'fullscreen' | Display mode |
|
|
161
|
-
| `widget-width` | string | '380px' | Widget width (widget mode only) |
|
|
162
|
-
| `widget-height` | string | '600px' | Widget height (widget mode only) |
|
|
163
|
-
| `primary-color` | string | '#4169E1' | Primary brand color |
|
|
164
|
-
| `primary-color-hover` | string | '#3457C7' | Hover state color |
|
|
165
|
-
| `user-message-bg` | string | '#D6E4FF' | User message background |
|
|
166
|
-
| `bot-message-bg` | string | '#F5F5F5' | Bot message background |
|
|
167
|
-
| `bot-avatar-url` | string | '' | Custom bot avatar image |
|
|
168
|
-
| `widget-icon-url` | string | '' | Custom widget button icon (widget mode only) |
|
|
169
|
-
| `background-image-url` | string | '' | Chat background image |
|
|
170
|
-
| `welcome-message` | string | 'How can I help you today?' | Initial message from assistant (appears as first chat message) |
|
|
171
|
-
| `welcome-subtitle` | string | '' | Optional subtitle added to welcome message |
|
|
172
|
-
|
|
173
|
-
## API Integration
|
|
174
|
-
|
|
175
|
-
The chat widget sends POST requests to the configured api-url with the following payload:
|
|
176
|
-
|
|
177
|
-
```json
|
|
178
|
-
{
|
|
179
|
-
"session_id": "string",
|
|
180
|
-
"question": "string"
|
|
181
|
-
}
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
Expected response format:
|
|
185
|
-
|
|
186
|
-
```json
|
|
187
|
-
{
|
|
188
|
-
"response": "string",
|
|
189
|
-
"suggested_follow_ups": [
|
|
190
|
-
"What are the main objectives of the program?",
|
|
191
|
-
"How can companies apply?",
|
|
192
|
-
"Who is eligible for the MySTI logo?"
|
|
193
|
-
]
|
|
194
|
-
}
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
<!-- FAQ functionality - commented out for now
|
|
198
|
-
{
|
|
199
|
-
"response": "string",
|
|
200
|
-
"faq_used": [
|
|
201
|
-
{
|
|
202
|
-
"no.": "1",
|
|
203
|
-
"question": "What is MySTI?"
|
|
204
|
-
}
|
|
205
|
-
],
|
|
206
|
-
"suggested_follow_ups": [...]
|
|
207
|
-
}
|
|
208
|
-
-->
|
|
209
|
-
|
|
210
|
-
**Supported field variations:**
|
|
211
|
-
<!-- - `faq_used` or `faqs_used` for related FAQs (commented out) -->
|
|
212
|
-
- `suggested_follow_ups` or `suggested_questions` for clickable follow-up questions
|
|
213
|
-
|
|
214
|
-
### Response Behavior
|
|
215
|
-
|
|
216
|
-
<!-- - **Related FAQs** - Displayed as non-clickable text references (commented out) -->
|
|
217
|
-
- **Suggested Questions** - Displayed as clickable buttons that send the question when clicked
|
|
218
|
-
- **List Formatting** - Messages support automatic list rendering:
|
|
219
|
-
- Unordered lists: Lines starting with `-`, `*`, or `•`
|
|
220
|
-
- Ordered lists: Lines starting with `1.`, `2.`, etc.
|
|
221
|
-
|
|
222
|
-
### List Formatting Example
|
|
223
|
-
|
|
224
|
-
Your API can return text with lists:
|
|
225
|
-
|
|
226
|
-
```
|
|
227
|
-
MySTI is a government initiative. Key objectives include:
|
|
228
|
-
|
|
229
|
-
1. Stimulating local industry growth
|
|
230
|
-
2. Driving technology-based economic growth
|
|
231
|
-
3. Creating job opportunities
|
|
232
|
-
|
|
233
|
-
Key features:
|
|
234
|
-
- Platform for applicants
|
|
235
|
-
- Database of approved goods
|
|
236
|
-
- Reference for procurement
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
This will be automatically rendered as proper HTML lists.
|
|
240
|
-
|
|
241
|
-
## Events
|
|
242
|
-
|
|
243
|
-
The component fires custom events you can listen to:
|
|
244
|
-
|
|
245
|
-
```javascript
|
|
246
|
-
const chat = document.querySelector('ai-chat');
|
|
247
|
-
|
|
248
|
-
// User sends a message
|
|
249
|
-
chat.addEventListener('message-sent', (event) => {
|
|
250
|
-
console.log('Message sent:', event.detail);
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
// AI responds
|
|
254
|
-
chat.addEventListener('response-received', (event) => {
|
|
255
|
-
console.log('Response received:', event.detail);
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
// Error occurs
|
|
259
|
-
chat.addEventListener('error', (event) => {
|
|
260
|
-
console.error('Error:', event.detail);
|
|
261
|
-
});
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
## Theme Examples
|
|
265
|
-
|
|
266
|
-
### Green Theme (Success)
|
|
267
|
-
```html
|
|
268
|
-
<ai-chat
|
|
269
|
-
primary-color="#10B981"
|
|
270
|
-
primary-color-hover="#059669"
|
|
271
|
-
user-message-bg="#D1FAE5"
|
|
272
|
-
bot-message-bg="#F3F4F6">
|
|
273
|
-
</ai-chat>
|
|
274
|
-
```
|
|
275
|
-
|
|
276
|
-
### Purple Theme (Creative)
|
|
277
|
-
```html
|
|
278
|
-
<ai-chat
|
|
279
|
-
primary-color="#8B5CF6"
|
|
280
|
-
primary-color-hover="#7C3AED"
|
|
281
|
-
user-message-bg="#EDE9FE"
|
|
282
|
-
bot-message-bg="#F5F3FF">
|
|
283
|
-
</ai-chat>
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
### Red Theme (Alert)
|
|
287
|
-
```html
|
|
288
|
-
<ai-chat
|
|
289
|
-
primary-color="#EF4444"
|
|
290
|
-
primary-color-hover="#DC2626"
|
|
291
|
-
user-message-bg="#FEE2E2"
|
|
292
|
-
bot-message-bg="#FEF2F2">
|
|
293
|
-
</ai-chat>
|
|
294
|
-
```
|
|
295
|
-
|
|
296
|
-
### Orange Theme (Warm)
|
|
297
|
-
```html
|
|
298
|
-
<ai-chat
|
|
299
|
-
primary-color="#F97316"
|
|
300
|
-
primary-color-hover="#EA580C"
|
|
301
|
-
user-message-bg="#FFEDD5"
|
|
302
|
-
bot-message-bg="#FFF7ED">
|
|
303
|
-
</ai-chat>
|
|
304
|
-
```
|
|
305
|
-
|
|
306
|
-
## Responsive Behavior
|
|
307
|
-
|
|
308
|
-
The widget automatically adapts to different screen sizes:
|
|
309
|
-
|
|
310
|
-
- **Desktop (>1024px)**: Full widget size
|
|
311
|
-
- **Tablet (769-1024px)**: Slightly larger widget (400px × 650px)
|
|
312
|
-
- **Small Tablet (481-768px)**: Compact widget (360px × 550px)
|
|
313
|
-
- **Mobile Portrait (≤480px)**: Nearly fullscreen (90vw × 70vh)
|
|
314
|
-
- **Mobile Landscape**: Wider widget (500px × adjusted height)
|
|
315
|
-
|
|
316
|
-
## Development
|
|
317
|
-
|
|
318
|
-
### Build for Production
|
|
319
|
-
```bash
|
|
320
|
-
npm run build
|
|
321
|
-
```
|
|
322
|
-
|
|
323
|
-
### Run Development Server
|
|
324
|
-
```bash
|
|
325
|
-
npm run dev
|
|
326
|
-
```
|
|
327
|
-
|
|
328
|
-
### Lint Code
|
|
329
|
-
```bash
|
|
330
|
-
npm run lint
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
## Browser Support
|
|
334
|
-
|
|
335
|
-
- Chrome/Edge (latest)
|
|
336
|
-
- Firefox (latest)
|
|
337
|
-
- Safari (latest)
|
|
338
|
-
- Modern mobile browsers
|
|
339
|
-
|
|
340
|
-
## License
|
|
341
|
-
|
|
342
|
-
MIT
|
|
343
|
-
|
|
344
|
-
## Contributing
|
|
345
|
-
|
|
346
|
-
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
1
|
+
# AI Chat Widget
|
|
2
|
+
|
|
3
|
+
A modern, customizable chat widget built with Lit web components. Features a clean UI, responsive design, and extensive theming options.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🎨 **Fully Customizable Theme** - Change colors, backgrounds, and styles
|
|
8
|
+
- 📱 **Responsive Design** - Works seamlessly on desktop, tablet, and mobile
|
|
9
|
+
- 🌓 **Dark Mode Support** - Built-in light and dark themes
|
|
10
|
+
- 📦 **Two Display Modes** - Fullscreen or floating widget
|
|
11
|
+
- 🔧 **Easy Integration** - Simple HTML attributes for configuration
|
|
12
|
+
- ⚡ **Built with Lit** - Fast, lightweight web component
|
|
13
|
+
- 🎯 **TypeScript Support** - Full type safety
|
|
14
|
+
- 📝 **List Formatting** - Automatic rendering of bulleted and numbered lists
|
|
15
|
+
- 💡 **Suggested Questions** - Clickable follow-up questions for better UX
|
|
16
|
+
<!-- - 🔗 **Related FAQs** - Display related FAQ references (commented out) -->
|
|
17
|
+
- 👋 **Customizable Welcome Message** - Set custom greeting with optional subtitle
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
### Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install @a.izzuddin/ai-chat
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Basic Usage
|
|
28
|
+
|
|
29
|
+
**HTML:**
|
|
30
|
+
```html
|
|
31
|
+
<script type="module">
|
|
32
|
+
import '@a.izzuddin/ai-chat';
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<ai-chat
|
|
36
|
+
api-url="https://your-api-endpoint.com"
|
|
37
|
+
session-id="user-123"
|
|
38
|
+
title="AI Assistant">
|
|
39
|
+
</ai-chat>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**React:**
|
|
43
|
+
```jsx
|
|
44
|
+
import '@a.izzuddin/ai-chat';
|
|
45
|
+
|
|
46
|
+
function App() {
|
|
47
|
+
return (
|
|
48
|
+
<ai-chat
|
|
49
|
+
api-url="https://your-api-endpoint.com"
|
|
50
|
+
session-id="user-123"
|
|
51
|
+
title="AI Assistant"
|
|
52
|
+
/>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Vue:**
|
|
58
|
+
```vue
|
|
59
|
+
<template>
|
|
60
|
+
<ai-chat
|
|
61
|
+
api-url="https://your-api-endpoint.com"
|
|
62
|
+
session-id="user-123"
|
|
63
|
+
title="AI Assistant">
|
|
64
|
+
</ai-chat>
|
|
65
|
+
</template>
|
|
66
|
+
|
|
67
|
+
<script setup>
|
|
68
|
+
import '@a.izzuddin/ai-chat';
|
|
69
|
+
</script>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Configuration
|
|
73
|
+
|
|
74
|
+
### Display Modes
|
|
75
|
+
|
|
76
|
+
#### Fullscreen Mode (Default)
|
|
77
|
+
```html
|
|
78
|
+
<ai-chat
|
|
79
|
+
api-url="https://api.example.com"
|
|
80
|
+
session-id="user-123"
|
|
81
|
+
title="AI Assistant"
|
|
82
|
+
mode="fullscreen">
|
|
83
|
+
</ai-chat>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
#### Widget Mode
|
|
87
|
+
```html
|
|
88
|
+
<ai-chat
|
|
89
|
+
api-url="https://api.example.com"
|
|
90
|
+
session-id="user-123"
|
|
91
|
+
title="AI Assistant"
|
|
92
|
+
mode="widget"
|
|
93
|
+
widget-width="400px"
|
|
94
|
+
widget-height="650px">
|
|
95
|
+
</ai-chat>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Theme Customization
|
|
99
|
+
|
|
100
|
+
#### Custom Colors
|
|
101
|
+
```html
|
|
102
|
+
<ai-chat
|
|
103
|
+
api-url="https://api.example.com"
|
|
104
|
+
session-id="user-123"
|
|
105
|
+
title="AI Assistant"
|
|
106
|
+
primary-color="#10B981"
|
|
107
|
+
primary-color-hover="#059669"
|
|
108
|
+
user-message-bg="#D1FAE5"
|
|
109
|
+
bot-message-bg="#F3F4F6">
|
|
110
|
+
</ai-chat>
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
#### Custom Avatars and Background
|
|
114
|
+
```html
|
|
115
|
+
<ai-chat
|
|
116
|
+
api-url="https://api.example.com"
|
|
117
|
+
session-id="user-123"
|
|
118
|
+
title="AI Assistant"
|
|
119
|
+
bot-avatar-url="/path/to/avatar.png"
|
|
120
|
+
widget-icon-url="/path/to/widget-icon.png"
|
|
121
|
+
background-image-url="/path/to/background.png">
|
|
122
|
+
</ai-chat>
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**Note:** The `widget-icon-url` sets a custom icon for the floating widget button (only applies in widget mode).
|
|
126
|
+
|
|
127
|
+
#### Custom Welcome Message
|
|
128
|
+
The welcome message appears as the first assistant message in the chat instead of a large empty state.
|
|
129
|
+
|
|
130
|
+
```html
|
|
131
|
+
<ai-chat
|
|
132
|
+
api-url="https://api.example.com"
|
|
133
|
+
session-id="user-123"
|
|
134
|
+
title="AI Assistant"
|
|
135
|
+
welcome-message="Hai, bagaimana saya boleh bantu?"
|
|
136
|
+
welcome-subtitle="Sila tanya tentang permohonan atau apa-apa berkaitan MySTI">
|
|
137
|
+
</ai-chat>
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
The welcome message and subtitle will be combined and displayed as a regular chat message from the assistant.
|
|
141
|
+
|
|
142
|
+
### Dark Mode
|
|
143
|
+
```html
|
|
144
|
+
<ai-chat
|
|
145
|
+
api-url="https://api.example.com"
|
|
146
|
+
session-id="user-123"
|
|
147
|
+
title="AI Assistant"
|
|
148
|
+
theme="dark">
|
|
149
|
+
</ai-chat>
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Available Attributes
|
|
153
|
+
|
|
154
|
+
| Attribute | Type | Default | Description |
|
|
155
|
+
|-----------|------|---------|-------------|
|
|
156
|
+
| `api-url` | string | '' | API endpoint URL for chat backend |
|
|
157
|
+
| `session-id` | string | 'default-session' | Unique session identifier |
|
|
158
|
+
| `title` | string | 'My AI Agent' | Chat widget title |
|
|
159
|
+
| `theme` | 'light' or 'dark' | 'light' | Color theme |
|
|
160
|
+
| `mode` | 'fullscreen' or 'widget' | 'fullscreen' | Display mode |
|
|
161
|
+
| `widget-width` | string | '380px' | Widget width (widget mode only) |
|
|
162
|
+
| `widget-height` | string | '600px' | Widget height (widget mode only) |
|
|
163
|
+
| `primary-color` | string | '#4169E1' | Primary brand color |
|
|
164
|
+
| `primary-color-hover` | string | '#3457C7' | Hover state color |
|
|
165
|
+
| `user-message-bg` | string | '#D6E4FF' | User message background |
|
|
166
|
+
| `bot-message-bg` | string | '#F5F5F5' | Bot message background |
|
|
167
|
+
| `bot-avatar-url` | string | '' | Custom bot avatar image |
|
|
168
|
+
| `widget-icon-url` | string | '' | Custom widget button icon (widget mode only) |
|
|
169
|
+
| `background-image-url` | string | '' | Chat background image |
|
|
170
|
+
| `welcome-message` | string | 'How can I help you today?' | Initial message from assistant (appears as first chat message) |
|
|
171
|
+
| `welcome-subtitle` | string | '' | Optional subtitle added to welcome message |
|
|
172
|
+
|
|
173
|
+
## API Integration
|
|
174
|
+
|
|
175
|
+
The chat widget sends POST requests to the configured api-url with the following payload:
|
|
176
|
+
|
|
177
|
+
```json
|
|
178
|
+
{
|
|
179
|
+
"session_id": "string",
|
|
180
|
+
"question": "string"
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Expected response format:
|
|
185
|
+
|
|
186
|
+
```json
|
|
187
|
+
{
|
|
188
|
+
"response": "string",
|
|
189
|
+
"suggested_follow_ups": [
|
|
190
|
+
"What are the main objectives of the program?",
|
|
191
|
+
"How can companies apply?",
|
|
192
|
+
"Who is eligible for the MySTI logo?"
|
|
193
|
+
]
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
<!-- FAQ functionality - commented out for now
|
|
198
|
+
{
|
|
199
|
+
"response": "string",
|
|
200
|
+
"faq_used": [
|
|
201
|
+
{
|
|
202
|
+
"no.": "1",
|
|
203
|
+
"question": "What is MySTI?"
|
|
204
|
+
}
|
|
205
|
+
],
|
|
206
|
+
"suggested_follow_ups": [...]
|
|
207
|
+
}
|
|
208
|
+
-->
|
|
209
|
+
|
|
210
|
+
**Supported field variations:**
|
|
211
|
+
<!-- - `faq_used` or `faqs_used` for related FAQs (commented out) -->
|
|
212
|
+
- `suggested_follow_ups` or `suggested_questions` for clickable follow-up questions
|
|
213
|
+
|
|
214
|
+
### Response Behavior
|
|
215
|
+
|
|
216
|
+
<!-- - **Related FAQs** - Displayed as non-clickable text references (commented out) -->
|
|
217
|
+
- **Suggested Questions** - Displayed as clickable buttons that send the question when clicked
|
|
218
|
+
- **List Formatting** - Messages support automatic list rendering:
|
|
219
|
+
- Unordered lists: Lines starting with `-`, `*`, or `•`
|
|
220
|
+
- Ordered lists: Lines starting with `1.`, `2.`, etc.
|
|
221
|
+
|
|
222
|
+
### List Formatting Example
|
|
223
|
+
|
|
224
|
+
Your API can return text with lists:
|
|
225
|
+
|
|
226
|
+
```
|
|
227
|
+
MySTI is a government initiative. Key objectives include:
|
|
228
|
+
|
|
229
|
+
1. Stimulating local industry growth
|
|
230
|
+
2. Driving technology-based economic growth
|
|
231
|
+
3. Creating job opportunities
|
|
232
|
+
|
|
233
|
+
Key features:
|
|
234
|
+
- Platform for applicants
|
|
235
|
+
- Database of approved goods
|
|
236
|
+
- Reference for procurement
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
This will be automatically rendered as proper HTML lists.
|
|
240
|
+
|
|
241
|
+
## Events
|
|
242
|
+
|
|
243
|
+
The component fires custom events you can listen to:
|
|
244
|
+
|
|
245
|
+
```javascript
|
|
246
|
+
const chat = document.querySelector('ai-chat');
|
|
247
|
+
|
|
248
|
+
// User sends a message
|
|
249
|
+
chat.addEventListener('message-sent', (event) => {
|
|
250
|
+
console.log('Message sent:', event.detail);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
// AI responds
|
|
254
|
+
chat.addEventListener('response-received', (event) => {
|
|
255
|
+
console.log('Response received:', event.detail);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
// Error occurs
|
|
259
|
+
chat.addEventListener('error', (event) => {
|
|
260
|
+
console.error('Error:', event.detail);
|
|
261
|
+
});
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## Theme Examples
|
|
265
|
+
|
|
266
|
+
### Green Theme (Success)
|
|
267
|
+
```html
|
|
268
|
+
<ai-chat
|
|
269
|
+
primary-color="#10B981"
|
|
270
|
+
primary-color-hover="#059669"
|
|
271
|
+
user-message-bg="#D1FAE5"
|
|
272
|
+
bot-message-bg="#F3F4F6">
|
|
273
|
+
</ai-chat>
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### Purple Theme (Creative)
|
|
277
|
+
```html
|
|
278
|
+
<ai-chat
|
|
279
|
+
primary-color="#8B5CF6"
|
|
280
|
+
primary-color-hover="#7C3AED"
|
|
281
|
+
user-message-bg="#EDE9FE"
|
|
282
|
+
bot-message-bg="#F5F3FF">
|
|
283
|
+
</ai-chat>
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Red Theme (Alert)
|
|
287
|
+
```html
|
|
288
|
+
<ai-chat
|
|
289
|
+
primary-color="#EF4444"
|
|
290
|
+
primary-color-hover="#DC2626"
|
|
291
|
+
user-message-bg="#FEE2E2"
|
|
292
|
+
bot-message-bg="#FEF2F2">
|
|
293
|
+
</ai-chat>
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### Orange Theme (Warm)
|
|
297
|
+
```html
|
|
298
|
+
<ai-chat
|
|
299
|
+
primary-color="#F97316"
|
|
300
|
+
primary-color-hover="#EA580C"
|
|
301
|
+
user-message-bg="#FFEDD5"
|
|
302
|
+
bot-message-bg="#FFF7ED">
|
|
303
|
+
</ai-chat>
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
## Responsive Behavior
|
|
307
|
+
|
|
308
|
+
The widget automatically adapts to different screen sizes:
|
|
309
|
+
|
|
310
|
+
- **Desktop (>1024px)**: Full widget size
|
|
311
|
+
- **Tablet (769-1024px)**: Slightly larger widget (400px × 650px)
|
|
312
|
+
- **Small Tablet (481-768px)**: Compact widget (360px × 550px)
|
|
313
|
+
- **Mobile Portrait (≤480px)**: Nearly fullscreen (90vw × 70vh)
|
|
314
|
+
- **Mobile Landscape**: Wider widget (500px × adjusted height)
|
|
315
|
+
|
|
316
|
+
## Development
|
|
317
|
+
|
|
318
|
+
### Build for Production
|
|
319
|
+
```bash
|
|
320
|
+
npm run build
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
### Run Development Server
|
|
324
|
+
```bash
|
|
325
|
+
npm run dev
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### Lint Code
|
|
329
|
+
```bash
|
|
330
|
+
npm run lint
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
## Browser Support
|
|
334
|
+
|
|
335
|
+
- Chrome/Edge (latest)
|
|
336
|
+
- Firefox (latest)
|
|
337
|
+
- Safari (latest)
|
|
338
|
+
- Modern mobile browsers
|
|
339
|
+
|
|
340
|
+
## License
|
|
341
|
+
|
|
342
|
+
MIT
|
|
343
|
+
|
|
344
|
+
## Contributing
|
|
345
|
+
|
|
346
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|