{"meta":{"page":"blog/how-to-build-whatsapp-chatbot-step-by-step","language":"en","url":"https://spoki.com/en/blog/how-to-build-whatsapp-chatbot-step-by-step","generated_at":"2026-04-18T20:30:01.080Z","formats":{"html":"https://spoki.com/en/blog/how-to-build-whatsapp-chatbot-step-by-step","markdown":"https://spoki.com/en/blog/how-to-build-whatsapp-chatbot-step-by-step.md","json":"https://spoki.com/en/blog/how-to-build-whatsapp-chatbot-step-by-step.json","xml":"https://spoki.com/en/blog/how-to-build-whatsapp-chatbot-step-by-step.xml"}},"content":{"title":"How to Build a WhatsApp Chatbot: Best Practice and Step-by-Step Guide","sections":[{"heading":"How to Build a WhatsApp Chatbot: Best Practice and Step-by-Step Guide","level":1,"text":"**Author:** Spoki | **Published:** 2/12/2026\n\n*Build a WhatsApp chatbot with the WhatsApp Business API and Spoki. Step-by-step: templates, session, opt-in, webhook, and automation.*\n\n---\n\nBuilding a **WhatsApp** **chatbot** means combining **approved** **templates**, the **24-hour** **session**, and **opt-in** so your bot can start **conversations** and reply within **WhatsApp** **Business** **API** rules. With **Spoki** you send **templates**, receive **inbound** messages via **webhook**, and keep **automation** **compliant**.\n\nThis guide walks you through **best practice** and **step-by-step** how to **build** a **WhatsApp** **chatbot**: from **template** design and **opt-in** to **webhook** setup and **session** handling. You will find links to [registration](https://spoki.io/registration), [pricing](https://spoki.io/pricing), [support](https://spoki.io/support), [book](https://spoki.io/book), and the [ROI calculator](https://spoki.io/roi-calculator)."},{"heading":"Step 1: Understand WhatsApp Business API Rules","level":2,"text":"The **WhatsApp** **Business** **API** does not allow free-form text for the first message to a user or after the **24-hour** **session** has ended. Your **chatbot** must:\n\n- **Use approved templates to start:** The first outbound message (or any message after **24h** of no reply) must be an **approved** **template**. **Spoki** helps you create and send **templates** (e.g. “Hi {{1}}, how can we help? Reply 1 for **support**, 2 for **sales**.”). See [registration](https://spoki.io/registration) and [support](https://spoki.io/support).\n\n- **Use session messages for replies:** Once the user replies, you have **24 hours** to send **session** messages—free-form replies, **buttons**, or **quick** **replies** (within **API** limits). No **template** is required for each answer. **Spoki** delivers **inbound** messages to your **webhook** so your **chatbot** logic can reply via **Spoki**. Use [pricing](https://spoki.io/pricing) and the [ROI calculator](https://spoki.io/roi-calculator).\n\n**Best practice:** Design **templates** that open a **conversation** (e.g. menu, welcome, **reminder**). Use **session** messages for the actual **dialogue**. **Spoki** sits between your **chatbot** and the **API** so you do not have to manage **template** vs **session** rules by hand."},{"heading":"Step 2: Collect and Store Opt-In","level":2,"text":"**WhatsApp** requires that users have agreed to receive messages before you send them. **Step-by-step** for **opt-in**:\n\n- **Capture consent clearly:** When a user **registers**, clicks a **WhatsApp** link, or fills a form, ask explicitly if they want messages via **WhatsApp**. Store **opt-in** (and scope, e.g. “**support** and **sales**”) in your **CRM** or **Spoki**. **Spoki** helps you respect **opt-out** (e.g. STOP) so your **chatbot** list stays **compliant**. See [registration](https://spoki.io/registration) and [support](https://spoki.io/support).\n\n- **Scope and honour opt-out:** Do not use the same **opt-in** for unrelated **campaigns**. When a user sends **STOP**, your **chatbot** or **app** must process it (update database, stop sending). **Spoki** can forward **opt-out** events to your **webhook**. Use [book](https://spoki.io/book) for **webhook** design.\n\n**Best practice:** Check **opt-in** before every **template** send. **Spoki** helps you segment contacts so the **chatbot** only messages those who have **opt-in** for that use case."},{"heading":"Step 3: Design Templates That Start Conversations","level":2,"text":"**Templates** are the only way to initiate (or re-open after **24h**). **Step-by-step**:\n\n- **Choose a use case:** **Support** (e.g. “Reply with your **order** ID”), **lead** qualification (“Reply 1 for **sales**, 2 for info”), **reminder** (“Your appointment is tomorrow at {{1}}. Reply YES to confirm.”). **Spoki** supports **template** variables and approval workflow. See [support](https://spoki.io/support) and [pricing](https://spoki.io/pricing).\n\n- **Keep copy clear and actionable:** **Templates** should tell the user what to do next (reply with a number, confirm, etc.). That way your **chatbot** can branch on the reply. Use [registration](https://spoki.io/registration) and the [ROI calculator](https://spoki.io/roi-calculator).\n\n- **Submit for approval:** **WhatsApp** must approve **templates** before use. **Spoki** helps you submit and track **template** status. Once approved, your **chatbot** can send them to start **conversations**. Links: [book](https://spoki.io/book), [support](https://spoki.io/support)."},{"heading":"Step 4: Set Up Your Webhook and Chatbot Logic","level":2,"text":"**Spoki** sends **inbound** **WhatsApp** messages to a **webhook** URL you configure. **Step-by-step**:\n\n- **Configure webhook in Spoki:** In **Spoki** set your **webhook** URL. When a user sends a **WhatsApp** message, **Spoki** posts the event (sender, message body, etc.) to that URL. Your **chatbot** (on your server, **CRM**, or no-code tool) receives it and runs logic. See [registration](https://spoki.io/registration) and [support](https://spoki.io/support).\n\n- **Parse and respond:** Your **chatbot** parses the **inbound** message (e.g. “1” for **support**, “2” for **sales**). It then calls **Spoki** to send a **session** message back (e.g. “We’ll connect you with **support**. What’s your **order** ID?”). **Spoki** delivers the reply within the **24-hour** **session**. Use [pricing](https://spoki.io/pricing) and [book](https://spoki.io/book).\n\n- **Handle opt-out:** If the message is **STOP** (or your **opt-out** keyword), your **chatbot** must update your database and stop sending. **Spoki** can notify your **webhook** of **opt-out** events. See the [ROI calculator](https://spoki.io/roi-calculator) to plan volume.\n\n**Best practice:** Reply quickly so the **conversation** stays within the **24-hour** window. **Spoki** handles delivery and **session** rules; your **chatbot** focuses on logic and **content**.\n\n**Chatbot** logic can run on your own server, a **CRM** (e.g. with **Spoki** integration), or a no-code platform that calls **Spoki** **API**. The important part is that **inbound** messages from **WhatsApp** reach your **webhook** (via **Spoki**), and your **chatbot** replies within the **24-hour** **session** using **Spoki** to send **session** messages. If you need to send a **template** again (e.g. after **24h** of no reply), **Spoki** lets you do that too. **Opt-in** and **opt-out** must be checked and stored; **Spoki** helps you keep **compliance** so your **chatbot** does not message users who have **opted** out. Use [registration](https://spoki.io/registration), [support](https://spoki.io/support), and [pricing](https://spoki.io/pricing) to design your **webhook** and **chatbot** flow."},{"heading":"Step 5: Test and Go Live","level":2,"text":"Before going live:\n\n- **Test templates:** Send **approved** **templates** to a test number. Confirm variables (e.g. {{1}}) are filled correctly. **Spoki** lets you test from the dashboard or **API**. See [support](https://spoki.io/support).\n\n- **Test webhook:** Trigger **inbound** messages and confirm your **webhook** receives them and your **chatbot** replies with **session** messages. Check **opt-in** and **opt-out** handling. Use [registration](https://spoki.io/registration) and [book](https://spoki.io/book).\n\n- **Monitor:** Use **Spoki** to monitor delivery and **webhook** responses. Fix timeouts or errors so users get replies within the **24-hour** window. Over time, refine **templates** and **chatbot** flows. Links: [pricing](https://spoki.io/pricing), [ROI calculator](https://spoki.io/roi-calculator)."},{"heading":"Conclusion","level":2,"text":"To **build** a **WhatsApp** **chatbot**: (1) use **approved** **templates** to start and after **24h**, (2) collect and store **opt-in**, (3) design **templates** that start **conversations**, (4) set up a **webhook** and **chatbot** logic to reply with **session** messages, (5) test and go live. **Spoki** works with the **WhatsApp** **Business** **API** so you manage **templates**, **webhooks**, and consent in one place.\n\nReady to **build** your **WhatsApp** **chatbot**? Visit [Spoki](https://spoki.io) for the **WhatsApp** **Business** **API**, [registration](https://spoki.io/registration), and [pricing](https://spoki.io/pricing). Use [support](https://spoki.io/support) or [book](https://spoki.io/book) for **webhook** and **template** design, and the [ROI calculator](https://spoki.io/roi-calculator) to plan volume."},{"heading":"Categories","level":3,"text":"- Blog-en"},{"heading":"Tags","level":3,"text":"- AI & Automation\n- API\n- GDPR & Privacy\n- Lead Generation\n- WhatsApp API\n\n---"},{"heading":"About Spoki","level":2,"text":"Use Spoki's simple, fast and intuitive platform to drive conversions, automate tasks and grow your business."},{"heading":"Solutions","level":3,"text":"- Marketing\n- Sales\n- Customer Care\n- Developers"},{"heading":"Special Programs","level":3,"text":"- Agencies\n- Affiliation\n- Reseller\n- Start up"},{"heading":"Quick Links","level":3,"text":"- [Features](https://spoki.com/en/features)\n- [Pricing](https://spoki.com/en/pricing)\n- [About](https://spoki.com/en/about)\n- [FAQ](https://spoki.com/en/faq)\n- [Blog](https://spoki.com/en/blog)\n- [Case Studies](https://spoki.com/en/case-studies)\n- [Integrations](https://spoki.com/en/integrations)\n\n© 2026 Spoki. All rights reserved."}]}}