DEV Community

Leandro Marcos Moreira
Leandro Marcos Moreira

Posted on

Turn WhatsApp Into a 24/7 AI Sales Machine (With Code)

Your business gets WhatsApp messages at 3am. Nobody answers. Lead lost.

I built a bot that handles this automatically — qualifies leads, answers questions, and sends payment links. Here is the architecture.

The Stack

  • Baileys (WhatsApp Web protocol, no Meta API needed)
  • Claude API for intelligent responses
  • SQLite for CRM (contacts, lead scores, conversation history)
  • Zero external dependencies. Runs on a $5 VPS.

How It Works

// Message comes in
sock.ev.on("messages.upsert", async ({ messages }) => {
  const msg = messages[0];
  const text = msg.message?.conversation || "";
  const from = msg.key.remoteJid;

  // Track in CRM
  crm.trackContact(from, text);

  // AI generates response with context
  const history = crm.getHistory(from, 20);
  const response = await claude.chat({
    system: salesPrompt,
    messages: history
  });

  // Send reply
  await sock.sendMessage(from, { text: response });

  // Auto-detect buying intent
  if (response.includes("payment")) {
    crm.updateStage(from, "closing");
  }
});
Enter fullscreen mode Exit fullscreen mode

Built-in CRM

Every contact gets:

  • Lead score (0-100) based on buying signals
  • Sales stage: new → interested → qualified → closing → converted
  • Tags: auto-applied (lead, hot-lead, customer)
  • Full conversation history for AI context
CREATE TABLE contacts (
  phone TEXT PRIMARY KEY,
  name TEXT,
  lead_score INTEGER DEFAULT 0,
  stage TEXT DEFAULT "new",
  tags TEXT DEFAULT "",
  messages_count INTEGER DEFAULT 0,
  first_seen INTEGER,
  last_seen INTEGER
);
Enter fullscreen mode Exit fullscreen mode

Sales Automation

The AI handles the full funnel:

  1. Greeting — warm, asks about needs
  2. Qualification — understands budget/timeline
  3. Objection handling — addresses concerns naturally
  4. Closing — sends payment link at the right moment
  5. Follow-up — checks in after 24h silence

Not pushy. Not robotic. It builds genuine trust.

Deploy in 5 Minutes

npm install
cp .env.example .env  # add your Claude API key
npm start             # scan QR code, done
Enter fullscreen mode Exit fullscreen mode

Or Docker:

docker compose up -d
Enter fullscreen mode Exit fullscreen mode

Get the Full Template

14 files, 1450 lines of production code. CRM, sales automation, multi-language, Docker deployment.

WhatsApp AI Bot Template — $79.99

Also available:


What channels are you automating with AI?

Top comments (0)