You are building a “virtually free” WhatsApp chatbot with 100% automation using Meta WhatsApp Cloud API + Firebase (Functions, Firestore, Hosting, Storage). The bot must work in Hindi + English, be flow-first (buttons/lists) and use AI only as escalation (RAG) so operating costs stay near-zero. Webstore integration will be added later; design all services as internal APIs so the bot doesn’t need rewriting. CONTEXT: - Expected volume: ~300 WhatsApp conversations/month. - Goals: Both sales + support. - Product scope: Books + Stationery + Notebooks + Toys + Gifts (all). - Languages: Hindi and English. - “Baremetal” means we own the app (not Shopify/WooCommerce dependency). Later we will connect to our webstore. STACK (MANDATORY): - Meta WhatsApp Cloud API (direct, not a BSP tool). - Firebase: Cloud Functions (Node.js TypeScript), Firestore, Firebase Hosting, Firebase Storage. - Optional but preferred: Firebase Authentication for admin panel. - AI: Use an API-based LLM only when necessary. Must be RAG-based on our own knowledge base in Firestore/Storage. No hallucinations allowed; if low confidence, open a ticket. - Deployment: Firebase project with environments (dev + prod). CORE REQUIREMENTS: 1) WhatsApp Bot Features (MVP) - Language selection at start: हिन्दी / English - Main menu (interactive list): 1) Place Order / ऑर्डर करें 2) Catalog + Prices / कैटलॉग व रेट 3) Track Order / ऑर्डर ट्रैक करें 4) Wholesale / B2B / होलसेल 5) Corporate Gifting / कॉर्पोरेट गिफ्टिंग 6) Support / सपोर्ट - Each menu option must be a deterministic flow (finite state machine) stored in Firestore session state. - Support flow must have categories: - Payment issue, Wrong/Missing item, Return/Replace, Delivery, Invoice/GST, Other (AI escalation) - Create Ticket automatically when: - AI confidence < threshold - user stuck 2 times - complaint keywords appear - All flows must end with a clear “Next action” CTA. 2) “AI Learning” Loop (Practical) - Log unanswered questions + drop-offs into Firestore - Nightly job clusters unresolved questions and drafts suggested FAQ entries - Put suggestions into an Approval Queue for admin panel - After approval, add to knowledge base; future answers improve (RAG) 3) Data Model (Firestore collections) - customers/{phone}: {name, language, tags, createdAt} - sessions/{phone}: {state, step, lastIntent, updatedAt, context} - messages/{id}: {phone, direction, text, payload, ts} - orders/{id}: {phone, items[], amount, status, createdAt, paymentRef} - tickets/{id}: {phone, category, summary, status, createdAt} - kb_docs/{id}: {title, source, text, lang, updatedAt} - kb_suggestions/{id}: {question, draftAnswer, lang, status(pending/approved/rejected)} 4) Webhooks + Security - Implement WhatsApp webhook verification. - Verify request signature where applicable; never accept spoofed requests. - Rate limit per phone number + abuse protection. - Do not store sensitive data unnecessarily (mask payment refs). - Maintain audit logs for admin changes. 5) Admin Panel (minimal) - View: tickets, orders, wholesale leads - Approve/Reject KB suggestions - Edit static content (store timings, policies, FAQs, messages) - Hosted on Firebase Hosting. 6) Cost Control - Use interactive flows as default; AI only for “Other” or complex free text. - Cache answers for repeated FAQs. - Keep WhatsApp messaging costs low by encouraging user-initiated conversations. DELIVERABLES: A) Architecture doc (1–2 pages) + flow map B) Firebase project structure (repo) C) Cloud Functions code with: - /whatsapp/webhook (receive) - /whatsapp/send (internal helper) - /cron/nightly-learning D) Firestore rules + indexes E) Admin panel (React) basic screens F) Setup guide: step-by-step to connect Meta WhatsApp Cloud API, configure webhook, deploy to Firebase G) Test plan + sample test conversations (Hindi + English) ACCEPTANCE CRITERIA: - Bot runs end-to-end in WhatsApp with menus + flows and stores session state. - Tickets are created automatically for escalations. - Admin can approve KB suggestions and they affect bot answers. - Code is clean, documented, and deployable. No hardcoded secrets. - Must work without any paid third-party chatbot platforms.