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
Metadata
Release files for chat-py-adapter-whatsapp 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| chat_py_adapter_whatsapp-0.1.0.tar.gz | 31.9 kB | Without provenance | Details for chat_py_adapter_whatsapp-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| chat_py_adapter_whatsapp-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for chat_py_adapter_whatsapp-0.1.0-py3-none-any.whl |
Total release size: 55.2 kB
Release files / chat_py_adapter_whatsapp-0.1.0.tar.gz
| Download URL | chat_py_adapter_whatsapp-0.1.0.tar.gz |
|---|---|
| Size | 31.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5a92a6446220211e64a022013d85711babdef3cdcf14fda85f709b978a5c5fec
|
|
BLAKE2b-256 checksum How to use checksums |
bc74761c167cc0a3cfdf724d923d3ed09304ff68c56b1862dc36c8980951a0ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Release files / chat_py_adapter_whatsapp-0.1.0-py3-none-any.whl
| Download URL | chat_py_adapter_whatsapp-0.1.0-py3-none-any.whl |
|---|---|
| Size | 23.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c0b4d8a37344326ec63b2a9389ffc44e974860f4653e910365cabe4dd5087571
|
|
BLAKE2b-256 checksum How to use checksums |
f69340973bcd0f67a91bd0da17ef81fb136070bc3dd00f0d92d68020028bff78
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Security for chat-py-adapter-whatsapp 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.