Back to BlogTutorials

WhatsApp Bot API Guide: Build a WhatsApp Bot in 2026

WALYTIC TEAMNOVEMBER 15, 20267 MIN READ

What Is a WhatsApp Bot API?

A WhatsApp bot API lets your application send and receive WhatsApp messages programmatically. When a customer sends a message, your server receives it via a webhook. Your code then processes the message and calls the REST API to send a reply.

This is different from manually typing responses in WhatsApp. With the bot API, you can:

  • Respond instantly to common questions, 24/7
  • Route conversations to the right team member or AI agent
  • Collect customer information through guided flows
  • Trigger actions in your backend — CRM updates, order lookups, ticket creation

The result: a WhatsApp number that feels like a live support agent but runs entirely on code.


How the WhatsApp Bot API Works

Every WhatsApp bot has two moving parts:

ComponentDirectionWhat It Does
WebhookInboundReceives messages from customers
REST APIOutboundSends replies back to customers

Inbound flow: Customer sends a message → the platform delivers it to your webhook URL as a JSON payload → your code parses it and decides how to respond.

Outbound flow: Your server calls the REST API with the recipient's phone number and message content → the message is delivered via WhatsApp.

This request/response loop is the foundation of every WhatsApp bot, from simple FAQ bots to complex AI agents with live-agent handoff.


Prerequisites

Before writing any code, you need:

  1. A WhatsApp number — either your existing business number connected by scanning a QR code, or a number registered through the Meta WhatsApp Cloud API
  2. A Walytic account — this provides the REST API endpoints, webhook relay, and inbox dashboard (start a 14-day free trial)
  3. A publicly accessible server — your webhook URL must be reachable from the internet (use ngrok for local testing)
  4. Any HTTP-capable language — the API is language-agnostic; examples below use Node.js

Step 1: Connect Your WhatsApp Number

Log in to Walytic and go to Settings → WhatsApp Connection. You have two options:

Option A: QR Code (fastest)

Scan the QR code with your existing WhatsApp or WhatsApp Business app. Your number is linked in under 60 seconds. Good for getting started immediately without any approval process.

Option B: Meta WhatsApp Cloud API

Register a dedicated business number through Meta's official Business Manager. This option gives you a verified green tick, higher messaging limits, and full Meta compliance. It takes 1–3 business days to provision.

Both options use the same Walytic API endpoints — the connection method is transparent to your bot code.


Step 2: Set Up Your Webhook

In the Walytic dashboard, go to Settings → Webhooks and register your endpoint URL. Walytic will POST a JSON payload to this URL whenever a message arrives.

Here's a minimal Node.js webhook handler using Express:

JAVASCRIPT
const express = require('express');
const app = express();
app.use(express.json());

app.post('/webhook/whatsapp', async (req, res) => {
  res.sendStatus(200); // Acknowledge before processing

  const { event, data } = req.body;

  if (event === 'message.received' && data.type === 'text') {
    const from = data.from;
    const text = data.text.body;

    console.log(`Message from ${from}: ${text}`);
    await sendReply(from, buildReply(text));
  }
});

app.listen(3000);

Always return a 200 response immediately before processing the message. If your handler times out, Walytic will retry the webhook delivery, which can cause duplicate replies.


Step 3: Send Automated Replies

To send a message, make a POST request to the Walytic REST API:

JAVASCRIPT
const WALYTIC_API_KEY = process.env.WALYTIC_API_KEY;

async function sendReply(to, message) {
  await fetch('https://api.walytic.com/v1/messages', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${WALYTIC_API_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      to,
      type: 'text',
      text: { body: message },
    }),
  });
}

function buildReply(incomingText) {
  const lower = incomingText.toLowerCase();

  if (lower.includes('price') || lower.includes('cost')) {
    return 'Our plans start at $48/year. See full pricing at https://walytic.com/pricing';
  }
  if (lower.includes('hours') || lower.includes('open')) {
    return 'We are open Monday to Friday, 9am-6pm EST. How else can I help?';
  }
  return 'Thanks for your message! A team member will reply shortly.';
}

This keyword-matching bot handles the most common questions automatically. For anything it doesn't recognize, it falls back to a handoff message telling the customer a human will follow up.


Step 4: Add AI Replies and Human Handoff

Keyword matching breaks down quickly as contact volume grows. The next step is adding an AI agent.

Walytic includes a built-in AI agent layer you can configure in the dashboard — no additional code required:

  1. Go to AI Agent → Settings
  2. Connect your knowledge base (FAQ documents, product pages, or plain text)
  3. Set a confidence threshold — messages below this score trigger a human handoff
  4. Assign escalated conversations to a specific inbox or agent

When the AI isn't confident enough to reply, it escalates the conversation to your team's shared inbox. The agent sees the full conversation history and can take over instantly. Once the issue is resolved, the AI resumes handling new messages automatically.

This human-in-the-loop design is what separates a genuinely useful business bot from an endless loop of "I didn't understand that."


Common WhatsApp Bot Use Cases

Use CaseTriggerAutomated Action
FAQ handlingCustomer questionAI agent replies from knowledge base
Order status"Where is my order?"Look up order ID, reply with status
Appointment booking"Book a session"Send calendar link or collect time preference
Payment remindersScheduled triggerRemind opted-in contacts of outstanding invoices
Support triageNew inbound messageClassify intent, route to right team queue
Post-purchase follow-upShopify order fulfilledSend satisfaction survey 24h after delivery

Walytic's Shopify integration triggers on order created, paid, fulfilled, or cancelled events — so your e-commerce bot reacts to real order activity without any polling.


What to Avoid

A few patterns that cause bot failures or account issues:

  • Slow webhook responses — always return 200 before processing; push long-running tasks to a background queue
  • Messaging contacts who haven't opted in — only message customers who gave explicit consent; see the WhatsApp compliance guide
  • No escalation path — always include a way for customers to reach a human; bots that loop infinitely damage trust and can get your number flagged

Next Steps

You now have everything needed to build a WhatsApp bot with the API:

  1. Start a 14-day free trial and connect your WhatsApp number
  2. Register your webhook URL in the Walytic dashboard
  3. Deploy the handler above and test with a real message
  4. Expand to AI replies and human handoff when volume grows

For all available message types, delivery receipts, media attachments, and contact management endpoints, see the API reference.

Ready to Automate WhatsApp?

Start sending bulk messages, automate follow-ups, and build chatbots, all with flat-rate pricing. No per-message fees.