WhatsApp (Meta Cloud API) adapter for chat-py
Project description
chat-adapter-whatsapp
WhatsApp (Meta Cloud API) adapter for chat-py. Python port of upstream packages/adapter-whatsapp.
Install
uv add chat-py chat-py-adapter-whatsapp chat-py-adapter-state-memory
Along with the core SDK and any chat-py-adapter-state-* (use chat-py-adapter-state-redis / -state-pg in production).
Environment variables
| Variable | Required | Description |
|---|---|---|
WHATSAPP_ACCESS_TOKEN |
yes | System User access token for the Cloud API |
WHATSAPP_APP_SECRET |
yes | Meta App Secret for X-Hub-Signature-256 HMAC verification |
WHATSAPP_PHONE_NUMBER_ID |
yes | Business phone number ID (not the phone number itself) |
WHATSAPP_VERIFY_TOKEN |
yes | Token returned during the hub.challenge handshake |
WHATSAPP_BOT_USERNAME |
no | Display name for the bot (defaults to whatsapp-bot) |
WHATSAPP_API_URL |
no | Override the Meta Graph API base URL (defaults to https://graph.facebook.com) |
Minimal example
import asyncio
from chat import Chat
from chat_adapter_state_memory import MemoryState
from chat_adapter_whatsapp import create_whatsapp_adapter
async def main() -> None:
chat = Chat(
user_name="my-bot",
adapters={"whatsapp": create_whatsapp_adapter()},
state=MemoryState(),
)
@chat.on_new_mention
async def _on_mention(event): # pragma: no cover - example only
await event.thread.post(f"Hi {event.message.author.user_name}!")
# Plug `chat.handle_webhook("whatsapp", body, headers)` into your HTTP
# framework of choice (FastAPI, Starlette, aiohttp, ...).
asyncio.run(main())
Webhook handling
WhatsAppAdapter.handle_webhook answers both:
GET— Meta verification challenge. The adapter checkshub.mode == "subscribe"andhub.verify_tokenagainst the configured verify token, then echoeshub.challengeback with status 200. Pass the request URL via theurl=keyword so the adapter can read the query string.POST— event delivery. The raw body is verified with HMAC-SHA256 against the App Secret using :func:hmac.compare_digest. Mismatched signatures produce401.
Each method returns (status, headers, body) matching the rest of the
chat-py adapter family.
Cards & interactive messages
Cards with reply-button actions (1-3 buttons) render as an interactive
button payload. Anything else falls back to a WhatsApp-flavoured markdown
message (*bold*, _italic_, ~strike~, ```code```). Reply
button IDs encode the action via chat:{json} so callbacks round-trip
through decode_whatsapp_callback_data.
Limitations / parity notes
- No edit / delete. WhatsApp Cloud API does not support
editMessage/deleteMessage; both raisechat.NotImplementedError, matching upstream'sErrorthrows. - No history fetch.
fetch_messagesalways returns{"messages": []}— the Cloud API has no message history endpoint. - No typing indicator.
start_typingis a no-op. - Single-DM threads. Every conversation is 1:1, so the channel ID is the thread ID.
Test
uv run pytest packages/chat-adapter-whatsapp
Upstream
https://github.com/vercel/chat/tree/main/packages/adapter-whatsapp
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chat_py_adapter_whatsapp-0.1.0.tar.gz.
File metadata
- Download URL: chat_py_adapter_whatsapp-0.1.0.tar.gz
- Upload date:
- Size: 31.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.20 {"installer":{"name":"uv","version":"0.9.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a92a6446220211e64a022013d85711babdef3cdcf14fda85f709b978a5c5fec
|
|
| MD5 |
b3a8610fa82b304b93c5860431bd9fae
|
|
| BLAKE2b-256 |
bc74761c167cc0a3cfdf724d923d3ed09304ff68c56b1862dc36c8980951a0ac
|
File details
Details for the file chat_py_adapter_whatsapp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: chat_py_adapter_whatsapp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 23.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.20 {"installer":{"name":"uv","version":"0.9.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0b4d8a37344326ec63b2a9389ffc44e974860f4653e910365cabe4dd5087571
|
|
| MD5 |
78c80b8926287a96afbb8f21d4cbca0a
|
|
| BLAKE2b-256 |
f69340973bcd0f67a91bd0da17ef81fb136070bc3dd00f0d92d68020028bff78
|