<?xml version="1.0" encoding="UTF-8"?>
<page lang="en" url="https://spoki.com/en/blog/how-to-build-whatsapp-chatbot-step-by-step">
  <meta>
    <title>How to Build a WhatsApp Chatbot: Best Practice and Step-by-Step Guide</title>
    <page>blog/how-to-build-whatsapp-chatbot-step-by-step</page>
    <language>en</language>
    <generated_at>2026-04-18T23:38:53.286Z</generated_at>
    <formats>
      <html>https://spoki.com/en/blog/how-to-build-whatsapp-chatbot-step-by-step</html>
      <markdown>https://spoki.com/en/blog/how-to-build-whatsapp-chatbot-step-by-step.md</markdown>
      <json>https://spoki.com/en/blog/how-to-build-whatsapp-chatbot-step-by-step.json</json>
      <xml>https://spoki.com/en/blog/how-to-build-whatsapp-chatbot-step-by-step.xml</xml>
    </formats>
  </meta>
  <sections>
    <section level="1" heading="How to Build a WhatsApp Chatbot: Best Practice and Step-by-Step Guide">
      <text><![CDATA[**Author:** Spoki | **Published:** 2/12/2026

*Build a WhatsApp chatbot with the WhatsApp Business API and Spoki. Step-by-step: templates, session, opt-in, webhook, and automation.*

---

Building 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**.

This 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).]]></text>
    </section>
    <section level="2" heading="Step 1: Understand WhatsApp Business API Rules">
      <text><![CDATA[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:

- **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).

- **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).

**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.]]></text>
    </section>
    <section level="2" heading="Step 2: Collect and Store Opt-In">
      <text><![CDATA[**WhatsApp** requires that users have agreed to receive messages before you send them. **Step-by-step** for **opt-in**:

- **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).

- **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.

**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.]]></text>
    </section>
    <section level="2" heading="Step 3: Design Templates That Start Conversations">
      <text><![CDATA[**Templates** are the only way to initiate (or re-open after **24h**). **Step-by-step**:

- **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).

- **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).

- **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).]]></text>
    </section>
    <section level="2" heading="Step 4: Set Up Your Webhook and Chatbot Logic">
      <text><![CDATA[**Spoki** sends **inbound** **WhatsApp** messages to a **webhook** URL you configure. **Step-by-step**:

- **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).

- **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).

- **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.

**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**.

**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.]]></text>
    </section>
    <section level="2" heading="Step 5: Test and Go Live">
      <text><![CDATA[Before going live:

- **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).

- **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).

- **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).]]></text>
    </section>
    <section level="2" heading="Conclusion">
      <text><![CDATA[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.

Ready 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.]]></text>
    </section>
    <section level="3" heading="Categories">
      <text><![CDATA[- Blog-en]]></text>
    </section>
    <section level="3" heading="Tags">
      <text><![CDATA[- AI & Automation
- API
- GDPR & Privacy
- Lead Generation
- WhatsApp API

---]]></text>
    </section>
    <section level="2" heading="About Spoki">
      <text><![CDATA[Use Spoki's simple, fast and intuitive platform to drive conversions, automate tasks and grow your business.]]></text>
    </section>
    <section level="3" heading="Solutions">
      <text><![CDATA[- Marketing
- Sales
- Customer Care
- Developers]]></text>
    </section>
    <section level="3" heading="Special Programs">
      <text><![CDATA[- Agencies
- Affiliation
- Reseller
- Start up]]></text>
    </section>
    <section level="3" heading="Quick Links">
      <text><![CDATA[- [Features](https://spoki.com/en/features)
- [Pricing](https://spoki.com/en/pricing)
- [About](https://spoki.com/en/about)
- [FAQ](https://spoki.com/en/faq)
- [Blog](https://spoki.com/en/blog)
- [Case Studies](https://spoki.com/en/case-studies)
- [Integrations](https://spoki.com/en/integrations)

© 2026 Spoki. All rights reserved.]]></text>
    </section>
  </sections>
</page>