Chatbot Modules Specification
1. Purpose & Overview
The and modules provide dual AI capabilities: the Platform AI Assistant (dashboard helper) and the WhatsApp AI Auto-Responder (automated customer response engine with vision support).
chatbotwa_chatbot2. Responsibilities
- Manage tenant knowledge base context files ().
content.json - Prompt OpenRouter LLM text models () and vision models (
stepfun/step-3.5-flash).openai/gpt-4o - Automatically process inbound WhatsApp text and image attachments.
3. Directory Structure
text
services/api/
├── chatbot/ # Platform AI Assistant
│ ├── views.py
│ └── tests.py
└── wa_chatbot/ # WhatsApp Auto-Responder & Vision
├── services.py
├── views.py
└── tests.py
4. Models & Database Schemas
- Uses for prompt overrides and
tenants.TenantConfigfor history memory.messaging.Message
5. Services & Business Logic
- : Analyzes message, fetches context, prompts OpenRouter, and dispatches outbound WhatsApp reply.
WAChatbotService.process_inbound_message(tenant, conversation, message) - : Prompts vision model for image content understanding.
WAChatbotService.analyze_image(image_url)
6. Serializers & Data Transfer Objects
- : Validates question input for platform assistant endpoint.
ChatbotQuerySerializer
7. Views & API Endpoints
- : Test AI response generation.
POST /api/chatbot/test/ - : Check AI engine health.
GET /api/chatbot/check/
8. Permissions & Role Rules
- for chatbot health checks;
AllowAnyfor assistant queries.IsAuthenticated
9. Signals & Event Listeners
- Inbound WhatsApp message signals trigger asynchronously.
process_inbound_message
10. Background Tasks & Celery Jobs
- AI generation tasks executed in Celery background workers to keep webhooks responsive.
11. Data Flow & External Dependencies
- Connects to OpenRouter REST API using .
OPENROUTER_API_KEY
12. Business Rules & Validations
- If no knowledge context is found or API times out, returns .
WA_CHATBOT_FALLBACK_MESSAGE
13. Sequence Diagram (Mermaid)
Rendering diagram...
14. Known Limitations & Technical Debt
- Local file storage for knowledge base context in early version.
content.json
15. Future Improvements
- Vector database Integration (pgvector / ChromaDB) for scalable Retrieval-Augmented Generation (RAG).