
In today’s world, customers expect instant replies especially when they message a business. But for small teams, it’s impossible to stay online 24/7. That’s where AI-powered sales agents step in.
I recently built a WhatsApp AI Sales Agent that automatically replies to customer messages on your WhatsApp Business number. It shares product information directly from a product catalog and answers questions conversationally using Groq’s LLaMA model.
Let’s break down how it works.
The Flow
- User sends a WhatsApp message to the business number.
- Meta’s WhatsApp Cloud API triggers a webhook to our backend endpoint (
/api/webhook). - On receiving the webhook:
- Extracts the sender ID and message content (
lib/whatsapp.ts). - Loads product catalog data from
products.csv(lib/loadCsv.ts). - Builds a context prompt and queries Groq’s LLaMA model (
lib/groq.ts). - The AI generates a reply.
- The reply is sent back to the customer on WhatsApp (
lib/whatsapp.ts).
- Extracts the sender ID and message content (
This ensures customers instantly receive product info and answers—even outside business hours.
Key Components
- Webhook Handler (
app/api/webhook/route.ts)- Handles GET requests for Meta’s webhook verification (returns
hub.challenge). - Handles POST requests for incoming messages, processes them, and returns replies.
- Handles GET requests for Meta’s webhook verification (returns
- WhatsApp Cloud API Helpers (
lib/whatsapp.ts)- Extract sender and message fields.
- Send AI-generated messages back to customers.
- CSV Loader (
lib/loadCsv.ts)- Reads
products.csv. - Formats product details into a structured context for the AI.
- Reads
- AI Integration (
lib/groq.ts)- Calls Groq’s LLaMA model.
- Passes product data + user query as context.
- Returns natural language answers tailored to the catalog.
- Product Catalog (
products.csv)- A simple CSV file containing product details.
- Keeps the setup lightweight, scalable, and easy to update.
Configuration
Environment variables keep secrets and API keys secure:
WHATSAPP_TOKEN– WhatsApp API auth tokenWHATSAPP_PHONE_ID– WhatsApp Business phone IDWHATSAPP_VERIFY_TOKEN– Used during webhook verificationGROQ_API_KEY– Authentication for Groq’s LLaMA modelAI_SYSTEM_PROMPT(optional) – Custom system prompt for guiding AI responses
Deployment
The backend is built using Next.js API Routes and deployed on Vercel. This makes the system:
- Serverless & Scalable – No servers to manage, scales automatically.
- Lightweight – Just CSV + API calls, no complex database required at Stage 1.
- Easily Extensible – Future features like authentication, analytics, or payments can be layered in.
Why This Matters
- 24/7 Customer Engagement – Customers get immediate answers without waiting.
- Reduced Workload – Teams don’t need to manually answer FAQs or product queries.
- Scalable Foundation – The CSV-based MVP can later evolve into a full e-commerce backend.
Right now, this AI Sales Agent covers the basics: answering queries and sharing product info. There are lot of features that could be added to this project which i looking forward to .