Building an AI Chatbot for a Pakistani Business with OpenAI
    AI & Automation 8 min read

    Building an AI Chatbot for a Pakistani Business with OpenAI

    AI Chatbot OpenAI WhatsApp Pakistan

    Building an AI Chatbot for a Pakistani Business


    For most local SMEs the winning channel is WhatsApp, and the winning bot handles Urdu, English, and Roman Urdu without complaint. Here is the stack that works.


    Architecture


  1. **WhatsApp Business Cloud API** — Meta's official webhook, free tier is generous.
  2. **FastAPI** receiver on a small VPS or Cloud Run.
  3. **OpenAI Responses API** with function calling.
  4. **Postgres + pgvector** for product knowledge and past chats.
  5. **Admin dashboard** for humans to take over any chat instantly.

  6. Retrieval, Not Just Prompting


    Never dump a large catalogue into the prompt. Chunk it, embed it, and retrieve the top few chunks per query. Costs drop dramatically and answers get sharper.


    Handling Urdu and Roman Urdu


    Modern GPT-4-class models handle both natively. Two rules:


  7. **Detect language** with a cheap classifier and reply in the same script.
  8. **Keep the system prompt in English** — the model follows English instructions more reliably.

  9. Function Calling for Real Actions


    Give the model tools, not just words: check stock, create order, get order status, escalate to human. The model chooses when to call them. Your backend enforces authorisation.


    Cost Control


  10. Use a small model for triage, escalate to a larger model only for complex intents.
  11. Cache retrieved chunks per session.
  12. Cap output tokens per reply.

  13. Typical run cost for an SME with a few thousand conversations per month is small — usually less than a single human agent shift.


    Safety Rails


  14. Never let the bot promise a price the catalogue doesn't confirm.
  15. Always allow the customer to type `agent` and reach a human.
  16. Log every conversation for review — mandatory for regulated industries.

  17. Rollout


    Start with one narrow use case (order status, or product recommendations). Measure containment rate weekly. Only add scope when the current scope is solid — the failed chatbots are the ones that tried to do everything on day one.


    Wrap-Up


    A well-scoped AI chatbot deflects 40–60% of routine queries and pays for itself inside a quarter. Keep it narrow, retrieve well, and let humans take over cleanly.

    Related Articles

    © 2026 Muhammad Ul Hasnain. All rights reserved.

    Crafted with in Islamabad, Pakistan