Most WhatsApp bots are terrible. They get stuck in loops ("Press 1 for Sales"). We recently built a "Human-Level" Sales Agent for a Real Estate client in Tulum to handle 500+ leads/week. Here is the architecture and code we used to do it.
The Problem: Speed
In high-ticket sales (like Real Estate in Tulum), if you don't reply in 5 minutes, the lead is gone. Humans are slow. Scripts are dumb. AI is the only way.
The Tech Stack
Engine: Node.js (Express or Serverless Functions)
API: WhatsApp Cloud API (Official Meta API)
Brain: OpenAI GPT-5 (JSON Mode enabled)
Memory: Firestore / Redis
Snippet: The "Context" Manager
The secret isn't calling OpenAI. It's injecting context before you call it.
javascript
/*
We pull the user's previous chats from the DB
so the bot "remembers" they wanted a 2-Bedroom Condo.
*/
async function getContext(userId) {
const doc = await db.collection('chats').doc(userId).get();
if (!doc.exists) return [];
// Return last 10 messages to save tokens
return doc.data().messages.slice(-10);
}
The System Prompt
This is where the magic happens. Don't just say "You are a helpful assistant." Be specific.
text
SYSTEM_PROMPT:
"You are Senior Broker at a luxury agency in Mexico.
Your goal is to get the user's Budget and Move-in Date.
Do not write long paragraphs. Keep it under 2 sentences (like a WhatsApp text)."
Integrating with CRM
Once the bot detects a "Hot Lead" (e.g., user says "I have $500k cash"), we trigger a webhook to JegoDigital's CRM to alert a human agent immediately.
Results
Response Time: 4 hours -> 12 seconds.
Conversion: +30% meetings booked.
If you are a dev, stop building "Menu Bots". Start building Agents.
SYSTEM_PROMPT:
"You are Senior Broker at a luxury agency in Mexico.
Your goal is to get the user's Budget and Move-in Date.
Do not write long paragraphs. Keep it under 2 sentences (like a WhatsApp text)."
Integrating with CRM
Once the bot detects a "Hot Lead" (e.g., user says "I have $500k cash"), we trigger a webhook to JegoDigital's CRM to alert a human agent immediately.
Results
Response Time: 4 hours -> 12 seconds.
Conversion: +30% meetings booked.
If you are a dev, stop building "Menu Bots". Start building Agents.
"Are you a developer? faster response times are great, but how do you actually build it? We released the open-source architecture and Node.js code in our Technical Guide: Building a WhatsApp AI Bot."
About the Author: CTO at JegoDigital, building white-label AI solutions for businesses.
Top comments (0)