@infomatebot/chatbot-widget
Version:
Build intelligent chatbots using pre-designed conversation flows with quick reply options. Upload documents for AI-powered, context-aware responses and reduce support costs by 80% with guided conversations
255 lines (192 loc) โข 6.29 kB
Markdown
Web component chatbot widget built with TypeScript and Vite. Embeddable widget for websites with conversation flows and AI-powered responses.
```bash
npm install
npm run dev
npm run build
```
- **Node.js**: 18.x or higher
- **Backend API**: InfoMate API running on http://localhost:3000
- **Web Components**: Custom element `<infomate-chatbot>`
- **TypeScript**: Full type safety
- **Conversation Flows**: Support for quick replies and input collectors
- **Theming**: Light/dark themes with custom colors
- **Responsive**: Works on desktop and mobile
- **Position Options**: bottom-right, bottom-left, top-right, top-left
- **Size Options**: small, medium, large, xl
```html
<infomate-chatbot
api-key="your-api-key-here"
api-base-url="http://localhost:3000"
bot-name="InfoMate Assistant"
welcome-message="Hi! How can I help you today?"
primary-color="#667eea"
secondary-color="#764ba2"
size="medium"
position="bottom-right"
theme="light"
auto-open="false"
show-powered-by="true">
</infomate-chatbot>
```
| Attribute | Type | Default | Options |
|-----------|------|---------|---------|
| `api-key` | string | **Required** | Your API key |
| `api-base-url` | string | `http://localhost:3000` | API base URL |
| `bot-name` | string | `InfoMate Assistant` | Bot display name |
| `welcome-message` | string | `Hi! How can I help you today?` | Initial message |
| `primary-color` | string | `
| `secondary-color` | string | `
| `size` | string | `medium` | `small`, `medium`, `large`, `xl` |
| `position` | string | `bottom-right` | `bottom-right`, `bottom-left`, `top-right`, `top-left` |
| `theme` | string | `light` | `light`, `dark` |
| `auto-open` | boolean | `false` | Auto-open on load |
| `show-powered-by` | boolean | `true` | Show branding |
- **POST** `/api/chat/start` - Initialize chat session
- **POST** `/api/chat/send` - Send messages
- **POST** `/api/chat/session/validate` - Validate session (commented)
- **GET** `/api/chat/conversation/history` - Get history (commented)
- **POST** `/api/chat/feedback` - Send feedback (commented)
### Events
```javascript
const widget = document.querySelector('infomate-chatbot');
// Chat lifecycle events
widget.addEventListener('chatbot:opened', () => console.log('Chat opened'));
widget.addEventListener('chatbot:closed', () => console.log('Chat closed'));
widget.addEventListener('chatbot:message', (e) => console.log('Message:', e.detail));
widget.addEventListener('chatbot:error', (e) => console.error('Error:', e.detail));
// Typing events
widget.addEventListener('chatbot:typing-start', () => console.log('Bot typing...'));
widget.addEventListener('chatbot:typing-end', () => console.log('Bot stopped typing'));
// Action events (conversation flows)
widget.addEventListener('chatbot:action-executed', (e) => console.log('Action:', e.detail));
widget.addEventListener('chatbot:input-requested', (e) => console.log('Input requested'));
widget.addEventListener('chatbot:input-submitted', (e) => console.log('Input submitted'));
```
Automatic rendering when API returns quick replies:
```json
{
"message": "How can I help you?",
"quickReplies": [
{ "id": "help", "label": "Help" },
{ "id": "services", "label": "Our Services" },
{ "id": "contact", "label": "Contact Us" }
]
}
```
Support for form-like data collection:
```json
{
"inputCollector": {
"fields": [
{
"name": "email",
"type": "email",
"label": "Email",
"required": true,
"validation": "email"
},
{
"name": "message",
"type": "textarea",
"label": "Message",
"required": true
}
]
}
}
```
```css
infomate-chatbot {
--chatbot-primary-color:
--chatbot-secondary-color:
--chatbot-background-color:
--chatbot-text-color:
--chatbot-border-color:
--chatbot-z-index: 999999;
}
```
- **small**: 320x450px
- **medium**: 380x520px
- **large**: 450x600px
- **xl**: 520x680px
- **light**: White background, dark text
- **dark**: Dark background, light text
```bash
npm test
npm run test:watch
npm run test:ui
npm run test:coverage
npm run test:integration
```
```bash
npm run dev
npm run typecheck
npm run lint
npm run format
```
```bash
npm run build
npm run test:build
npm run size
```
- `dist/index.umd.js` - UMD bundle
- `dist/index.esm.js` - ES modules
- `dist/index.d.ts` - TypeScript definitions
```
src/
โโโ constants/
โโโ types/
โโโ ui/
โโโ utils/
โโโ services/
โโโ index.ts
```
- `src/index.ts` - Web component registration
- `src/constants/defaults.ts` - Default configuration
- `src/types/internal.types.ts` - Type definitions
- `src/ui/` - UI components and styles
- `vite.config.js` - Build configuration
Commercial license. All rights reserved.
- **Documentation**: See `examples/` folder
- **Issue Tracking**: Internal issue tracker