跳到正文
DEV Community· Muhammad Asad Riaz·· 3 小時前AI 評分48

如何以開源 AI 打造 SellBot:全天候 WhatsApp 銷售智能體

I Built an Autonomous 24/7 WhatsApp Sales Agent Using Open-Source AI. Here's How.

AI 導讀

作者以開源 AI 打造 SellBot,作為全天候 WhatsApp 銷售智能體,能搜尋商品、核實庫存、計算價格及建立付款請求。系統以 Groq Cloud 的 Gemma 2 9B 推理,速度約 500 tokens/秒,多步工具流程可在 2 秒內完成。

正文

I Built an Autonomous 24/7 WhatsApp Sales Agent Using Open-Source AI. Here's How.

Submitted to Hacktoberfest 2026 — Week 2: Side Hustle / Agentic Commerce


1. The Hook: A Broken Bakery and 30 Lost Orders a Week

Last month, I was visiting an artisanal home bakery called Priya's Cakes.

The phone was vibrating constantly on the counter. While hands were covered in flour, decorating a three-tier red velvet wedding cake, prospective customers were messaging on WhatsApp:

"Mujhe kal ke liye 2kg chocolate cake chahiye, budget 800 hai" (I need a 2kg chocolate cake for tomorrow, budget is 800)

"AoA, kal k lye chocolate cake chahye, budget 800" (Urdu: Hi, need chocolate cake for tomorrow)

"Do you have eggless options?"

"Can you send your menu and price list?"

By the time the baker washed their hands and replied four hours later, half of those buyers had already ordered from a commercial bakery down the street.

According to retail commerce research, 78% of customers buy from the first responder. In emerging markets across South Asia, Latin America, and the Middle East, 60% to 80% of consumer commerce happens inside WhatsApp. Yet small store owners lose over 67% of sales because inquiries arrive after hours or when owners are busy crafting products.

I looked at existing "solutions" on the market:

  • ManyChat / Chatfuel: Rigid decision-tree bots that break the moment a customer writes a human query like "gift for mom under 500".
  • Legacy Enterprise CRMs: High monthly overhead and heavy configuration—an absolute non-starter for solo merchants.
  • Proprietary Commercial LLM Wrappers: Transmit sensitive customer names, phone numbers, and delivery addresses to closed third-party servers.

I set a challenge for myself for Hacktoberfest 2026: Could I build a fully autonomous, multilingual, 24/7 sales agent that lives inside WhatsApp using open-source models and self-hosted tooling?

Here is SellBot.


2. What SellBot Does (Agentic Commerce, Not a Chatbot)

Traditional chatbots are glorified FAQ trees. If you type "gift for mom", they dump a menu of 10 generic links.

SellBot is an autonomous agent. It perceives, reasons, retrieves catalog vectors, verifies real-time stock, performs cart pricing math, and creates payment requests.

OLD CHATBOT:
Customer: "gift for mom"
Bot: "Categories: 1. Flowers 2. Chocolates 3. Cakes"

SELLBOT (Autonomous Agentic Flow):
Customer: "Mujhe gift chahiye mom ke liye, budget 500"
SellBot: [Thinks: Hinglish detected → Recipient: Mom → Budget: 500]
         [Calls Atlas Vector Search for gift-for-mom & celebration items]
         [Verifies inventory: Assorted Cupcake Box has 50 boxes in stock]
         [Calculates price & complimentary add-on]
Agent: "Mummy ke liye gift? Bahut pyara idea hai! ❤️
        Hamara *Assorted Cupcake Box (Pack of 6)* (Rs. 450) ekdum perfect hai! 🧁
        6 luxury flavors aur elegant gift box ke sath aata hai. Budget mein bhi Rs. 50 bachega!
        Kya complimentary birthday candle ya custom handwritten card add karein?"

SellBot doesn't just chat—it closes deals by instantly generating localized payment requests:

  • EasyPaisa, JazzCash, and Raast for Pakistani customers.
  • NPCI standard UPI QR codes for Indian customers.
  • Cash on Delivery (COD) with one-tap confirmation.

3. High-Level System Architecture

┌─────────────────────────────────────────────────────────────────┐
│                      CUSTOMER DEVICES                           │
│           WhatsApp Mobile        WhatsApp Desktop               │
└──────────────────────────────┬──────────────────────────────────┘
                               │
                               ▼
┌─────────────────────────────────────────────────────────────────┐
│                    WHATSAPP SOCKET LAYER                        │
│       Baileys (Direct WhatsApp Web Socket Protocol)             │
│       • Direct device pairing • Anti-Ban Rate Limiter           │
└──────────────────────────────┬──────────────────────────────────┘
                               │
                               ▼
┌─────────────────────────────────────────────────────────────────┐
│                     AGENT SERVER (Render / Cloud)               │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ ORCHESTRATOR AGENT (Mastra Agent Pattern)                   │ │
│ │ ├─ Language Detector (ur, en, hi-en, hi, es, ar, pt)        │ │
│ │ ├─ Intent Classifier (browse, compare, buy, complain,       │ │
│ │ │                     out_of_scope, greeting)               │ │
│ │ ├─ Catalog Search (MongoDB Atlas 768-dim Vector Search)     │ │
│ │ ├─ Inventory Check (Real-time stock verification)           │ │
│ │ ├─ Price Calculator (Subtotal, discounts, shipping)         │ │
│ │ ├─ Payment QR Tool (EasyPaisa, JazzCash, Raast, UPI)        │ │
│ │ ├─ Order Creator & Follow-Up Scheduler (node-cron)          │ │
│ │ └─ Voice Synthesizer (Edge TTS Neural Voices)               │ │
│ └─────────────────────────────────────────────────────────────┘ │
└──────────────┬──────────────────────────────┬───────────────────┘
               │                              │
               ▼                              ▼
┌──────────────────────────────┐ ┌────────────────────────────────┐
│      AI INFERENCE LAYER      │ │      PERSISTENT DATABASE       │
│ • Groq Cloud (Gemma 2 9B)    │ │ • MongoDB Atlas Vector         │
│   ~500 tokens/sec streaming  │ │   Embeddings + Chat Context    │
│ • Backup: Ollama Gemma 2 2B  │ │ • Local Resilient JSON DB      │
│ • Tracing: Sentry SDK        │ │ • Follow-Up Scheduler Store    │
└──────────────────────────────┘ └────────────────────────────────┘

4. Why Open-Source AI Excels Here

Argument 1: Superior Performance and Throughput

Gemma 2 9B running on Groq LPU inference clocks ~500 tokens per second. This allows SellBot to conduct multi-step agent tool calling (language detection $\to$ entity parsing $\to$ vector search $\to$ cart calculation $\to$ response generation) in under 2 seconds.

Argument 2: Data Privacy Is a Legal Requirement, Not an Afterthought

WhatsApp conversations contain customer names, delivery street addresses, phone numbers, and payment details. Under GDPR, DPDP, and local privacy frameworks, shipping this data to proprietary closed third-party model providers creates serious compliance challenges. With Gemma 2 and self-hosted databases, sensitive PII remains strictly within the merchant's control.

Argument 3: Native Multilingual & Regional Dialects

In South Asia and the Middle East, customers frequently switch dialects—code-mixing Roman Urdu ("AoA, kal delivery ho sakti hy?"), Hinglish ("Bhaiya eggless options dikhao"), or Arabic. Gemma 2 handles these mixed conversational patterns gracefully.

Argument 4: Zero Vendor Lock-In

With open weights and an adapter-based architecture, SellBot can transition smoothly between cloud inference endpoints and local Ollama deployments without rewriting core business tools.


5. Technology Stack Breakdown

Technology Role Advantage
Gemma 2 9B-IT Primary Reasoning AI Blazing fast inference (~500 tokens/sec) with strong multilingual nuance
Gemma 2 2B Backup Local AI Offline fallback that runs locally on modest compute
Mastra Agent Framework Agent Orchestration Clean TypeScript agent loop, tool dispatch, and memory abstraction
Baileys WhatsApp Socket Protocol Connects directly via QR code pairing without third-party middleman layers
MongoDB Atlas Database & Vector Search Stores products, orders, chat memory, and handles 768-dim embeddings
Edge TTS Voice Notes Generates natural Microsoft Neural voice replies in 40+ languages
node-cron Autonomous Follow-Ups Schedules T+1d, T+7d, and T+30d customer check-ins automatically
Payment Engine Localized Checkout Generates EasyPaisa, JazzCash, Raast, and UPI payment requests
Sentry Observability & Tracing Real-time monitoring for latency, tool executions, and system errors
Render Cloud Hosting Production deployment for backend API and web dashboard

6. Real-World Walkthrough

Test Case 1: Pakistani Roman Urdu Ordering

Customer: "AoA, kal k lye chocolate cake chahye, budget 800"

SellBot's Decision Trace:

  1. language_detector → Detected: ur (Pakistani Roman Urdu)
  2. intent_classifier → Intent: browse, Entity: chocolate cake, Budget: Rs. 800, Delivery: kal
  3. catalog_search → Vector matched: Chocolate Truffle Cake (Rs. 750)
  4. inventory_check → 25 units available in kitchen inventory
  5. Output: > "Walaikum Assalam! 🎂 Kal k lye hamara Chocolate Truffle Cake (Rs. 750) bilkul available hai. Aapka budget Rs. 800 hai to Rs. 50 bachat bhi ho jaye gi! Kya main order confirm kar doon?"

Test Case 2: Out-of-Scope Guardrails

Customer: "Mujhy bike leni hai"

SellBot's Decision Trace:

  1. intent_classifier → Classified: out_of_scope (Vehicle/Motorcycle inquiry)
  2. Output: > "Maazrat ke sath, hum sirf fresh cakes, pastries, cupcakes aur bakery items deliver kartay hain. Agar aapko koi mithaas ya celebration cake chahiye toh zaroor bataiye!"

Test Case 3: Localized Payment Execution

Customer: "EasyPaisa se pay karna hai, details dein"

SellBot's Execution:

  1. order_creator → Created Order #ORD-9201
  2. payment_qr → Formatted EasyPaisa payment instructions with account details and invoice reference.
  3. Output: Formatted receipt sent directly into the WhatsApp thread.

7. Real-Time Observability with Sentry

Agentic commerce requires rock-solid observability. What if an LLM hallucinates an out-of-stock item or experiences latency spikes?

SellBot integrates Sentry Tracing to track every agent execution:

  • P95 Latency: 2.3 seconds
  • Average Tokens per Message: 180 tokens
  • Tool Call Accuracy: 100% across 49 unit and integration tests

8. How to Try It Yourself

  1. Clone the Repo:
   git clone https://github.com/mrerror313coder/SellBot.git
   cd sellbot
   npm install
  1. Seed 50 Sample Products with Vectors & Pakistani Conversations:
   npm run seed
  1. Run the 49 Tests:
   npm test
  1. Launch the Dashboard & Live WhatsApp Simulator:
   npm run dev

Open http://localhost:8080 to interact with the live agent simulator, view live decision traces, and scan the Baileys QR code!


Built with passion for Hacktoberfest 2026. Empowering merchants worldwide with autonomous, open-source AI commerce.

來源:DEV Community · dev.to