Back to Blog
AI Agents April 25, 2025 12 min read

Building a WhatsApp AI Sales Agent with n8n and Ollama

How I built a production WhatsApp AI agent for a Moroccan e-commerce business — architecture, conversation memory, product catalog Q&A, and order tracking.

Architecture Overview

WhatsApp Business API
        ↓
    n8n Webhook
        ↓
   Ollama (Llama 3.1 8B) ← Product DB (Postgres)
        ↓
   Conversation Memory (Redis)
        ↓
  WhatsApp Reply

n8n Workflow Nodes

  1. Webhook — receives WhatsApp messages
  2. Redis GET — load conversation history (last 10 turns)
  3. Postgres — retrieve product details by name/category
  4. Ollama Chat — generate response with context
  5. Redis SET — save updated conversation
  6. HTTP Request — send reply via WhatsApp Cloud API

System Prompt

You are Amina, a friendly bilingual (FR/AR) customer service agent for [Store]. 
Always respond in the same language the customer uses.
Only recommend products from the provided catalog.
Never invent prices or availability.

Conversation Memory Design

Store as JSON array in Redis with 24h TTL:

[{"role":"user","content":"..."},
 {"role":"assistant","content":"..."}]
n8nWhatsAppOllamaLLM AgentsAutomation
O

Ossama Elhakki

AI Engineer & ML Systems Builder — Morocco