n8n OpenAI Chatwoot Meta API PostgreSQL

WhatsApp AI Support Agent

Customer service on autopilot, from first message to human handoff, fully automated via WhatsApp.

See it in action

The Problem

The existing customer support system relied on a button-based chatbot and a live chat platform embedded in the company's website and app. It worked, but it couldn't scale.

๐Ÿ”’ No Tool Access

The AI agent had no access to external tools or internal systems, severely limiting what it could actually resolve for users.

๐Ÿ“‚ Manual Knowledge Base

Knowledge base required manual file uploads to stay current, a slow and error-prone process that left the bot frequently outdated.

๐Ÿ”˜ Button-Driven Flows

Conversation flow driven by pre-set buttons, not user intent. Customers couldn't ask questions naturally, only pick from a menu.

๐Ÿ“ต No WhatsApp Support

Customers had to access the company's own platform to get support. There was no WhatsApp channel, no way to meet users where they already are.

The Solution

Built a custom automation architecture from scratch, replacing third-party chatbot platforms with a fully orchestrated system where n8n is the brain, WhatsApp is the front door, and every component talks to each other.

Core Design Decisions

  • WhatsApp as the primary channel: where users already are, zero friction to start a conversation
  • Chatwoot as the human agent interface: seamless fallback channel for complex cases
  • n8n as the sole orchestrator: no vendor lock-in, full control over every workflow step
  • PostgreSQL as the session and state store: persistent, queryable, and fast
  • OpenAI for natural language understanding: real intent detection, not button menus
  • Whisper for audio support: customers can send voice messages and get intelligent responses

Architecture: 5 Workflows

Every workflow includes an Error Trigger โ†’ formatted error message โ†’ WhatsApp alert to admin.

โšก WF01 ยท Main Agent Flow

Receives WhatsApp messages (text or audio), processes them through the AI agent, queries the real-time data API for showtimes and sessions, generates responses, and sends them back via Meta API. Manages session state in PostgreSQL on every interaction.

๐Ÿ”„ WF02 ยท Cache Programming

Handles scheduled cache refresh for 20,000+ session records using a Blue-Green swap strategy: one table is always live while the other is being rebuilt. Zero-downtime updates to the session store.

โฑ๏ธ WF03 ยท Session Expiration

Runs every minute via Schedule Trigger. Queries PostgreSQL for sessions inactive for more than 10 minutes, marks them as closed in session history and chat histories, resolves the conversation in Chatwoot, and removes any pending agent labels.

๐Ÿค WF04 ยท Human Handoff

Triggered when the AI detects it cannot resolve the request. Transfers the conversation to a human agent in Chatwoot, assigns via round-robin, applies queue labels, and notifies the agent immediately.

๐Ÿ“‹ WF05 ยท Queue Processing

Manages the agent queue, assigns waiting conversations, tracks agent availability, and re-routes if the assigned agent is offline.

๐Ÿšจ Error Monitoring (All Workflows)

Every single workflow has an Error Trigger node. On failure, it formats a detailed error message and sends an immediate WhatsApp notification to the admin. No silent failures.

What the Agent Delivers

๐ŸŽ™๏ธ Text & Audio Support

Responds to both text and voice messages via WhatsApp, with Whisper transcription handling audio inputs seamlessly.

๐ŸŽฌ Real-Time Data

Answers questions about policies, schedules, and availability by querying a live internal API on every session request, always up to date.

๐Ÿ”— Purchase Links

Sends direct purchase links for specific sessions or products, reducing friction and guiding users straight to conversion.

๐Ÿง  Smart Handoff

Detects when human support is needed and routes automatically to an available agent in Chatwoot via round-robin assignment.

๐Ÿ“Š Queue Management

Manages conversation queues and agent assignment end-to-end, including re-routing when agents go offline.

๐Ÿงน Auto Session Cleanup

Closes idle sessions automatically after 10 minutes, resolves Chatwoot tickets, and keeps the system clean without manual intervention.

Technical Highlights

5
Automated Workflows
20K+
Session Records Managed
10 min
Auto Session Expiry
100%
n8n Orchestrated

Under the Hood

  • Session management: PostgreSQL, 20K+ records, auto-expire at 10 min inactivity
  • Cache strategy: Blue-Green swap, zero downtime on cache refresh
  • Audio support: Whisper transcription integrated in WF01
  • Human handoff: Chatwoot API + round-robin assignment
  • Error monitoring: Every workflow has error capture โ†’ WhatsApp alert to admin
  • Real-time data: Cinema API queried on every session request
  • Orchestration: 100% n8n, no custom backend needed
  • Knowledge base: Agent queries a structured knowledge base maintained directly inside the company's ERP, always reflecting the latest content without manual sync
  • ERP integration: Session and chat histories are imported into the ERP after each conversation, giving the support team full visibility and management of all interactions in one place

Technical Stack

Orchestration

n8n: self-hosted workflow automation, sole orchestrator for all 5 workflows

AI / LLM

OpenAI GPT for natural language responses + Whisper for voice message transcription

Messaging

Meta API (official): WhatsApp Business integration for inbound and outbound messages

Agent Interface

Chatwoot: human agent console for fallback support and conversation management

Database

PostgreSQL: session state, conversation history, cache tables with Blue-Green swap strategy

Infrastructure

Docker + Coolify on self-hosted VPS: full control, data privacy, zero vendor lock-in