Sign in to view this page.
| File | Responsibility |
|---|---|
backend/server.py | Flask app, Evolution webhook route, group message two-step logic, Evolution management endpoints, dashboard API, auth middleware |
backend/whatsapp.py | Thin wrapper delegating to Evolution API provider |
backend/providers/evolution.py | Evolution API: webhook parsing (group vs DM via @g.us/@s.whatsapp.net JIDs), message sending, instance management (create, status, QR code) |
backend/llm.py | BrightWrapper integration: generate_reply() for responses, evaluate_relevance() for group scoring |
backend/models.py | SQLite database: conversations (with is_group/group_id), messages, settings, llm_decisions tables |
frontend/dashboard.html | Admin SPA: conversations, Evolution connection/QR code, decision chain viewer, settings (provider, bot name, threshold, system prompt) |
An Evolution API "instance" is a single WhatsApp Web session — one phone number linked via QR code scan. Evolution API (built on the Baileys library) connects to WhatsApp's servers using the same WebSocket protocol as the WhatsApp Web browser app. Our instance is named whatsapp-agent.
The instance maintains a persistent connection to WhatsApp and stores session authentication keys in PostgreSQL. When a message arrives, Evolution API forwards it as a webhook POST to our Flask app. When we want to send a reply, we call Evolution API's REST endpoint, and it sends the message through the existing WebSocket connection.
This is an unofficial integration using the WhatsApp Web protocol via Baileys, which supports both group chats and 1:1 messaging.
whatsapp.py wraps the Evolution API provider with a stable interface: parse_incoming_message(), send_message(), is_configured().systemd whatsapp-agent.service, runs as app_whatsapp_agent on port 9208systemd evolution-api.service, runs as app_evolution_api on port 9209, internal only (no nginx exposure)systemd postgresql.service, database evolution_db for Evolution API session/message storage/opt/secrets/evolution-api.json (Evolution API key + DB creds), /opt/secrets/brightwrapper.json (BrightWrapper API key)/home/app_whatsapp_agent/data/whatsapp_agent.db (app data), PostgreSQL evolution_db (Evolution sessions)