Practical AI Chatbots on WhatsApp: Automating Repetitive Customer Inquiries
For businesses operating in Nepal, WhatsApp is not just a messaging utility; it is the primary commercial channel where customers ask about product stock, pricing, store locations, and warranty terms. However, retail teams spend hours every day answering the exact same repetitive questions: "Delivery charge kati ho?", "Butwal ma store kata cha?", or "eSewa bata pay garna milcha?". Deploying an intelligent AI chatbot directly on WhatsApp automates over 80% of customer support around the clock.
Strategic Executive Summary
- Core Insight: Modern Large Language Models (LLMs) understand Romanized Nepali (e.g. "Mero parcel kahile aipugcha?" ), standard Devanagari, and English effortlessly when primed with a structured system prompt.
- Production Quality: Battle-tested engineering techniques designed specifically for Nepal's network infrastructure and business environment.
- Direct Implementation: Copy-paste ready code architectures with security safeguards against race conditions, data corruption, and unauthorized access.
Table of Contents
1. Meta Cloud API Webhook Architecture
The Meta Cloud API transmits incoming WhatsApp messages via asynchronous HTTP POST webhooks to your server. First, verify the webhook registration endpoint:
<?php
// Webhook Verification (webhook.php)
$verify_token = "SAFAL_WHATSAPP_TOKEN_SECRET_987";
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if (isset($_GET['hub_mode']) && $_GET['hub_mode'] === 'subscribe' &&
isset($_GET['hub_verify_token']) && $_GET['hub_verify_token'] === $verify_token) {
echo $_GET['hub_challenge'];
exit;
}
http_response_code(403);
exit;
}
2. Processing Inbound Messages and Connecting to AI
When a customer sends a message, extract the phone number and message body, query the LLM API with your company knowledge base, and dispatch the answer:
<?php
$input = file_get_contents('php://input');
$payload = json_decode($input, true);
if (isset($payload['entry'][0]['changes'][0]['value']['messages'][0])) {
$messageData = $payload['entry'][0]['changes'][0]['value']['messages'][0];
$from = $messageData['from']; // Customer phone number
$text = $messageData['text']['body'] ?? '';
if (!empty($text)) {
// Query LLM with Company Context
$aiResponse = queryAiAssistant($text);
// Send reply back via Meta Cloud API
sendWhatsAppReply($from, $aiResponse);
}
}
http_response_code(200);
3. Engineering the System Prompt for Nepali Retail
The secret to high-accuracy responses lies in providing crisp grounding data:
System Prompt:
You are the official digital assistant for Safal Store in Butwal, Nepal.
Knowledge Base:
- Store Location: Kalikanagar, Ward 11, Butwal (Near Horizon Chowk).
- Delivery: Same day in Butwal (NPR 50). 2-3 days outside valley (NPR 150). Free delivery on orders over NPR 3,000.
- Payment Methods: Cash on Delivery, eSewa, Khalti, Fonepay QR.
- Language Instruction: Reply warmly in the same language the customer uses (Romanized Nepali, Devanagari, or English). Keep answers concise under 3 sentences.
4. Human Handover Protocol
A great automated system knows when to step aside. If the AI detects phrases like "complain", "faulty item", "talk to manager", or "urgent", it flags the conversation in your CRM and notifies a human agent via WhatsApp or SMS, ensuring customers never feel trapped in an endless bot loop.