Skip to main content
RapidDev - Software Development Agency
openclaw-integrationsDirect API Integration

How to Connect WhatsApp Business to OpenClaw

To connect WhatsApp Business to OpenClaw, either set up the official WhatsApp Business Cloud API (requires Meta Business verification) or use the Baileys library for a session-based connection. Configure your credentials in OpenClaw's config — either a WHATSAPP_CLOUD_API_TOKEN with phone number ID, or Baileys session data. OpenClaw then sends and receives WhatsApp messages programmatically. The Cloud API is recommended for production use; Baileys is faster to set up for personal or testing workflows.

What you'll learn

  • How to set up WhatsApp Business Cloud API credentials in Meta Business Suite
  • How to configure WHATSAPP_CLOUD_API_TOKEN and phone number ID in OpenClaw
  • How to send template messages and free-form messages through the WhatsApp API
  • How to receive incoming WhatsApp messages via webhook configuration
  • How to troubleshoot WhatsApp message template approval and delivery errors
Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Intermediate15 min read30 minutesMessagingMarch 2026RapidDev Engineering Team
TL;DR

To connect WhatsApp Business to OpenClaw, either set up the official WhatsApp Business Cloud API (requires Meta Business verification) or use the Baileys library for a session-based connection. Configure your credentials in OpenClaw's config — either a WHATSAPP_CLOUD_API_TOKEN with phone number ID, or Baileys session data. OpenClaw then sends and receives WhatsApp messages programmatically. The Cloud API is recommended for production use; Baileys is faster to set up for personal or testing workflows.

Why Connect WhatsApp Business to OpenClaw?

WhatsApp is the world's most-used messaging platform in many markets — with over 2 billion active users and dominant market share across Europe, Latin America, India, the Middle East, and Africa. For businesses and automation workflows targeting these regions, WhatsApp is not optional — it is where your customers and contacts are. Connecting WhatsApp to OpenClaw lets your AI agent send notifications, respond to customer inquiries, and automate conversation flows across WhatsApp without manual message handling.

There are two technically distinct approaches to WhatsApp integration. The official Meta Cloud API is WhatsApp's sanctioned business platform — it requires Meta Business verification (a process taking 1-7 days) but provides a stable, reliable API with no risk of account termination. The Baileys library uses WhatsApp Web's protocol to create a QR-code-scanned session, which works immediately without verification but carries the risk of account termination if WhatsApp detects automation (Meta does not support third-party clients). The right choice depends on your use case and timeline.

A key constraint of the official Cloud API: you can only send free-form messages within 24 hours of a customer initiating contact. Outside that window, you must use pre-approved message templates. This restriction does not apply to Baileys. For customer-initiated support conversations, the Cloud API is ideal. For outbound notifications and broadcasts, you need approved templates — or Baileys for personal/testing use.

Integration method

Direct API Integration

WhatsApp Business integration in OpenClaw supports two approaches: the official Meta Cloud API (requires a verified Meta Business account, uses a permanent access token and phone number ID) and the Baileys library (a Node.js library that creates a session-based connection using WhatsApp Web's protocol, no business verification required). The Cloud API is more reliable and suitable for production; Baileys is faster to set up for personal automation and testing. Both approaches use direct HTTP API calls from OpenClaw to send messages.

Prerequisites

  • For Cloud API: a Meta Business account (business.facebook.com) and a WhatsApp Business phone number registered with Meta
  • For Baileys: a WhatsApp-registered phone number (personal or business) and OpenClaw running in an environment with Node.js available
  • A public HTTPS URL for webhook delivery (Cloud API requires this for receiving messages)
  • OpenClaw installed and running on your machine
  • Basic familiarity with REST APIs and webhook configuration

Step-by-step guide

1

Option A: Set Up WhatsApp Cloud API Credentials

This is the official Meta approach. Go to developers.facebook.com, create a Meta App (select 'Business' type), and add the 'WhatsApp' product to your app. Meta will walk you through connecting a WhatsApp Business Account. In the WhatsApp app setup, Meta provides a temporary access token and a test phone number ID for immediate testing (no business verification required for testing). For production, you add a real business phone number — this requires Meta Business verification. Your credentials from the Meta developer console: 1. **Phone Number ID** — found in WhatsApp > Getting Started. Looks like `123456789012345`. 2. **Access Token** — for testing, use the temporary token in Getting Started. For production, generate a permanent System User token: Business Settings > System Users > Add System User > Generate New Token > select your WhatsApp app > whatsapp_business_messaging permission. 3. **WhatsApp Business Account ID (WABA ID)** — also on the Getting Started page. For webhook setup (required to receive messages): go to your app's WhatsApp > Configuration > Webhook. Enter your public HTTPS URL and a verification token (any string you choose). Meta will send a verification GET request to confirm the endpoint is accessible — OpenClaw must be running and the webhook path must be configured before completing this step.

terminal
1# Test Cloud API credentials:
2curl -X GET "https://graph.facebook.com/v18.0/YOUR_PHONE_NUMBER_ID" \
3 -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
4
5# Expected response:
6# {"id": "123456789012345", "display_phone_number": "+1 555-0100", "verified_name": "OpenClaw Bot"}
7
8# Send a test message to a WhatsApp number:
9curl -X POST "https://graph.facebook.com/v18.0/YOUR_PHONE_NUMBER_ID/messages" \
10 -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
11 -H "Content-Type: application/json" \
12 -d '{
13 "messaging_product": "whatsapp",
14 "to": "+15550001234",
15 "type": "text",
16 "text": {"body": "Test message from OpenClaw via WhatsApp Cloud API"}
17 }'

Pro tip: Meta's test phone number (provided in the Getting Started page) can only send messages to numbers you explicitly add as test recipients. Add your own phone number as a test recipient in the WhatsApp Getting Started page before testing — messages to unregistered test recipients fail silently.

Expected result: The getPhoneNumber API call returns your phone number info, and the test message arrives on your WhatsApp as a message from your business number.

2

Option B: Set Up Baileys Session (Faster, Personal Use)

Baileys is an open-source Node.js library that connects to WhatsApp using the WhatsApp Web protocol. It requires a QR code scan to authenticate a WhatsApp account session. This is faster to set up than the Cloud API and works with any WhatsApp account (personal or business), but it is not officially supported by Meta and carries account risk if used for high-volume automation. To use Baileys with OpenClaw, you run a small session initialization script that generates a QR code. Scan the QR with your phone (WhatsApp > Linked Devices > Link a Device). Baileys saves session credentials to disk so you only scan once — the session persists across restarts. After scanning, Baileys provides OpenClaw with a running WhatsApp connection object. OpenClaw writes messages through this connection and receives incoming messages as events. Note: WhatsApp has a policy against third-party clients. Personal automation with Baileys at low volume (personal productivity bots, testing) is low risk. High-volume business use with Baileys risks account termination — use the Cloud API for production customer communications.

init-whatsapp-baileys.js
1# Baileys session initialization (run once to generate QR and save credentials):
2# ~/.openclaw/scripts/init-whatsapp-baileys.js
3const { default: makeWASocket, useMultiFileAuthState } = require('@whiskeysockets/baileys')
4
5async function initSession() {
6 const { state, saveCreds } = await useMultiFileAuthState('./whatsapp-session')
7 const sock = makeWASocket({ auth: state })
8
9 sock.ev.on('creds.update', saveCreds)
10 sock.ev.on('connection.update', (update) => {
11 const { connection, lastDisconnect, qr } = update
12 if (qr) {
13 console.log('Scan this QR code with WhatsApp:')
14 require('qrcode-terminal').generate(qr, { small: true })
15 }
16 if (connection === 'open') {
17 console.log('WhatsApp connected successfully!')
18 process.exit(0)
19 }
20 })
21}
22initSession()
23
24# Run with:
25# node ~/.openclaw/scripts/init-whatsapp-baileys.js

Pro tip: Store the Baileys session files in `~/.openclaw/whatsapp-session/` and back them up. If the session files are deleted, you need to scan the QR code again. Session files contain authentication credentials — keep them out of version control.

Expected result: The QR code appears in terminal, you scan it with your phone, and 'WhatsApp connected successfully!' is printed. Session files are saved for persistent reconnection.

3

Configure WhatsApp Credentials in OpenClaw

Open `~/.openclaw/config.yaml` and add the WhatsApp integration block under `integrations`. The configuration differs based on whether you are using the Cloud API or Baileys. For Cloud API: add `phone_number_id`, `access_token`, and `waba_id` from your Meta developer console. The `webhook_verify_token` must match the token you entered in Meta's webhook configuration step. For Baileys: point OpenClaw to the session directory you created during initialization. OpenClaw loads the session from the saved credentials files and maintains the connection. After saving the config, run `clawhub reload`. For Cloud API, OpenClaw will verify the credentials by calling the phone number info endpoint. For Baileys, OpenClaw loads the session and reconnects to WhatsApp Web.

~/.openclaw/config.yaml
1# ~/.openclaw/config.yaml Cloud API configuration
2integrations:
3 whatsapp_business:
4 mode: cloud_api
5 phone_number_id: "123456789012345"
6 access_token: "EAAxxxxxxxxxxxxxxx"
7 waba_id: "987654321098765"
8 webhook_verify_token: "my-webhook-secret-token"
9 webhook_path: /whatsapp/webhook
10 default_messaging_product: whatsapp
11
12# OR: Baileys configuration
13# integrations:
14# whatsapp_business:
15# mode: baileys
16# session_path: ~/.openclaw/whatsapp-session
17# auto_reconnect: true
18# reconnect_interval: 5000 # ms between reconnect attempts

Pro tip: For Cloud API production deployments, use a permanent System User token rather than the temporary testing token. Temporary tokens expire and will break your integration — generate a System User token in Meta Business Settings and set it to never expire.

Expected result: `clawhub reload` shows the WhatsApp integration connected with your phone number confirmed for Cloud API, or Baileys session loaded and WhatsApp Web connection active.

4

Send Messages and Configure Message Templates

The Cloud API distinguishes between two message types with different rules: **Session messages** (free-form text, within 24-hour window): can only be sent in response to a customer-initiated message within the past 24 hours. This is the natural back-and-forth support conversation model. **Template messages** (outside 24-hour window or proactive outreach): must use a pre-approved message template. Templates are approved by Meta and contain fixed text with optional variable placeholders. Submit templates in Meta Business Suite > WhatsApp > Message Templates. For session messages, send any text within the 24-hour window. For template messages, reference the template name and fill in variables. For Baileys, there are no template restrictions — any message can be sent at any time to any contact who has your number saved (or has previously messaged you). RapidDev recommends building your template library early (3-5 key templates: order confirmation, appointment reminder, support acknowledgment, general notification) since template approval takes 24-48 hours and you cannot send outside session windows until templates are approved.

terminal
1# Send a session message (within 24-hour conversation window):
2curl -X POST "https://graph.facebook.com/v18.0/YOUR_PHONE_NUMBER_ID/messages" \
3 -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
4 -H "Content-Type: application/json" \
5 -d '{
6 "messaging_product": "whatsapp",
7 "to": "+15550001234",
8 "type": "text",
9 "text": {"body": "Thanks for reaching out! How can we help you today?"}
10 }'
11
12# Send a template message (proactive or outside 24-hour window):
13curl -X POST "https://graph.facebook.com/v18.0/YOUR_PHONE_NUMBER_ID/messages" \
14 -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
15 -H "Content-Type: application/json" \
16 -d '{
17 "messaging_product": "whatsapp",
18 "to": "+15550001234",
19 "type": "template",
20 "template": {
21 "name": "order_confirmation",
22 "language": {"code": "en_US"},
23 "components": [{
24 "type": "body",
25 "parameters": [
26 {"type": "text", "text": "#ORD-12345"},
27 {"type": "text", "text": "3 items"},
28 {"type": "text", "text": "March 28, 2026"}
29 ]
30 }]
31 }
32 }'

Pro tip: Name templates clearly and consistently (snake_case, descriptive): `order_confirmation`, `appointment_reminder_24h`, `support_ticket_opened`. You cannot rename templates after submission — and Meta distinguishes between templates of the same name in different languages, so plan your naming convention before submitting.

Expected result: Session messages arrive in the target WhatsApp chat immediately. Template messages are delivered with the correct variable substitutions filled in from your API call.

5

Set Up Webhook for Incoming Messages

To receive incoming WhatsApp messages (not just send), configure a webhook endpoint. For the Cloud API, Meta delivers incoming messages by POSTing to your webhook URL. OpenClaw must be accessible at a public HTTPS URL for this to work. Verify the webhook setup: Meta first sends a GET request with `hub.mode=subscribe`, `hub.verify_token` (your configured token), and `hub.challenge`. Your endpoint must respond with the `hub.challenge` value. OpenClaw handles this automatically when `webhook_verify_token` is configured. After verification, Meta sends POST requests with message payloads for every incoming message. Each payload contains the sender's phone number, message type (text, image, audio, etc.), and message content. For Baileys, no webhook configuration is needed — messages arrive as events on the Baileys connection object that OpenClaw listens to directly. For local development without a public URL, use Cloudflare Tunnel or ngrok to expose your local OpenClaw instance temporarily during testing.

whatsapp-webhook.json
1# Incoming Cloud API webhook payload format:
2{
3 "object": "whatsapp_business_account",
4 "entry": [{
5 "id": "WABA_ID",
6 "changes": [{
7 "value": {
8 "messaging_product": "whatsapp",
9 "metadata": {"phone_number_id": "PHONE_ID"},
10 "messages": [{
11 "id": "wamid.xxx",
12 "from": "+15550001234",
13 "timestamp": "1709123456",
14 "type": "text",
15 "text": {"body": "Hello, I need help with my order"}
16 }]
17 }
18 }]
19 }]
20}
21
22# Subscribe to webhook events in Meta console, or via API:
23curl -X POST "https://graph.facebook.com/v18.0/YOUR_WABA_ID/subscribed_apps" \
24 -H "Authorization: Bearer YOUR_SYSTEM_USER_TOKEN" \
25 -H "Content-Type: application/json"

Pro tip: Always respond to Meta webhook POST requests with HTTP 200 within 20 seconds. If your endpoint returns a non-200 status or times out, Meta will retry the delivery several times before marking the webhook as unhealthy and potentially suspending webhook delivery to your endpoint.

Expected result: Incoming WhatsApp messages from customers appear in OpenClaw's event log and trigger configured workflows. The Meta developer console shows the webhook status as 'Active'.

Common use cases

Customer Support Automation

When customers message your WhatsApp Business number, OpenClaw receives the message via webhook, generates an AI-powered response, and replies within the 24-hour conversation window using the free-form messaging API. Handles FAQs, order status inquiries, and basic support triage without human intervention.

OpenClaw Prompt

Configure OpenClaw to receive incoming WhatsApp messages from my Cloud API phone number, classify them as support/sales/general, and reply with the appropriate template or AI-generated response

Copy this prompt to try it in OpenClaw

Transactional Notification Broadcasting

Send order confirmations, appointment reminders, shipping updates, and account alerts to customers via WhatsApp. Uses pre-approved message templates to reach customers who have not messaged in the past 24 hours. More effective than email for time-sensitive notifications in WhatsApp-dominant markets.

OpenClaw Prompt

Build an OpenClaw workflow that sends a WhatsApp order confirmation template to customers when a new order is placed, including order number, item count, and estimated delivery date

Copy this prompt to try it in OpenClaw

Personal Assistant Bot (Baileys)

Using Baileys for personal use, connect your personal WhatsApp account to OpenClaw as a private assistant. Send commands to yourself via WhatsApp to trigger OpenClaw workflows — set reminders, query Notion databases, get weather summaries, or control other connected integrations from your phone.

OpenClaw Prompt

Set up an OpenClaw Baileys bot that responds to commands sent to my WhatsApp number: /remind adds a reminder, /summary gets a daily summary, and /search performs a web search

Copy this prompt to try it in OpenClaw

Troubleshooting

Cloud API returns 'Message failed to send because more than 24 hours have passed since the customer last replied'

Cause: Attempting to send a free-form session message outside the 24-hour conversation window. WhatsApp enforces this restriction on the Cloud API to prevent unsolicited messages.

Solution: Use a pre-approved message template for proactive outreach or messages sent more than 24 hours after the customer's last message. Submit templates in Meta Business Suite and wait for approval (typically 24-48 hours). Check the error code in the API response for the specific error type.

typescript
1# Error response for expired window:
2# {"error": {"code": 131047, "title": "Re-engagement message", "message": "Message failed to send..."}}
3# Solution: use template message instead of text message

Baileys connection drops and does not reconnect automatically

Cause: WhatsApp Web sessions have a maximum multi-device session limit (typically 4 linked devices). If the limit is reached, older sessions are terminated. Also, network interruptions can close the WebSocket without triggering the reconnection logic.

Solution: Set `auto_reconnect: true` in your Baileys config. If the account has hit the linked device limit, unlink devices in WhatsApp (Settings > Linked Devices > unlink old sessions) and re-scan the QR code. Check that the session directory is not corrupted — if session files are incomplete, delete them and re-scan.

typescript
1# Check Baileys session health:
2ls -la ~/.openclaw/whatsapp-session/
3# Should contain creds.json and multiple key files
4# If empty or only partially populated, re-run the session init script

Message templates rejected by Meta with 'REJECTED' status

Cause: Template content violates Meta's WhatsApp Business Policy — common reasons include promotional language, missing opt-out language, overly vague placeholders, or template category mismatch (e.g., labeling a promotional template as 'UTILITY').

Solution: Review Meta's WhatsApp Business Policy for template requirements. Use the correct template category (AUTHENTICATION for OTPs, UTILITY for transactional messages, MARKETING for promotional content). Ensure utility templates do not contain promotional language. Add opt-out instructions for marketing templates.

Webhook verification fails — Meta shows 'Could not validate callback URL'

Cause: OpenClaw is not accessible at the webhook URL (not running, wrong port, or behind a firewall), or the `webhook_verify_token` in OpenClaw config does not match the verification token entered in Meta's developer console.

Solution: Verify OpenClaw is running and accessible at the webhook URL from an external network (test with curl from a different machine or use a public URL checker). Confirm the verification tokens match exactly (case-sensitive). Use Cloudflare Tunnel for a public HTTPS URL if testing locally.

typescript
1# Test webhook URL accessibility from external network:
2curl "https://your-openclaw-server.com/whatsapp/webhook?hub.mode=subscribe&hub.verify_token=YOUR_TOKEN&hub.challenge=test123"
3# Should return: test123 (the challenge value)

Best practices

  • Build a library of approved message templates before going live with the Cloud API — template approval takes 24-48 hours and you cannot send proactive messages without them. Prepare at least 3-5 core templates covering your main use cases.
  • Use the Cloud API for any production customer-facing WhatsApp automation and reserve Baileys for personal automation or development testing only — Baileys sessions are terminated by WhatsApp without warning at scale.
  • Store Cloud API access tokens (especially System User tokens) as environment variables in OpenClaw config (`${WHATSAPP_ACCESS_TOKEN}`) to keep credentials out of config files that might be committed to version control.
  • Always respond to incoming messages within the 24-hour window to avoid needing template messages for follow-ups — set up automated acknowledgment responses that reset the 24-hour session timer while your team prepares a full response.
  • Test template messages with your own registered test recipient number before submitting them for approval — verify variable placeholders fill in correctly and the message reads naturally before Meta reviews it.
  • Subscribe to Meta's webhook status events (not just message events) to receive delivery receipts, read receipts, and error notifications — this gives you visibility into whether messages are actually reaching recipients.
  • For Baileys deployments, implement exponential backoff in reconnection logic and monitor the connection state actively — silent disconnections that go undetected mean messages queue up without delivery until the next reconnect.

Alternatives

Frequently asked questions

How do I set up WhatsApp Business integration in OpenClaw?

For Cloud API: create a Meta App at developers.facebook.com, add the WhatsApp product, get your phone number ID and access token, and configure them under `integrations.whatsapp_business` in `~/.openclaw/config.yaml`. For Baileys: run the session initialization script, scan the QR code with WhatsApp on your phone, and point OpenClaw to the saved session directory. Run `clawhub reload` in both cases.

What is the difference between WhatsApp Cloud API and Baileys in OpenClaw?

The Cloud API is Meta's official WhatsApp Business platform — requires business verification but is stable, reliable, and policy-compliant for customer communications. It enforces a 24-hour conversation window and requires template approval for proactive messages. Baileys is an unofficial Node.js library that mimics WhatsApp Web — no verification needed, no template restrictions, but carries account termination risk if used at scale. Use Cloud API for production, Baileys for personal automation.

Why can't I send messages outside the 24-hour window in WhatsApp Cloud API?

WhatsApp's Business Policy enforces a 24-hour session window to prevent spam. After 24 hours without a customer reply, you can only send pre-approved message templates. Submit templates in Meta Business Suite > WhatsApp > Message Templates. Templates are reviewed by Meta (typically 24-48 hours) and allow proactive outreach to customers who have opted in to receive WhatsApp messages from your business.

Do I need a business phone number for WhatsApp Cloud API?

Meta provides a test phone number in the developer console for testing without a real business number. For production, you need a real phone number registered with Meta — either a new dedicated WhatsApp Business number or an existing phone number that has not been used with WhatsApp before. The number cannot already be active on WhatsApp personal or WhatsApp Business app.

Can OpenClaw send images and documents via WhatsApp?

Yes — both the Cloud API and Baileys support sending images, documents, audio, video, and location messages. For Cloud API, use `type: image` or `type: document` with a `link` (public URL) or `id` (Media API upload ID) instead of `type: text`. Media files must be accessible via public URL or pre-uploaded to Meta's media hosting using the Media API before sending.

Is there help available for setting up WhatsApp Business integration with OpenClaw?

RapidDev's team helps set up WhatsApp Business Cloud API integrations in OpenClaw including Meta Business verification guidance, message template submission strategy, webhook configuration, and automated conversation workflow design. If you are navigating Meta's approval process or building customer support automation on WhatsApp, reach out for hands-on assistance.

RapidDev

Talk to an Expert

Our team has built 600+ apps. Get personalized help with your project.

Book a free consultation

Need help with your project?

Our experts have built 600+ apps and can accelerate your development. Book a free consultation — no strings attached.

Book a free consultation

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We'll discuss your project and provide a custom quote at no cost.