How to Build a WhatsApp Chatbot: Best Practice and Step-by-Step Guide
Content

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, pricing, support, book, and the ROI calculator.
Step 1: Understand WhatsApp Business API Rules
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 and 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 and the 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.
Step 2: Collect and Store Opt-In
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 and 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 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.
Step 3: Design Templates That Start Conversations
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 and 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 and the 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, support.
Step 4: Set Up Your Webhook and Chatbot Logic
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 and 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 and 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 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, support, and pricing to design your webhook and chatbot flow.
Step 5: Test and Go Live
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.
- 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 and 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, ROI calculator.
Conclusion
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 for the WhatsApp Business API, registration, and pricing. Use support or book for webhook and template design, and the ROI calculator to plan volume.

