How devthayron/whatsapp-ai-agent works
This is a FastAPI WhatsApp AI agent: incoming messages are normalized, associated with a user, combined with persisted or initially imported conversation history, sent to OpenAI, saved, and returned through Evolution API. The direct chat endpoint shares the agent workflow. The README documents history synchronization, duplicate-message handling, and persistent SQLite storage; unsampled model and schema details are represented only at their documented paths.
Main entry points: agent.py Conversation agent · conversations.py History and messages · evolution.py Evolution integration · webhook.py Webhook route
Components 15
API ingress
- FastAPI application
app/main.py - Webhook route
app/routes/webhook.py - Chat route
app/routes/chat.py
Conversation processing
- Message normalization
bot/message_processor.py - Conversation agent
services/agent.py
External integrations
- Evolution integration
services/evolution.py - OpenAI integration
services/openai.py
Persistence
- User identification
database/users.py - History and messages
database/conversations.py - Conversation database
database/models.py - Database connection
database/connection.py
Other components
- WhatsApp user
- Evolution API
- OpenAI
- Chat API client
Connections 22
- WhatsApp user → Evolution API: sends messages
- Evolution API → Webhook route: delivers webhook
- Webhook route → Message normalization: extracts and normalizes
- Webhook route → Conversation agent: processes message
- Conversation agent → User identification: identifies user
- Conversation agent → History and messages: ensures history
- Conversation agent → History and messages: saves message
- Conversation agent → History and messages: loads context
- History and messages → Evolution integration: imports initial history
- History and messages → User identification: finds or creates user
- User identification → Conversation database: reads and writes users
- History and messages → Conversation database: reads and writes messages
- FastAPI application → Database connection: creates tables
- Database connection → Conversation database: configures persistence
- Conversation agent → OpenAI integration: generates response
- OpenAI integration → OpenAI: requests completion
- Webhook route → Evolution integration: sends reply
- Chat API client → Chat route: submits message
- Chat route → Conversation agent: processes message
- Chat route → Evolution integration: sends reply
- Evolution integration → Evolution API: fetches history
- Evolution integration → Evolution API: sends WhatsApp message