WhatsApp Business Cloud
Connect to WhatsApp Business Cloud for customer messaging and automated conversations.
Install
pnpm add @chat-adapter/whatsappQuick start
The adapter auto-detects WHATSAPP_ACCESS_TOKEN, WHATSAPP_APP_SECRET, WHATSAPP_PHONE_NUMBER_ID, and WHATSAPP_VERIFY_TOKEN from the environment.
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!");
});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
- Go to developers.facebook.com/apps and create a Business app.
- Add the WhatsApp product to your app.
- Open WhatsApp then API Setup to find your Phone Number ID and a temporary Access Token.
2. Configure webhooks
- Open WhatsApp then Configuration.
- Set the callback URL to
https://your-domain.com/api/webhooks/whatsapp. - Set a Verify Token of your choosing — this becomes
WHATSAPP_VERIFY_TOKEN. - Subscribe to the
messageswebhook 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_tokenchallenge that must match yourWHATSAPP_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
| Feature | Supported |
|---|---|
| Post message | |
| Edit message | |
| Delete message | |
| File uploads | Images, audio, docs |
| Streaming | Buffered |
| Scheduled messages |
Rich content
| Feature | Supported |
|---|---|
| Card format | WhatsApp templates |
| Buttons | Interactive replies |
| Link buttons | |
| Select menus | |
| Tables | |
| Fields | Template variables |
| Images in cards | |
| Modals |
Conversations
| Feature | Supported |
|---|---|
| Slash commands | |
| Mentions | |
| Add reactions | |
| Remove reactions | |
| Typing indicator | |
| DMs | |
| Ephemeral messages | |
| User lookup | |
| Parent subject | |
| Native client | |
| Custom API endpoint |
Message history
| Feature | Supported |
|---|---|
| Fetch messages | Cached sent only |
| Fetch single message | |
| Fetch thread info | |
| Fetch channel messages | |
| List threads | |
| Fetch channel info | |
| Post channel message |