How to Build a WhatsApp Bot for Your Business: Complete Guide 2026
WhatsApp has 2 billion+ active users. It's the dominant messaging platform in Central Asia, South Asia, Latin America, and much of Europe and Africa. If your customers are on WhatsApp — and they almost certainly are — automating it is one of the highest-ROI technical investments you can make.
This guide covers everything: how WhatsApp Business API works, how to set it up, and how to build a bot with Node.js.
WhatsApp Business API vs WhatsApp Business App
Before writing a single line of code, understand the difference:
| Feature | WhatsApp Business App | WhatsApp Business API |
|---|---|---|
| Automation | None (manual replies) | Full automation possible |
| Multiple agents | No | Yes |
| CRM integration | No | Yes |
| Message templates | No | Yes |
| Scale | Small business (1 phone, 1 person) | Enterprise |
| Cost | Free | Pay-per-message |
| How to get it | Download from app store | Through a BSP partner |
For any real automation, you need the WhatsApp Business API (WABA).
Step 1: Get WhatsApp Business API Access
You can't access WABA directly from Meta — you must go through a Business Solution Provider (BSP). Popular BSPs:
- 360dialog — good pricing, strong API, popular in Europe/CIS
- Twilio — familiar to developers, reliable
- Wati — no-code friendly, good for small teams
- Infobip — enterprise-grade, global
- Cloud API (Meta direct) — Meta now offers direct access via Meta Business Suite
The easiest path in 2026: Meta's Cloud API through the Meta for Developers portal. No BSP middleman, pay directly to Meta.
Meta Cloud API Setup:
- Go to developers.facebook.com → Create App → Business
- Add the WhatsApp product to your app
- Go to WhatsApp → Getting Started
- You get a test phone number to send up to 5 test messages
- For production: add a real business phone number (can't be registered with any other WhatsApp)
- Verify your Meta Business account (submit business documents)
- Get your Phone Number ID, WhatsApp Business Account ID, and Access Token
Step 2: Set Up Your Webhook
WhatsApp sends events to your webhook when messages arrive.
// Express.js webhook handler
import express from 'express';
const app = express();
app.use(express.json());
const VERIFY_TOKEN = process.env.WHATSAPP_VERIFY_TOKEN; // your random string
// Webhook verification (GET)
app.get('/webhooks/whatsapp', (req, res) => {
const mode = req.query['hub.mode'];
const token = req.query['hub.verify_token'];
const challenge = req.query['hub.challenge'];
if (mode === 'subscribe' && token === VERIFY_TOKEN) {
console.log('Webhook verified');
return res.status(200).send(challenge);
}
res.sendStatus(403);
});
// Incoming messages (POST)
app.post('/webhooks/whatsapp', (req, res) => {
const body = req.body;
if (body.object !== 'whatsapp_business_account') {
return res.sendStatus(404);
}
const entry = body.entry?.[0];
const changes = entry?.changes?.[0];
const value = changes?.value;
if (value?.messages) {
for (const message of value.messages) {
handleIncomingMessage(message, value.metadata.phone_number_id);
}
}
// Always return 200 quickly — WhatsApp will retry if you don't
res.sendStatus(200);
});
Register this webhook URL in Meta Developer Portal → WhatsApp → Configuration.
Step 3: Send Messages
const WHATSAPP_TOKEN = process.env.WHATSAPP_ACCESS_TOKEN;
const PHONE_NUMBER_ID = process.env.WHATSAPP_PHONE_NUMBER_ID;
const WHATSAPP_API_URL = `https://graph.facebook.com/v20.0/${PHONE_NUMBER_ID}/messages`;
async function sendTextMessage(to, text) {
const response = await fetch(WHATSAPP_API_URL, {
method: 'POST',
headers: {
'Authorization': `Bearer ${WHATSAPP_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
messaging_product: 'whatsapp',
to,
type: 'text',
text: { body: text },
}),
});
return response.json();
}
async function sendInteractiveButtons(to, bodyText, buttons) {
// buttons = [{ id: 'btn_1', title: 'Yes' }, { id: 'btn_2', title: 'No' }]
const response = await fetch(WHATSAPP_API_URL, {
method: 'POST',
headers: {
'Authorization': `Bearer ${WHATSAPP_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
messaging_product: 'whatsapp',
to,
type: 'interactive',
interactive: {
type: 'button',
body: { text: bodyText },
action: {
buttons: buttons.map(btn => ({
type: 'reply',
reply: { id: btn.id, title: btn.title },
})),
},
},
}),
});
return response.json();
}
Step 4: Handle Incoming Messages
async function handleIncomingMessage(message, phoneNumberId) {
const from = message.from; // customer's phone number
const type = message.type; // 'text' | 'interactive' | 'image' | 'audio' etc.
if (type === 'text') {
const text = message.text.body.trim().toLowerCase();
await handleTextMessage(from, text, phoneNumberId);
}
if (type === 'interactive') {
const buttonId = message.interactive?.button_reply?.id;
await handleButtonReply(from, buttonId, phoneNumberId);
}
}
async function handleTextMessage(to, text, phoneNumberId) {
// Simple state machine
if (text.includes('hello') || text.includes('hi') || text.includes('start')) {
await sendInteractiveButtons(
to,
"Hi! I'm the Aunimeda assistant. How can I help you today?",
[
{ id: 'services', title: 'Our Services' },
{ id: 'pricing', title: 'Get a Quote' },
{ id: 'contact', title: 'Talk to a Human' },
]
);
return;
}
if (text.includes('price') || text.includes('cost') || text.includes('how much')) {
await sendTextMessage(
to,
"Our pricing depends on the project scope. Tell me what you need:\n\n" +
"• Mobile app\n• Web application\n• Telegram/WhatsApp bot\n• AI automation\n\n" +
"Or type *contact* to speak with our team directly."
);
return;
}
// Fallback
await sendTextMessage(
to,
"I didn't quite get that. Type *hello* to see the main menu, or *contact* to reach our team."
);
}
async function handleButtonReply(to, buttonId, phoneNumberId) {
switch (buttonId) {
case 'services':
await sendTextMessage(to,
"We build:\n\n" +
"📱 Mobile apps (iOS & Android)\n" +
"🌐 Web apps & websites\n" +
"🤖 Telegram & WhatsApp bots\n" +
"🧠 AI automation systems\n" +
"🛒 E-commerce platforms\n\n" +
"What are you looking to build?"
);
break;
case 'pricing':
await sendTextMessage(to,
"To give you an accurate quote, we need to understand your project.\n\n" +
"Please describe what you want to build in a few sentences, and we'll get back to you within 2 hours."
);
break;
case 'contact':
await sendTextMessage(to,
"Our team is available Mon–Fri 9:00–18:00 (Bishkek time).\n\n" +
"You can also reach us at:\n" +
"📧 hello@aunimeda.com\n" +
"🌐 aunimeda.com/contact\n\n" +
"Leave your message here and we'll respond as soon as we're back online."
);
break;
}
}
Step 5: Message Templates (for Outbound Notifications)
To message a customer first (not reply to them), you must use a pre-approved template:
async function sendOrderStatusNotification(to, orderId, status) {
// Template must be pre-approved in Meta Business Manager
const response = await fetch(WHATSAPP_API_URL, {
method: 'POST',
headers: {
'Authorization': `Bearer ${WHATSAPP_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
messaging_product: 'whatsapp',
to,
type: 'template',
template: {
name: 'order_status_update', // your approved template name
language: { code: 'en' },
components: [
{
type: 'body',
parameters: [
{ type: 'text', text: orderId },
{ type: 'text', text: status },
],
},
],
},
}),
});
return response.json();
}
Template approval takes 1–3 days in Meta Business Manager.
Production Checklist
- Webhook URL is HTTPS (required by Meta)
- Webhook verification token stored in env variable (not hardcoded)
- Access token stored securely (env var, secrets manager)
- Webhook responds with 200 within 5 seconds (process async)
- Message deduplication: WhatsApp may send duplicate webhook events
- Rate limiting: WhatsApp has per-number limits (~80 messages/sec)
- Error handling + logging for failed sends
- Template messages pre-approved before launch
WhatsApp vs Telegram: Which Should You Build First?
If you're choosing between the two for a global product:
- WhatsApp if your audience is in SE Asia, South Asia, Latin America, Africa, Middle East, or CIS countries
- Telegram if you need rich UI (inline keyboards, games, payments), channels, or a developer-savvy audience
For most B2C businesses, both with a shared backend is the right answer.
Need help building a WhatsApp bot for your business? →
Aunimeda builds WhatsApp bots, Telegram bots, mobile apps, and AI automation systems for businesses worldwide.
See also: How to Build a Telegram Bot for Business, How to Build a Taxi App, DevOps for Startups: What You Actually Need