AI agents & automation

WhatsApp Business API Integration, Step by Step

A practical walkthrough of integrating the WhatsApp Business Platform into your product: account setup, templates, webhooks, the 24-hour window and how to store conversations.

By Devang GandhiUpdated Nov 3, 20267 min read

A WhatsApp Business API integration is one of the highest-return features you can add to a sales or service product, especially for customers in India, the UAE and much of the world where WhatsApp is the default inbox. It is also easy to get wrong: templates get rejected, webhooks drop messages, and conversations end up scattered.

I have built WhatsApp automation for Antoc, a real-estate CRM used by 100+ firms, including a visual flow builder with triggers and nurture drips. Here is the step-by-step path I follow, in the order that avoids rework.

TL;DR

Get Meta business verification and a phone number on the Cloud API first. Design your message templates and opt-in capture before coding. Build a fast, idempotent webhook for inbound messages and status updates, store everything keyed by WhatsApp message ID, and respect the 24-hour service window. Automation and AI come after the plumbing is reliable.

key takeaways

  • A WhatsApp Business API integration has two halves: sending through the Cloud API and receiving through a verified webhook.
  • The 24-hour customer service window decides whether you can send free-form text or must use an approved template.
  • Store every message with its WhatsApp message ID and status so delivery, read receipts and retries are traceable.
  • Design templates and opt-in capture before you write code, because approval and consent shape everything downstream.

Step 1: Accounts, numbers and tokens

Everything starts in Meta's business tooling. The WhatsApp Cloud API documentation covers the details, but the checklist looks like this:

  1. Create or use a Meta Business portfolio and complete business verification.
  2. Create an app and add the WhatsApp product.
  3. Register a phone number that is not active on the consumer WhatsApp app.
  4. Create a system user and generate a permanent access token with WhatsApp permissions.
  5. Note the phone number ID and WhatsApp Business Account ID; you will use both constantly.

If your product is multi-tenant, decide now whether each customer brings their own number (embedded signup) or whether you send from a shared one. For a CRM, customers almost always want their own number and their own brand name in the chat.

Step 2: Templates and the 24-hour window

WhatsApp separates conversations into two modes. When a customer messages you, a 24-hour customer service window opens and you can reply with free-form messages. Outside that window, the business can only start a conversation with a pre-approved template.

Situation What you can send Notes
Customer messaged within 24h Free text, media, interactive buttons Window resets on each inbound message
No recent inbound message Approved template only Utility, marketing or authentication category
Login or OTP Authentication template Strict format rules
Promotional follow-up Marketing template Requires opt-in, priced higher

Plan templates around real moments: new enquiry acknowledgement, site visit reminder, follow-up after a missed call. Use variables ({{1}}, {{2}}) for names and dates, keep wording specific, and avoid anything that reads like spam. Rejections usually come from vague content or a mismatched category.

Step 3: The webhook

Inbound messages, delivery statuses and read receipts arrive at a webhook you register with Meta. This is the part most worth engineering carefully.

Verification and security

Meta first sends a GET request with a hub.challenge that you echo back when the verify token matches. After that, every POST includes a signature header computed with your app secret. Verify it on every request before trusting the payload.

Handler design

  • Acknowledge fast. Return 200 immediately and push the payload onto a queue or background job.
  • Be idempotent. Use the WhatsApp message ID (wamid) as a unique key. Retries and duplicate deliveries happen.
  • Separate messages from statuses. A status update (sent, delivered, read, failed) should update an existing outbound record, not create a new one.
  • Handle every type. Text, image, document, audio, location, button replies and list replies all arrive with different shapes.

Step 4: Data model

A clean schema saves you months later. The minimum I use:

  • conversations: business ID, contact phone, linked lead ID, last inbound timestamp (for the 24h window), assigned user.
  • messages: conversation ID, direction, wamid, type, body or media reference, template name if any, status, timestamps per status, error code if failed.
  • templates: name, language, category, approval status, variable mapping.

Link conversations to leads by normalized phone number in E.164 format. In a CRM with duplicate detection, this is where WhatsApp contacts merge with leads that came from ads or portals instead of creating duplicates.

How I built this in practice

In Antoc, WhatsApp sits next to lead capture from Meta lead ads, Google Ads, property portals, Google Sheets, webhooks and public forms. When a new lead arrives, duplicate detection and auto-assignment rules run first, and then WhatsApp automation can fire.

The automation runs on a visual flow builder. Flows start from triggers such as an incoming message, a new lead, a reminder or a pipeline stage change. A typical real-estate nurture flow sends an acknowledgement on Day 0, a follow-up with project details on Day 2 and a check-in on Day 7, each as an approved template because the customer may not have replied. There is also an AI agent node that can answer free-form questions inside the service window.

The backend is Node/Express with MongoDB, with Socket.IO pushing new messages to the agent inbox in real time. Because the flows depend on reliable inbound events, the webhook handler is the most defended piece of the system. Read more in the Antoc case study.

Common mistakes

  • Writing code before templates are approved, then discovering the flow needs a template category you do not have.
  • Processing webhooks synchronously, so slow database writes cause timeouts and retries.
  • Not deduplicating by wamid, which creates double replies and duplicate leads.
  • Ignoring the 24-hour window and getting send failures for free-form messages.
  • Storing phone numbers in mixed formats, which breaks matching between WhatsApp contacts and CRM leads.
  • Sending marketing templates without recorded opt-in, which damages the number's quality rating.

keep reading

FAQ

How long does a WhatsApp Business API integration take?+

A basic send-and-receive integration with templates and a webhook can be done in one to two weeks once Meta business verification is in place. A full inbox with assignment, automation flows and analytics usually takes four to eight weeks.

Do I need a Business Solution Provider to use the WhatsApp API?+

No. Meta's Cloud API lets you integrate directly using a Meta business account and a system user token. A provider can help with onboarding and support, but many teams integrate directly to avoid an extra layer and markup.

Can I send marketing messages to anyone on WhatsApp?+

No. You need the user's opt-in and an approved marketing template for business-initiated messages. Sending without consent risks quality rating drops, messaging limits and account restrictions.

What happens if my webhook goes down?+

Meta retries failed webhook deliveries for a period, but you should acknowledge fast, queue processing, and make handlers idempotent using the message ID. That way retries and duplicates never create duplicate leads or replies.

Devang Gandhi

AI & full stack developer at Passdn, building CRMs, SaaS, AI agents and Flutter apps for clients in the US, UK, Australia, UAE and India. More about me

Read next

More in AI agents & automation