Chat Interface Integration
ChatKit + ShadCN Integration provides a modern, voice-enabled chat interface that seamlessly connects with AltSportsLeagues.ai's n8n automation workflows. This integration combines OpenAI's ChatKit styling patterns with ShadCN UI components for professional AI conversations.
π― Integration Overview
The chat interface serves as the primary user interaction layer for AltSportsLeagues.ai's AI automation system, enabling natural language conversations that trigger complex business workflows through n8n.
ποΈ Architecture Flow
Message Journey: User β AI β Response
Data Flow Architecture
π Technical Implementation
ChatInterface Component Structure
Communication Protocol
π Integration Patterns
Webhook Communication Flow
βββββββββββββββββββ HTTP POST βββββββββββββββββββ
β Chat Interface β βββββββββββββββΊ β n8n Webhook β
β β β β
β React Component β β Workflow Triggerβ
β useChatWithN8n β ββββββββββββββββ β β
βββββββββββββββββββ JSON Response βββββββββββββββββββ
β β
β βΌ
β βββββββββββββββββββ
β β Ultimate Assistantβ
β β Orchestrator β
β βββββββββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββ WebSocket βββββββββββββββββββ
β UI Updates β ββββββββββββββββ β Real-time Stream β
β β β β
β Message Bubbles β β Streaming Text β
β Typing States β β Progress Updatesβ
βββββββββββββββββββ βββββββββββββββββββVoice Integration Flow
βββββββββββββββββββ Voice Start βββββββββββββββββββ
β Voice Button β βββββββββββββββΊ β Web Speech API β
β (Pressed) β β β
βββββββββββββββββββ βββββββββββββββββββ
β β
β βΌ
βΌ βββββββββββββββββββ
βββββββββββββββββββ β Audio Stream β
β Recording UI β ββββββββββββββββ β β
β Visual Feedbackβ β Real-time Audio β
βββββββββββββββββββ βββββββββββββββββββ
β β
β βΌ
βΌ βββββββββββββββββββ
βββββββββββββββββββ β Voice β Text β
β Stop Recording β βββββββββββββββΊ β β
β (Released) β β Speech Recognitionβ
βββββββββββββββββββ βββββββββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββ Voice Message βββββββββββββββββββ
β Voice Bubble β βββββββββββββββΊ β n8n Processing β
β Audio Playback β β β
βββββββββββββββββββ βββββββββββββββββββπ¨ UI Component Architecture
ChatKit Styling Integration
Component Composition Tree
ChatInterface
βββ ChatHeader
β βββ Avatar (Assistant)
β βββ UserInfo
β β βββ Name
β β βββ Status (Online/Typing)
β βββ ActionButtons
β βββ PhoneButton
β βββ VideoButton
β βββ MoreButton
βββ MessageContainer (ScrollArea)
β βββ MessageList
β βββ MessageBubble (repeated)
β β βββ Avatar (User/Assistant)
β β βββ MessageContent
β β β βββ TextContent
β β β βββ VoiceContent
β β β βββ StreamingIndicator
β β βββ MessageMeta
β β β βββ Username
β β β βββ Timestamp
β β βββ MessageStatus
β βββ TypingIndicator
βββ InputArea
βββ AttachmentButton
βββ MessageInput
β βββ TextInput
β βββ EmojiButton
βββ VoiceButton
βββ SendButtonπ§ Configuration & Setup
Environment Variables
# Required for n8n integration
NEXT_PUBLIC_N8N_WEBHOOK_URL=https://n8n.altsportsleagues.ai/webhook/chat
# Optional: WebSocket for real-time updates
NEXT_PUBLIC_WS_URL=wss://n8n.altsportsleagues.ai/websocket
# Optional: Voice processing
NEXT_PUBLIC_VOICE_ENABLED=true
NEXT_PUBLIC_VOICE_API_KEY=your-voice-api-keyn8n Workflow Configuration
{
"name": "Chat Interface Webhook",
"nodes": [
{
"parameters": {
"httpMethod": "POST",
"path": "chat",
"responseMode": "responseNode",
"options": {}
},
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 1.0,
"webhookId": "chat-webhook-id"
},
{
"parameters": {
"workflowId": "ultimate-assistant-workflow-id"
},
"name": "Execute Workflow",
"type": "n8n-nodes-base.executeWorkflow",
"typeVersion": 1.0
}
],
"connections": {
"Webhook": {
"main": [
[
{
"node": "Execute Workflow",
"type": "main",
"index": 0
}
]
]
}
}
}π§ͺ Testing & Validation
Integration Test Flow
Test Scenarios
π Test Scenarios Matrix
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Scenario | Input Type | Expected Behavior | Validation Method
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Basic Text | Text | Assistant responds with text | Response content check
Voice Message | Audio | Voice transcribed and processed | Transcription accuracy
File Upload | File | File processed by workflow | Processing completion
Streaming | Text | Response streams in real-time | UI animation timing
Error Handling | Invalid | Graceful error display | Error message format
Rate Limiting | Rapid | Proper throttling applied | Request timing
Offline Mode | Any | Offline indicator shown | Network status check
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββπ Performance & Monitoring
Key Metrics to Monitor
Real-time Monitoring Dashboard
ββ Chat Interface Performance Dashboard βββββββββββββββββββββββββββ
β β
β Response Times: ββββββββββ 85% < 1.5s Voice Accuracy: 96% β
β Message Volume: βββββββββ 720/min Error Rate: 0.3% β
β Active Sessions: 42 Memory Usage: 145MB β
β β
β Recent Alerts: β
β β’ Voice processing latency spike (2.1s β 1.8s) β
β β’ High message volume detected (850/min) β
β β
β Top Workflows: β
β 1. Partnership Inquiry Processing 245 executions β
β 2. League Onboarding Assistant 189 executions β
β 3. Contract Generation Pipeline 156 executions β
β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββπ Deployment & Scaling
Production Architecture
Scaling Strategies
π Auto-scaling Triggers
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Metric | Threshold | Action
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Response Time | > 2.0s | Scale n8n instances +20%
Message Queue Depth | > 1000 | Scale webhook workers +50%
Memory Usage | > 80% | Scale frontend pods +25%
Error Rate | > 5% | Enable circuit breaker
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Global Distribution
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Region | Purpose | Capacity | Latency Target
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
us-east-1 | Primary | 100% baseline | < 50ms
eu-west-1 | EU Users | 60% baseline | < 80ms
ap-southeast-1| Asia Users | 40% baseline | < 120ms
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββπ Security & Compliance
Data Protection Flow
Security Controls
π Security Control Matrix
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Layer | Control Type | Implementation | Validation
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Frontend | Input Sanitization| DOMPurify | XSS Prevention
| Rate Limiting | Client-side | Abuse Prevention
| Content Security| CSP Headers | Injection Prevention
ββββββββββββββββΌβββββββββββββββββββΌββββββββββββββββββΌβββββββββββββββββ
Transport | TLS Encryption | TLS 1.3 | Certificate Validation
| Request Signing | HMAC-SHA256 | Integrity Check
| API Keys | JWT Tokens | Authentication
ββββββββββββββββΌβββββββββββββββββββΌββββββββββββββββββΌβββββββββββββββββ
Application | Access Control | RBAC | Permission Check
| Data Validation | Zod Schemas | Type Safety
| Audit Logging | Structured Logs | Compliance
ββββββββββββββββΌβββββββββββββββββββΌββββββββββββββββββΌβββββββββββββββββ
Data | Encryption | AES-256-GCM | Data Protection
| Masking | PII Detection | Privacy
| Retention | Auto-deletion | Compliance
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββπ οΈ Troubleshooting
Common Issues & Solutions
β Issue: Messages not reaching n8n
β
Solution:
1. Check NEXT_PUBLIC_N8N_WEBHOOK_URL environment variable
2. Verify webhook endpoint is active in n8n
3. Check network connectivity and CORS settings
4. Review n8n workflow execution logs
β Issue: Voice messages not processing
β
Solution:
1. Verify Web Speech API browser support
2. Check microphone permissions
3. Validate voice processing workflow in n8n
4. Test with smaller audio files first
β Issue: Streaming responses laggy
β
Solution:
1. Check WebSocket connection stability
2. Optimize message chunking in n8n workflow
3. Reduce streaming frequency if needed
4. Monitor network latency between services
β Issue: UI not updating on message send
β
Solution:
1. Verify React state updates in useChatWithN8n hook
2. Check for JavaScript errors in browser console
3. Validate message object structure
4. Test with simple text messages firstDebug Tools
π§ Debug Command Reference
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Command | Purpose | Output
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
npm run test:chat | Run chat component tests | Test results & coverage
node scripts/test-chat-integration.js | Test n8n integration | Connection status & logs
curl -X POST webhook-url | Manual webhook test | Raw response data
n8n workflow:execute | Test workflow locally | Execution results
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Debug Data Flow
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
1. Frontend β Browser Console β Message sent
2. Network Tab β Webhook request β Status 200
3. n8n β Workflow logs β Processing started
4. Database β Query logs β Data retrieved
5. AI Service β API logs β Response generated
6. WebSocket β Real-time updates β UI updated
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββπ Future Enhancements
Planned Features
Performance Optimizations
β‘ Performance Optimization Pipeline
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Optimization | Current | Target | Impact
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Message Chunking | 1KB chunks | 512B chunks | 40% faster streaming
Lazy Loading | None | Component | 60% initial load
Caching Strategy | Basic | Intelligent | 80% repeat queries
Bundle Splitting | Single | Multi-chunk | 50% code size
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββπ― Quick Start
1. Install Dependencies
npm install @radix-ui/react-scroll-area lucide-react2. Set Environment
export NEXT_PUBLIC_N8N_WEBHOOK_URL=https://n8n.altsportsleagues.ai/webhook/chat3. Use the Component
import { ChatInterface, useChatWithN8n } from '@/components/chat/ChatInterface';
export default function ChatPage() {
const n8nWebhookUrl = process.env.NEXT_PUBLIC_N8N_WEBHOOK_URL;
const chatProps = useChatWithN8n(n8nWebhookUrl);
return (
<div className="h-screen">
<ChatInterface {...chatProps} />
</div>
);
}4. Test Integration
node scripts/test-chat-integration.js $NEXT_PUBLIC_N8N_WEBHOOK_URLThis chat interface provides the conversational gateway to AltSportsLeagues.ai's powerful n8n automation system, enabling natural language interactions with complex business workflows.