Kapso
WhatsApp adapter for Chat SDK backed by Kapso webhooks, sends, media, reactions, contacts, conversations, and message history.
Create a new bot
Scaffold a Next.js bot with the Kapso adapter using create-chat-sdk:
pnpm create chat-sdk@latest my-bot --adapter kapso memory -yThe generated app uses the Memory state adapter for local development. To add the adapter to an existing app, start at Install.
Install
pnpm add @kapso/chat-adapter chatThe examples below use @chat-adapter/state-memory for local development. Install a durable Chat SDK state adapter for production.
Quick start
Kapso webhooks are direct-message conversations, which is why the example uses onDirectMessage. Replies, cards, files, reactions, and history calls use the same Chat SDK Thread and Message APIs as the official adapters.
Platform setup
- Create or use a Kapso integration and copy your API key.
- Copy the WhatsApp phone number ID connected in Kapso if the bot will initiate outbound direct messages.
- Create a webhook secret in Kapso and set the same value as
KAPSO_WEBHOOK_SECRET. - Set your webhook endpoint URL to the public route that forwards requests to
bot.webhooks.kapso. - Subscribe to
whatsapp.message.received; addwhatsapp.message.sentonly if your app needs sent-message echoes.
Configuration
Prop
Type
Environment variables
| Variable | Required | Description |
|---|---|---|
KAPSO_API_KEY | Yes | Kapso API key used for sends, history, contacts, conversations, and media. |
KAPSO_PHONE_NUMBER_ID | Recommended | WhatsApp phone number ID connected in Kapso. Required for openDM() and useful as a webhook fallback. |
KAPSO_WEBHOOK_SECRET | Recommended | Secret used to verify Kapso X-Webhook-Signature webhook deliveries. |
KAPSO_BASE_URL | No | Kapso proxy URL. Defaults to https://api.kapso.ai/meta/whatsapp. |
KAPSO_BOT_USERNAME | No | Bot display name. Defaults to the Chat SDK userName after initialization. |
Webhooks
Kapso sends platform webhooks as POST requests. Forward the raw Request to Chat SDK:
By default, the adapter verifies the Kapso X-Webhook-Signature header and returns 401 when a signature is invalid. Pass verifyWebhookSignatures: false only for unsigned local fixtures.
Sending messages
Reply inside an incoming WhatsApp handler:
Start a WhatsApp conversation from your app with openDM():
Buttons and cards
Chat SDK card buttons render as WhatsApp reply buttons.
WhatsApp allows up to 3 reply buttons, and each label must be 1-20 characters. If a card breaks either limit, the adapter throws a validation error rather than truncating labels or dropping buttons.
Media
Send files through Chat SDK:
Inbound media arrives as Chat SDK attachments. When Kapso includes a mirrored media URL, the attachment has a url. When a WhatsApp media ID is available, the attachment has a lazy fetchData().
History
When KAPSO_API_KEY is set, fetchMessages() reads history from Kapso:
fetchThread() enriches metadata with Kapso contact and conversation records when available.
Thread IDs
Current thread IDs use this format, where the conversation ID segment is optional:
Use the adapter's helpers rather than building thread IDs by hand:
Limitations
- Direct Meta webhook setup is a compatibility path. Prefer Kapso platform webhooks.
- WhatsApp and Kapso don't support editing or deleting messages on recipient devices.
- WhatsApp and Kapso don't support streaming to recipient devices.
- Send raw WhatsApp templates, flows, and catalogs through
@kapso/whatsapp-cloud-apidirectly, alongside the Chat SDK adapter.
Feature support
Messaging
| Feature | Supported |
|---|---|
| Post message | |
| Message replies | |
| Edit message | |
| Delete message | |
| File uploads | Images, video, audio, documents, stickers |
| Streaming | |
| Scheduled messages |
Rich content
| Feature | Supported |
|---|---|
| Card format | WhatsApp-compatible text and actions |
| Buttons | Up to 3 reply buttons |
| Link buttons | |
| Select menus | |
| Tables | |
| Charts | |
| Fields | |
| Images in cards | Sent as media |
| Modals |
Conversations
| Feature | Supported |
|---|---|
| Slash commands | |
| Mentions | |
| Add reactions | |
| Remove reactions | |
| Typing indicator | |
| Mark as read | |
| Message edit events | |
| Message delete events | |
| DMs | |
| Ephemeral messages | |
| User lookup | |
| Parent subject | |
| Native client | |
| Custom API endpoint |
Message history
| Feature | Supported |
|---|---|
| Fetch messages | |
| Fetch single message | |
| Fetch thread info | |
| Fetch channel messages | |
| List threads | |
| Fetch channel info | |
| Post channel message |