Back to Recipes

WhatsApp Sales Agent

Research leads, draft personalized WhatsApp messages, send outreach, track replies, and escalate warm prospects to human sales.

Best for: Agencies, founders, sales teams, local service businesses

What You Get

  • -Lead research workflow
  • -Message generation with personalization
  • -Follow-up scheduling logic
  • -CRM update automation
  • -Human escalation rule engine

Step by Step

1. Set up the database

Create a PostgreSQL database with tables for leads (id, name, phone, company, role, source, status, enriched_data), messages (id, lead_id, content, direction, status, sent_at), and escalation_log (id, lead_id, reason, assigned_to, resolved_at).

2. Configure WhatsApp Business API

Register for WhatsApp Business API access. Set up a webhook endpoint to receive incoming messages and delivery status callbacks. Configure rate limits (250 messages per day per number for marketing).

3. Build lead import and enrichment

Create an API to accept lead CSV uploads. On import, enrich each lead using OpenAI: extract company info, role seniority, and potential pain points from their website. Store enriched data as JSON in the leads table.

4. Implement message generation

Use OpenAI to generate personalized WhatsApp messages. Prompt should include: lead name, company, role, a relevant pain point, and a clear call to action. Include template variables for fallback.

5. Build the sending pipeline

Create a queue-based sending system that processes leads in batches. Send messages, update status, and handle delivery receipts via webhook. Implement retry logic for failed sends.

6. Track replies and escalate

Parse incoming WhatsApp messages. Use OpenAI to classify intent: interested, not interested, need more info. Auto-escalate interested leads to a human via Slack webhook or CRM task creation.

7. Build the dashboard

Create a simple Next.js dashboard: lead list with status filters, message history view, escalation queue for human review, and stats (sent, delivered, replied, conversion rate).

Stack

WhatsApp Business APIOpenAIPostgreSQLNode.js/Next.jsCRM webhook integration

Build This

Copy this prompt and paste it into Claude Code, OpenCode, Codex, or Cursor to build this recipe.

Build a WhatsApp sales outreach agent using Node.js and PostgreSQL. ROLE: You are an AI-powered sales automation system that researches leads, crafts personalized outreach, and manages the conversation lifecycle. CONSTRAINTS: - Rate limit to 250 messages/day per number (WhatsApp marketing limit) - All messages must comply with WhatsApp Business Policy (no unsolicited bulk messaging) - Use temperature=0.7 for message generation to balance personalization with consistency - Never send messages without human approval for first 10 leads (warm-up period) - Log every action with timestamps for audit trail TOOL CALLING: - Use function calling to interact with: WhatsApp Business API (send_message, get_delivery_status, get_reply), CSV parser (parse_leads), CRM API (create_contact, update_contact), Slack webhook (send_notification) - Each tool call must use the official API schema — define parameters as JSON Schema objects - On tool failure: retry once with exponential backoff, then escalate to human STRUCTURED OUTPUT: - Lead enrichment must return JSON: { company_size: string, tech_stack: string[], pain_points: string[], role_seniority: string, confidence: number } - Message generation must return JSON: { message_text: string, personalization_tokens: string[], cta: string, tone: string } - Reply classification must return JSON: { intent: 'interested' | 'not_interested' | 'need_more_info' | 'unsubscribed', confidence: number, reasoning: string } - Use response_format with JSON mode or parse validated JSON from the LLM response CHAIN OF THOUGHT: - Before generating each message, reason through: lead's likely pain points → which product feature addresses it → optimal CTA → tone calibration - Before classifying a reply, reason through: explicit signals → implicit signals → confidence assessment FEW-SHOT EXAMPLES: Include 3 example message generations in the system prompt: Example 1: Input: {name: 'Carlos', company: 'TechMex', role: 'CTO', pain_point: 'slow deployment'} → Output: 'Hola Carlos, vi que TechMex está escalando rápido. ¿Cómo están manejando el deploy de código actualmente? Muchos CTOs me comentan que el deployment manual les quita 5h/semana. Tenemos una solución que lo reduce a 15 min.' Example 2: Input: {name: 'Sarah', company: 'GrowthCo', role: 'VP Sales', pain_point: 'lead Follow-up gaps'} → Output: 'Hi Sarah, noticed GrowthCo is hiring 3 SDRs — that usually means the follow-up pipeline is getting complex. We built a system that auto-escalates warm leads within 5 minutes. Want to see how it works?' Example 3: Input: {name: 'Miguel', company: 'DataFlow', role: 'CEO', pain_point: 'manual reporting'} → Output: 'Miguel, saw DataFlow raised their Series A — congrats! With growth comes reporting overhead. We automated daily biz reports for a similar company and saved the CEO 3 hours every morning. Quick demo?' EVALUATION CRITERIA: - Message personalization score: must reference at least 2 of {name, company, role, pain_point} - CTA clarity: each message must have exactly one clear next step - Reply classification accuracy: measure against a labeled test set of 50 replies - End-to-end success rate: percentage of leads that reach 'interested' status OUTPUT FORMAT: Return results as structured JSON with fields: lead_id, message_text, personalization_score (0-1), cta_type, classification (if reply), next_action. The system should include: 1) CSV import and lead enrichment pipeline, 2) Message generation with personalization, 3) WhatsApp Business API integration with rate limiting, 4) Reply tracking and intent classification, 5) Human escalation for warm leads via Slack/CRM, 6) PostgreSQL logging, 7) Dashboard for lead review and manual follow-up triggers.

Common Failure Modes

  • !WhatsApp number not connected to API
  • !Rate limiting from WhatsApp
  • !Message templates rejected by WhatsApp review
  • !Poor personalization from bad lead data

Implementation Notes

Start with 5 test leads before scaling to full list. Verify WhatsApp Business API credentials before building the agent. Use a staging phone number first.

Related skill: whatsapp sales outreach

Ship whatsapp sales agent in production with 4M Labs

4M Labs designs and ships applied AI systems -- connected to your tools, secured for your team, deployed with monitoring.

  • Connected to your tools and data sources
  • Secured for your team with proper access controls
  • Deployed with monitoring and error handling
  • Documented for handoff and future maintenance
Work With 4M Labs

Frequently Asked Questions

Can I use this recipe in production?
Yes. Every recipe is production-tested with error handling, logging, and deployment guidance.
Which LLM providers are supported?
Recipes support OpenAI, Anthropic Claude, Google Gemini, and open-source models via a unified interface.
How do I customize these recipes?
Each recipe includes a configuration section. Override model selection, API keys, and parameters without changing core logic.