Integrations
Chat Interface Integration

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-key

n8n 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 first

Debug 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-react

2. Set Environment

export NEXT_PUBLIC_N8N_WEBHOOK_URL=https://n8n.altsportsleagues.ai/webhook/chat

3. 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_URL

This chat interface provides the conversational gateway to AltSportsLeagues.ai's powerful n8n automation system, enabling natural language interactions with complex business workflows.

Platform

Documentation

Community

Support

partnership@altsportsdata.comdev@altsportsleagues.ai

2025 Β© AltSportsLeagues.ai. Powered by AI-driven sports business intelligence.

πŸ€– AI-Enhancedβ€’πŸ“Š Data-Drivenβ€’βš‘ Real-Time