The n8n WhatsApp AI Agent stack is composed of eight services, each with a narrow, well-defined responsibility. No single service handles more than one concern — WhatsApp Cloud API manages the connection to Meta’s messaging network, Chatwoot surfaces conversations to human agents, n8n orchestrates all automation logic, PostgreSQL provides durable persistence, Redis holds ephemeral state, Caddy terminates TLS and routes traffic, OpenAI processes language and audio, and Google Drive supplies the canonical client dataset. Understanding what each component owns — and what it explicitly does not own — makes the system easier to operate, debug, and extend.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/DevMauricio03/n8n-whatsapp-ai-agent/llms.txt
Use this file to discover all available pages before exploring further.
Component overview
| Component | Function | Data handled | Dependencies |
|---|---|---|---|
| WhatsApp Cloud API | Receives and sends messages | Phone number, text, audio, delivery status | Meta, internet |
| Chatwoot | Centralizes conversations | Contacts, conversations, agents | PostgreSQL, Redis |
| n8n | Executes automations | Payloads, context, results | All services |
| OpenAI | Transcribes and generates responses | Text, audio, and sent context | External API |
| PostgreSQL | Persistence | Clients, folios, memory | Docker volume |
| Redis | Temporary state | Buffers and human-handoff locks | Docker volume |
| Google Drive | Sync source | Corporate XLSX file | Google OAuth |
| Caddy | Reverse proxy | HTTPS traffic | DNS, ports 80/443 |
Component deep-dives
WhatsApp Cloud API
WhatsApp Cloud API
WhatsApp Cloud API is the Meta-hosted gateway that connects the platform’s phone number to the rest of the stack. It is not a container you deploy — it is a managed service whose credentials and configuration live in the Meta Developer Console.Operational responsibilities:
- Keep the business phone number active and in good standing with Meta’s policy requirements.
- Deliver inbound message events to Chatwoot via the registered webhook.
- Enable sending of text messages, audio files, and images through the Graph API.
- Rotate access tokens before expiry and audit webhook permissions after any Meta platform update.
WHATSAPP_GRAPH_API_VERSION and WHATSAPP_PHONE_NUMBER_ID environment variables defined in .env govern which Graph API version and number the workflow targets. Upgrading the API version should be done intentionally and tested against a non-production number first.Chatwoot
Chatwoot
Chatwoot is the agent-facing inbox that sits between WhatsApp Cloud API and n8n. Every inbound message from WhatsApp arrives in Chatwoot first; from there, Chatwoot emits webhook events that drive n8n’s automation logic.Operational responsibilities:
- Present a unified conversation inbox to human support agents.
- Emit webhook payloads to n8n for every message event — both incoming messages from customers and outgoing messages sent by agents.
- Differentiate between
incomingandoutgoingmessage directions so that n8n can correctly detect human agent intervention. - Retain the full visible conversation history so operators can review context without querying the database directly.
chatwoot PostgreSQL database and uses Redis for ephemeral session and queue data managed by Sidekiq. The CHATWOOT_DOMAIN environment variable controls the public hostname that Caddy routes to Chatwoot.n8n
n8n
n8n is the automation engine at the center of the stack. It receives webhook events from Chatwoot and executes a multi-branch workflow that routes messages, applies business rules, queries PostgreSQL, calls OpenAI, and delivers replies via WhatsApp Cloud API.Operational responsibilities:
- Validate the structure of every incoming Chatwoot payload before processing.
- Prevent outgoing messages from re-triggering the AI — the
msg_from_clientnode allows onlyincomingmessages to proceed into the AI pipeline. - Apply Human Handoff by checking and setting Redis keys before handing off to the AI agent.
- Buffer and group messages using Redis lists so that rapid successive messages from a customer are processed together.
- Execute the business-hours schedule, AI agent inference, PostgreSQL client lookups, and WhatsApp reply delivery.
- Log all executions and errors to the
n8ndatabase for operational visibility.
N8N_DOMAIN environment variable and N8N_ENCRYPTION_KEY are required for the service to start correctly. Credentials for all external services are stored encrypted in the n8n database.PostgreSQL
PostgreSQL
PostgreSQL provides all durable persistence for the platform. A single PostgreSQL instance hosts three logically separate databases, each owned by a different layer of the stack.The three databases:
n8n— stores n8n’s internal configuration, encrypted credentials, workflow definitions, and execution history. n8n manages this database entirely; do not modify it manually.chatwoot— stores Chatwoot’s contacts, conversations, agent accounts, and inbox configuration. Chatwoot manages this database via its own migrations.agent— stores the business-specificbd_clientestable and the conversational memory table created by n8n’s Postgres Chat Memory node. This is the only database that operators query directly in normal operation.
POSTGRES_USER and POSTGRES_PASSWORD values in .env apply to all three databases. The docker/initdb/ scripts create all three databases and the bd_clientes schema the first time the PostgreSQL volume is provisioned.Redis
Redis
Redis provides fast, ephemeral state storage for two critical functions: Human Handoff locks and message buffering. It also holds temporary session data used internally by Chatwoot’s Sidekiq workers.Operational responsibilities:
- Store Human Handoff keys with a TTL of 1800 seconds (30 minutes) so that the AI is silenced while a human agent is active in a conversation.
- Maintain per-conversation buffer lists that hold incoming messages until the grouping window closes and n8n processes them as a batch.
- Support Chatwoot’s Sidekiq background job queue, which relies on Redis for job persistence and scheduling.
REDIS_PASSWORD environment variable. If Redis becomes unavailable, the safe behavior is to fail closed — the workflow should not auto-respond rather than risk interfering with a human agent conversation.Caddy
Caddy
Caddy is the reverse proxy that terminates HTTPS and routes public traffic to the correct internal service. It is the only container that exposes ports 80 and 443 to the internet.Operational responsibilities:
- Automatically request and renew TLS certificates from Let’s Encrypt using the
LETSENCRYPT_EMAILaddress. - Route requests to
N8N_DOMAIN(e.g.n8n.example.com) to the n8n container. - Route requests to
CHATWOOT_DOMAIN(e.g.chat.example.com) to the Chatwoot container.
OpenAI
OpenAI
OpenAI provides two AI capabilities used by the workflow: audio transcription via the Whisper model and conversational response generation via the chat completions API.Operational responsibilities:
- Transcribe audio messages downloaded from WhatsApp Cloud API into text before the message enters the main processing pipeline.
- Generate AI agent responses based on the 10-message context window, the system prompt, and any client data retrieved from
bd_clientes. - Return special image keys that the workflow interprets to select and send the correct price or package image from the URLs defined in
.env.
Google Drive
Google Drive
Google Drive hosts the authoritative XLSX spreadsheet that populates the
bd_clientes table. Rather than requiring operators to interact with PostgreSQL directly, the business team maintains the client list in a familiar spreadsheet format that n8n syncs on a schedule.Operational responsibilities:- Store the XLSX file identified by the
GOOGLE_DRIVE_SOURCE_FILE_IDenvironment variable. - Provide access via a Google Drive OAuth2 credential configured in n8n.
- Serve as the single source of truth for client folio, contact, and payment status data.
ON CONFLICT (folio) DO UPDATE upsert into bd_clientes. The expected column headers are fixed — any structural change to the spreadsheet requires a matching update to the workflow’s field mapping.Health matrix
Use the following checks to confirm that every service is operating correctly. Run these verifications after initial deployment and after any infrastructure change.| Service | Verification |
|---|---|
| Caddy | Both domains respond over HTTPS without certificate errors |
| n8n | Web interface is accessible and the workflow can be executed manually |
| Chatwoot | Dashboard is accessible and Sidekiq is processing the job queue |
| PostgreSQL | pg_isready returns success and direct queries return correct results |
| Redis | PING returns PONG when authenticated with REDIS_PASSWORD |
| OpenAI | Controlled test with a text message and an audio message both produce valid responses |
| A real message sent to the business number is received and replied to end-to-end |