WhatsApp Business Cloud

Connect to WhatsApp Business Cloud for customer messaging and automated conversations.

Install

pnpm add @chat-adapter/whatsapp

Quick start

The adapter auto-detects WHATSAPP_ACCESS_TOKEN, WHATSAPP_APP_SECRET, WHATSAPP_PHONE_NUMBER_ID, and WHATSAPP_VERIFY_TOKEN from the environment.

lib/bot.ts
import { Chat } from "chat";
import { createWhatsAppAdapter } from "@chat-adapter/whatsapp";

const bot = new Chat({
  userName: "mybot",
  adapters: {
    whatsapp: createWhatsAppAdapter(),
  },
});

bot.onNewMention(async (thread, message) => {
  await thread.post("Hello from WhatsApp!");
});
app/api/webhooks/whatsapp/route.ts
import { bot } from "@/lib/bot";

export async function GET(request: Request) {
  return bot.webhooks.whatsapp(request);
}

export async function POST(request: Request) {
  return bot.webhooks.whatsapp(request);
}

Configuration

Prop

Type

Authentication

1. Create a Meta app

  1. Go to developers.facebook.com/apps and create a Business app.
  2. Add the WhatsApp product to your app.
  3. Open WhatsApp then API Setup to find your Phone Number ID and a temporary Access Token.

2. Configure webhooks

  1. Open WhatsApp then Configuration.
  2. Set the callback URL to https://your-domain.com/api/webhooks/whatsapp.
  3. Set a Verify Token of your choosing — this becomes WHATSAPP_VERIFY_TOKEN.
  4. Subscribe to the messages webhook field.

3. Get credentials

From your Meta app dashboard, copy:

  • App Secret (under App Settings then Basic) → WHATSAPP_APP_SECRET.
  • Access Token (under WhatsApp then API Setup) → WHATSAPP_ACCESS_TOKEN. For production, generate a permanent System User Token instead.
  • Phone Number ID (under WhatsApp then API Setup) → WHATSAPP_PHONE_NUMBER_ID.

Advanced

Webhook flow

WhatsApp uses two webhook mechanisms:

  • Verification handshake (GET) — Meta sends a hub.verify_token challenge that must match your WHATSAPP_VERIFY_TOKEN.
  • Event delivery (POST) — incoming messages, reactions, and interactive responses, verified via X-Hub-Signature-256.

Interactive messages

Card elements are automatically converted to WhatsApp interactive messages:

  • 3 or fewer buttons — rendered as WhatsApp reply buttons (max 20 chars per title).
  • More than 3 buttons — falls back to formatted text.
  • Max body text — 1024 characters.

Thread ID format

whatsapp:{phoneNumberId}:{userWaId}

Example: whatsapp:1234567890:15551234567.

Auto-chunking

Outgoing messages longer than 4096 characters are automatically chunked.

Feature support

Messaging

FeatureSupported
Post message
Edit message
Delete message
File uploadsImages, audio, docs
StreamingBuffered
Scheduled messages

Rich content

FeatureSupported
Card formatWhatsApp templates
ButtonsInteractive replies
Link buttons
Select menus
Tables
FieldsTemplate variables
Images in cards
Modals

Conversations

FeatureSupported
Slash commands
Mentions
Add reactions
Remove reactions
Typing indicator
DMs
Ephemeral messages
User lookup
Parent subject
Native client
Custom API endpoint

Message history

FeatureSupported
Fetch messagesCached sent only
Fetch single message
Fetch thread info
Fetch channel messages
List threads
Fetch channel info
Post channel message