Most of your customers already use WhatsApp every day. A chatbot on that channel answers questions at midnight, collects lead details and hands the good ones to your sales team. Building one is easier than it was a few years ago, and there are still places where projects go wrong. This guide covers what you need, how the pieces fit together and six lessons from building the bot that answers messages for Ivaan Information Technology.
What you need before writing code
- A Meta business account. Create it in Meta Business Suite and complete business verification. Verification takes days, so start first.
- The WhatsApp Business Platform (Cloud API). Meta hosts the infrastructure and you talk to it over HTTPS. You do not run your own servers for WhatsApp.
- A phone number. Use a number that is not already tied to a regular WhatsApp account, or one you are willing to migrate.
- Credentials. A permanent access token, the phone number ID and the app secret. Store all three as secrets in your hosting dashboard, never in the repository.
- A public webhook URL. Meta calls it every time a customer writes to you.
How the pieces fit together
- A customer sends a message to your number.
- Meta sends a
POSTrequest with the message to your webhook. - Your server checks the request came from Meta, then reads the message.
- Your code loads the conversation so far and asks a language model for a reply, giving it a few tools such as "save this lead".
- Your server sends the reply back through the Graph API, and stores the updated conversation in a database.
Besides plain text, the API supports images, contact cards, lists, buttons and WhatsApp Flows, which are short in-app forms. A bot that shows your portfolio as five images and a tappable list feels far better than one that pastes links.
Six lessons from building ours
1. Verify every webhook call
Your webhook URL is public. Anyone can send it a forged message that looks like a customer lead or tries to make your bot spend money on model calls. Meta signs each request with an X-Hub-Signature-256 header, an HMAC of the raw body made with your app secret. Compute the same value and compare the two with a constant-time function before you touch the payload. Reject the request when the secret is missing, instead of skipping the check.
2. Learn the 24-hour rule early
WhatsApp lets you send any kind of message for 24 hours after a customer's last message. Outside that window you can only send pre-approved template messages. This shapes your design. A follow-up three days later needs a template, and so does a one-time code. Submit templates for approval early, because review can take a while, and keep their wording generic so they pass the first time.
3. Keep memory short and let it expire
We store the last 15 turns of each conversation. If a customer is silent for two hours we start fresh, and a greeting on a long chat resets it too. Typing "restart" always works. Old context wastes tokens and confuses the model: a person asking about pricing on Monday does not want the bot to continue Friday's talk about a different project. Tell customers about the restart command in your prompt.
4. Give the model tools, and a strict rule for each
Our bot can save a lead, show projects, offer a booking flow and share a contact card. Each tool has a description that says when to call it, and the system prompt repeats the key rule: do not call a tool for a greeting. Without that line, models tend to fire tools early. Validate tool arguments with a schema before acting on them, so a hallucinated email address never reaches your CRM.
5. Reply even when the AI fails
Language model providers have outages, rate limits and slow days. Our first version stayed silent when the model call failed, and the customer saw nothing. Now the bot answers with a short apology and the team's phone number, and it does not save the failed turn, so the customer can send the message again. A bot that says "I'm having trouble" keeps trust. A bot that says nothing loses the lead.
6. Test the path from chat to your team
A lead only counts when someone on your team sees it. We forward conversational leads to a Google Sheet and by email. After a security change on our contact form, the bot's lead forwarding stopped working. The chat still looked fine, and leads piled up in the database where nobody was looking. We found it in a review, not through an alert. Test the whole path with a real message after every release, and watch your logs for forwarding errors.
Privacy and cost
Collect only what you need, tell customers how you use their details, and keep message text out of your logs. Log the step that failed and the error code instead. For cost, Meta changes its pricing model from time to time and charges by message category, so check the current rates for your country before you promise a budget. Model usage is a second cost, and short conversation memory keeps it low.
When a chatbot is not the answer
A bot suits first answers, qualification and scheduling. It does not suit disputes, medical or financial advice, or anything where a wrong answer costs real money. Give customers a clear way to reach a person, and hand over the conversation with its history attached.
A checklist before you launch
- Business verification is complete and templates are approved.
- The webhook verifies signatures and fails closed.
- Secrets live in the hosting dashboard.
- Conversations expire, and "restart" works.
- Every tool has a rule and validated arguments.
- A failed model call produces a friendly reply.
- A test lead reaches your Sheet or CRM and your inbox.
- Logs show errors by step and contain no message text.
Connect the chatbot to the rest of your business
A chatbot is most useful when it talks to the tools you already use. Beyond leads, it can send invoices, payment reminders and order updates. Our Lena Dena business platform shares invoices, delivery challans and supplier orders on WhatsApp and sends due-date reminders, so customers see them on the app they already check all day. Pair that with a bot for first replies and you have a complete loop: the customer asks, the bot answers, the team confirms, and the invoice arrives in the same chat.
Start small
- Pick one job, such as collecting leads or sending payment reminders.
- Write the ten most common questions and their answers.
- Test with your team for a week before real customers see it.
We build WhatsApp assistants, website chatbots and lead automation for businesses. See our WhatsApp automation project and our AI and chatbot services, or tell us what you want your bot to do and we will suggest a plan.

