WhatsApp Business + AI Memory

WhatsApp Business API powers customer conversations for millions of businesses. By adding REM Labs, your WhatsApp bot remembers every customer interaction -- their preferences, purchase history, and support context -- making every conversation feel personal rather than robotic.

Architecture Overview

The WhatsApp Business API sends webhooks to your server when messages arrive. Your server checks REM Labs for customer context, generates a response with an LLM, stores the interaction, and replies via the WhatsApp API.

WhatsApp → Your Webhook → REM Labs (recall) → LLM (generate) → REM Labs (remember) → WhatsApp (reply)

Webhook Handler with Memory

// server.js (Express + Node.js) import express from "express"; import { RemLabs } from "@remlabs/sdk"; import OpenAI from "openai"; const app = express(); const memory = new RemLabs({ apiKey: process.env.REMLABS_KEY }); const openai = new OpenAI({ apiKey: process.env.OPENAI_KEY }); app.post("/webhook", express.json(), async (req, res) => { const msg = req.body.entry?.[0]?.changes?.[0]?.value ?.messages?.[0]; if (!msg) return res.sendStatus(200); const phone = msg.from; // customer phone number const text = msg.text?.body || ""; const namespace = `whatsapp-${phone}`; // 1. Recall customer context const memories = await memory.recall({ query: text, namespace, limit: 5 }); const context = memories .map(m => m.content).join("\n"); // 2. Generate personalized response const completion = await openai.chat.completions.create({ model: "gpt-4o", messages: [ { role: "system", content: `You are a helpful business assistant. Customer history:\n${context}` }, { role: "user", content: text } ] }); const reply = completion.choices[0].message.content; // 3. Store this interaction await memory.remember({ content: `Customer: ${text}\nAgent: ${reply}`, namespace, tags: ["whatsapp", "support"] }); // 4. Send reply via WhatsApp API await fetch( `https://graph.facebook.com/v18.0/${process.env.PHONE_ID}/messages`, { method: "POST", headers: { "Authorization": `Bearer ${process.env.WA_TOKEN}`, "Content-Type": "application/json" }, body: JSON.stringify({ messaging_product: "whatsapp", to: phone, text: { body: reply } }) } ); res.sendStatus(200); }); app.listen(3000);

Customer Profile Building

Over time, REM Labs builds a rich profile for each customer. Store structured data alongside conversations:

// After a purchase await memory.remember({ content: `Customer purchased: Blue Widget x2, total $49.98, order #12345. Shipping preference: express delivery. Said they are buying for a birthday gift.`, namespace: `whatsapp-${phone}`, tags: ["purchase", "order-12345"] }); // Later, the bot can recall: // "Has this customer ordered before?" // → Yes, they bought Blue Widgets for a birthday

Handoff to Human Agents

When escalating to a human agent, include the customer's memory context so the agent does not ask the customer to repeat themselves:

// On escalation const history = await memory.recall({ query: "recent interactions and issues", namespace: `whatsapp-${phone}`, limit: 10 }); // Pass to human agent dashboard await notifyAgent({ phone, summary: history.map(m => m.content).join("\n\n") });

Compliance: REM Labs encrypts all data at rest (AES-256) and in transit (TLS 1.3). For GDPR compliance, use the forget endpoint to delete a customer's memories on request.

Give your WhatsApp bot a memory

Free tier. Per-customer memory isolation. GDPR-ready forget endpoint.

Get started free →