SDK & Embed Pages¶
Purpose: Widget embedding and SDK documentation
Category: Integration
Pages: 1 page
Audience: Developers
SDK Chatbot Page¶
File: src/app/sdk-chatbot/page.tsx
Route: /sdk-chatbot
Type: Public
Purpose: Embedded chatbot widget and SDK documentation
Features¶
1. Widget Preview
- Live chatbot widget demo
- Embedded in page
- Shows actual chatbot in action
- Customizable theme preview
2. Embed Code Generator
- Copy-paste embed code
- HTML snippet
- JavaScript SDK
- Customization options
3. Configuration Options
- Avatar selection
- Color theme
- Position (bottom-right, bottom-left, etc.)
- Size (small, medium, large)
- Initial greeting message
- Popup delay
4. SDK Documentation
- Installation instructions
- API reference
- Configuration options
- Event listeners
- Methods
- Examples
Embed Code Format¶
HTML Snippet:
<!-- MachineAvatars Chatbot Widget -->
<script>
window.MachineAvatarsConfig = {
botId: "your_bot_id_here",
theme: "light", // or "dark"
position: "bottom-right",
primaryColor: "#FF6622",
greeting: "Hi! How can I help you today?",
avatar: "Emma",
};
</script>
<script src="https://cdn.machineavatars.com/widget.js" async></script>
React Component:
import { MachineAvatarsWidget } from "@machineavatars/react";
function App() {
return (
<MachineAvatarsWidget
botId="your_bot_id_here"
theme="light"
position="bottom-right"
/>
);
}
SDK Methods¶
Initialize:
Show/Hide:
Send Message (Programmatic):
Event Listeners:
MachineAvatars.on("message", (data) => {
console.log("New message:", data);
});
MachineAvatars.on("widgetOpened", () => {
console.log("Widget opened");
});
MachineAvatars.on("widgetClosed", () => {
console.log("Widget closed");
});
Customization Options¶
| Option | Type | Default | Description |
|---|---|---|---|
botId |
string | Required | Unique chatbot ID |
theme |
"light" \| "dark" |
"light" | Color theme |
position |
"bottom-right" \| "bottom-left" \| "top-right" \| "top-left" |
"bottom-right" | Widget position |
primaryColor |
string | "#FF6622" | Brand color |
greeting |
string | "Hi! How can I help?" | Initial message |
avatar |
string | "Emma" | Avatar name |
language |
string | "en" | Language code |
zIndex |
number | 999999 | CSS z-index |
showBranding |
boolean | true | Show "Powered by" |
Installation Methods¶
Via CDN (Recommended):
Via NPM:
Via React:
Widget Behavior¶
Desktop:
- Appears in corner
- Minimizable button
- Expands to chat window
- Can be dragged (optional)
Mobile:
- Full-screen overlay
- Slide-up animation
- Native feel
Responsive:
- Auto-adjusts to screen size
- Touch-friendly
- Keyboard accessible
Security¶
- HTTPS required
- Domain whitelist
- Rate limiting
- XSS protection
- CORS configured
Analytics Integration¶
Track Events:
User Identification:
API Endpoints¶
GET /v2/widget/{botId}/config- Get widget configurationPOST /v2/widget/{botId}/message- Send messageGET /v2/widget/{botId}/chat-history- Get chat historyPOST /v2/widget/{botId}/track- Track event
Browser Support¶
- Chrome 90+
- Firefox 88+
- Safari 14+
- Edge 90+
- Mobile Safari (iOS 13+)
- Chrome Mobile (Android 8+)
Dependencies¶
- None (vanilla JavaScript)
- Optional: React bindings
File Size¶
- Main SDK: ~50KB (minified + gzipped)
- React wrapper: +15KB
Code Preview Component¶
Interactive Code Editor:
- Syntax highlighting
- Copy button
- Edit options
- Live preview
Estimated Lines: ~600 lines
"Embed anywhere, customize everything."