Skip to content

Commit 807f4ad

Browse files
committed
docs: create comprehensive README for widget with accurate technical details
- Complete feature overview (text chat, voice calls, error handling) - Architecture documentation with Mermaid diagram - API integration details and WebSocket events - Configuration options and programmatic usage - Development workflow and build process - Performance, security, and deployment guidance - .gitignore: allow widget/README.md to be tracked
1 parent 28bce3a commit 807f4ad

2 files changed

Lines changed: 324 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ docs/*.md
8989
!docs/DEPLOYMENT.md
9090
!docs/SECURITY.md
9191
!docs/CONTRIBUTING.md
92+
!widget/README.md
9293

9394
# Keep license file
9495
LICENSE

widget/README.md

Lines changed: 323 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,323 @@
1+
# 🤖 Syntera Embeddable Widget
2+
3+
**Production-ready AI chat widget for website integration with real-time voice calls and comprehensive error handling.**
4+
5+
## Overview
6+
7+
The Syntera widget is a standalone, embeddable TypeScript application that provides AI-powered customer support directly on any website. It features real-time text chat, voice calls via LiveKit, WebSocket connectivity, and enterprise-grade error handling.
8+
9+
**Technology**: TypeScript, Vite, LiveKit WebRTC, Socket.io
10+
**Bundle Size**: ~200KB gzipped
11+
**Browser Support**: Modern browsers with WebRTC support
12+
13+
## Core Features
14+
15+
### 💬 **Real-time Text Chat**
16+
- **WebSocket connectivity** - Persistent connections with automatic reconnection
17+
- **Message threading** - Conversation organization and context management
18+
- **Typing indicators** - Real-time user feedback
19+
- **Message history** - Persistent conversation storage
20+
- **File attachments** - Support for document uploads
21+
22+
### 🎤 **Voice Call Integration**
23+
- **LiveKit WebRTC** - Low-latency voice communication
24+
- **Audio streaming** - Real-time bidirectional audio
25+
- **Call controls** - Mute/unmute, volume controls
26+
- **Connection resilience** - Automatic reconnection on network issues
27+
- **Background noise handling** - Audio quality optimization
28+
29+
### 🎨 **Advanced UI/UX**
30+
- **Floating widget button** - Customizable position and styling
31+
- **Responsive design** - Mobile-optimized interface
32+
- **Dark/light themes** - Automatic theme detection
33+
- **Accessibility** - Keyboard navigation and screen reader support
34+
- **Emoji picker** - Rich text input with emoji support
35+
36+
### 🛡️ **Enterprise Features**
37+
- **Error handling** - Comprehensive error banners and recovery
38+
- **GDPR compliance** - Consent management and data protection
39+
- **Sentry integration** - Error tracking and monitoring
40+
- **Rate limiting** - API abuse prevention
41+
- **Audit logging** - Security event tracking
42+
43+
## Architecture
44+
45+
### Widget Structure
46+
```
47+
widget/
48+
├── src/
49+
│ ├── index.ts # Auto-initialization from script tag
50+
│ ├── widget.ts # Main SynteraWidget class
51+
│ ├── types.ts # TypeScript interfaces
52+
│ ├── styles.css # Widget styling
53+
│ ├── api/
54+
│ │ ├── client.ts # HTTP API client (REST endpoints)
55+
│ │ ├── websocket.ts # WebSocket client (real-time events)
56+
│ │ └── livekit.ts # LiveKit client (voice calls)
57+
│ ├── ui/
58+
│ │ ├── chat-interface.ts # Complete chat UI component
59+
│ │ └── gdpr-consent.ts # GDPR consent modal
60+
│ └── utils/
61+
│ ├── logger.ts # Structured logging
62+
│ ├── sentry.ts # Error tracking
63+
│ └── icons.ts # SVG icon components
64+
├── dist/
65+
│ ├── widget.iife.js # UMD bundle for browsers
66+
│ ├── widget.css # Compiled styles
67+
│ └── *.d.ts # TypeScript declarations
68+
└── test.html # Development testing page
69+
```
70+
71+
### Component Architecture
72+
73+
#### **SynteraWidget Class**
74+
Main orchestrator handling initialization, configuration, and lifecycle management:
75+
76+
```typescript
77+
class SynteraWidget {
78+
async init(): Promise<void> {
79+
// Load agent configuration
80+
// Initialize API clients
81+
// Create UI components
82+
// Setup error handling
83+
}
84+
85+
async startChat(): Promise<void> {
86+
// Create conversation
87+
// Initialize WebSocket connection
88+
// Render chat interface
89+
}
90+
91+
async startVoiceCall(): Promise<void> {
92+
// Get LiveKit token
93+
// Initialize voice connection
94+
// Handle audio streaming
95+
}
96+
}
97+
```
98+
99+
#### **ChatInterface Component**
100+
Complete chat UI with message handling, typing indicators, and voice controls:
101+
102+
```typescript
103+
class ChatInterface {
104+
private createMessageBubble(message: Message): HTMLElement {
105+
// Render message with timestamp
106+
// Add reaction capabilities
107+
// Handle file attachments
108+
}
109+
110+
private handleVoiceCall(): void {
111+
// Initialize LiveKit connection
112+
// Setup audio streaming
113+
// Update UI state
114+
}
115+
}
116+
```
117+
118+
## API Integration
119+
120+
### Required Endpoints
121+
The widget communicates with Syntera's backend services:
122+
123+
| Endpoint | Method | Purpose |
124+
|----------|--------|---------|
125+
| `/api/public/agents/:id` | GET | Fetch agent configuration |
126+
| `/api/public/conversations` | POST | Create new conversation |
127+
| `/api/public/messages` | POST | Send chat messages |
128+
| `/api/public/livekit/token` | POST | Get voice call tokens |
129+
| `/api/public/websocket/config` | POST | Get WebSocket configuration |
130+
131+
### Real-time Events (WebSocket)
132+
```
133+
Client → Server:
134+
├── message:send # Send chat message
135+
├── typing:start # Show typing indicator
136+
├── call:start # Initiate voice call
137+
└── conversation:join # Join conversation room
138+
139+
Server → Client:
140+
├── message:new # New message received
141+
├── typing:update # Typing status changes
142+
├── call:status # Voice call status updates
143+
└── error # Error notifications
144+
```
145+
146+
## Configuration & Initialization
147+
148+
### Script Tag Integration
149+
```html
150+
<script src="https://cdn.syntera.com/widget.iife.js"
151+
data-agent-id="agent-123"
152+
data-api-key="pub_key_abc"
153+
data-api-url="https://api.syntera.com"
154+
data-position="bottom-right"
155+
data-theme="auto"
156+
data-debug="false">
157+
</script>
158+
```
159+
160+
### Configuration Options
161+
162+
| Attribute | Required | Default | Description |
163+
|-----------|----------|---------|-------------|
164+
| `data-agent-id` | ✅ Yes | - | Syntera agent identifier |
165+
| `data-api-key` | ✅ Yes | - | Public API key for authentication |
166+
| `data-api-url` | ❌ No | `https://api.syntera.com` | Backend API base URL |
167+
| `data-position` | ❌ No | `bottom-right` | Widget position: `bottom-right`, `bottom-left`, `top-right`, `top-left` |
168+
| `data-theme` | ❌ No | `auto` | Theme: `light`, `dark`, `auto` |
169+
| `data-debug` | ❌ No | `false` | Enable debug logging |
170+
171+
### Programmatic Usage
172+
```typescript
173+
import { SynteraWidget } from '@syntera/widget'
174+
175+
const widget = new SynteraWidget({
176+
agentId: 'agent-123',
177+
apiKey: 'pub_key_abc',
178+
apiUrl: 'https://api.syntera.com',
179+
position: 'bottom-right',
180+
theme: 'auto',
181+
sentryDsn: 'https://sentry-dsn', // Optional
182+
})
183+
184+
// Initialize widget
185+
await widget.init()
186+
187+
// Programmatic control
188+
widget.open() // Show chat
189+
widget.close() // Hide chat
190+
await widget.sendMessage('Hello!')
191+
```
192+
193+
## Development & Building
194+
195+
### Local Development
196+
```bash
197+
cd widget
198+
199+
# Install dependencies
200+
pnpm install
201+
202+
# Development server with hot reload
203+
pnpm dev
204+
205+
# Build for production
206+
pnpm build
207+
208+
# Type checking
209+
pnpm type-check
210+
```
211+
212+
### Build Output
213+
```bash
214+
dist/
215+
├── widget.iife.js # UMD bundle (~200KB)
216+
├── widget.css # Styles (~15KB)
217+
├── widget.d.ts # TypeScript declarations
218+
└── *.d.ts.map # Source maps
219+
```
220+
221+
### Testing
222+
```bash
223+
# Open test page in browser
224+
open test.html
225+
226+
# Or serve locally
227+
python -m http.server 8000
228+
# Visit http://localhost:8000/test.html
229+
```
230+
231+
## Error Handling & Monitoring
232+
233+
### Error Recovery
234+
- **Connection failures** - Automatic reconnection with exponential backoff
235+
- **API errors** - User-friendly error messages with retry options
236+
- **Audio issues** - Fallback to text-only mode
237+
- **Network interruptions** - State preservation and recovery
238+
239+
### Monitoring Integration
240+
```typescript
241+
// Sentry error tracking
242+
if (config.sentryDsn) {
243+
initSentry({
244+
dsn: config.sentryDsn,
245+
environment: 'production',
246+
agentId: config.agentId,
247+
})
248+
}
249+
250+
// Structured logging
251+
logger.info('Widget initialized', {
252+
agentId: config.agentId,
253+
theme: config.theme,
254+
userAgent: navigator.userAgent
255+
})
256+
```
257+
258+
## Browser Compatibility
259+
260+
### Supported Browsers
261+
- **Chrome/Edge**: 88+ (WebRTC support)
262+
- **Firefox**: 87+ (WebRTC support)
263+
- **Safari**: 14+ (WebRTC support)
264+
- **Mobile Safari**: iOS 14.5+
265+
- **Chrome Android**: 88+
266+
267+
### Feature Detection
268+
The widget automatically detects and adapts to browser capabilities:
269+
- **WebRTC support** - Falls back to text-only if unavailable
270+
- **WebSocket support** - Graceful degradation for older browsers
271+
- **CSS Grid/Flexbox** - Progressive enhancement for layouts
272+
273+
## Performance Optimization
274+
275+
### Bundle Optimization
276+
- **Tree shaking** - Unused code elimination
277+
- **Code splitting** - Lazy loading of non-critical features
278+
- **Compression** - Gzip/Brotli compression
279+
- **Caching** - Aggressive caching headers
280+
281+
### Runtime Performance
282+
- **Virtual scrolling** - Efficient message list rendering
283+
- **Debounced inputs** - Reduced API calls during typing
284+
- **Memory management** - Automatic cleanup of event listeners
285+
- **Image optimization** - Lazy loading and responsive images
286+
287+
## Security Considerations
288+
289+
### Data Protection
290+
- **HTTPS only** - Secure connections for all communications
291+
- **API key rotation** - Regular credential updates
292+
- **Input sanitization** - XSS prevention and validation
293+
- **Session isolation** - No cross-conversation data leakage
294+
295+
### Privacy Compliance
296+
- **GDPR consent** - User permission for data collection
297+
- **Data minimization** - Only necessary data collection
298+
- **Right to erasure** - User data deletion capabilities
299+
- **Audit trails** - Complete activity logging
300+
301+
## Deployment & Hosting
302+
303+
### CDN Deployment
304+
```bash
305+
# Build production bundle
306+
pnpm build
307+
308+
# Upload to CDN
309+
aws s3 cp dist/ s3://cdn.syntera.com/widget/ --recursive
310+
311+
# CDN URL: https://cdn.syntera.com/widget/widget.iife.js
312+
```
313+
314+
### Version Management
315+
- **Semantic versioning** - Major.minor.patch releases
316+
- **Changelog maintenance** - Feature and bug fix documentation
317+
- **Backwards compatibility** - API stability guarantees
318+
- **Deprecation notices** - Advance warning for breaking changes
319+
320+
---
321+
322+
**Enterprise-grade embeddable AI chat widget with voice capabilities and comprehensive error handling.**
323+

0 commit comments

Comments
 (0)