chat-adapter-zalo
Community adapter — This package is a community-maintained Zalo adapter for Chat SDK. It is not an official
@chat-adapter/*package.
Zalo Bot adapter for Chat SDK, using the Zalo Bot Platform API.
Installation
Usage
When using createZaloAdapter() without arguments, credentials are auto-detected from environment variables.
Zalo Bot setup
1. Create a Zalo Bot
- Go to bot.zapps.me and sign in with your Zalo account
- Create a new bot and note your Bot Token (format:
12345689:abc-xyz) - Go to Webhooks settings and set your webhook URL
2. Configure webhooks
- In the Zalo Bot dashboard, navigate to Webhooks
- Set Webhook URL to
https://your-domain.com/api/webhooks/zalo - Set a Secret Token of your choice (8–256 characters) — this becomes
ZALO_WEBHOOK_SECRET - Subscribe to the message events you need (
message.text.received,message.image.received, etc.)
3. Get credentials
From your Zalo Bot dashboard, copy:
- Bot Token as
ZALO_BOT_TOKEN - The Secret Token you set in the webhook config as
ZALO_WEBHOOK_SECRET
Configuration
All options are auto-detected from environment variables when not provided.
*Required at runtime — either via config or environment variable.
Environment variables
Webhook setup
Zalo delivers all events via POST requests with an X-Bot-Api-Secret-Token header. The adapter verifies this header using timing-safe comparison before processing any payload.
Features
Messaging
Conversations
Incoming message types
Message history
Thread ID format
Example: zalo:1234567890
The chatId is the conversation ID from the Zalo webhook payload. For group chats it is the group ID; for private chats it is the user ID.
Notes
- Zalo does not expose message history APIs to bots.
fetchMessagesreturns an empty array. - All formatting (bold, italic, code blocks) is stripped to plain text — Zalo renders no markdown.
- The bot token is embedded in the API URL path and is never logged.
isDM()always returnstrue— Zalo thread IDs do not encode chat type.
Troubleshooting
Webhook verification failing
- Confirm
ZALO_WEBHOOK_SECRETmatches the value you entered in the Zalo Bot dashboard - The adapter compares the
X-Bot-Api-Secret-Tokenheader using a timing-safe byte comparison — ensure the secret contains only ASCII characters and has no trailing whitespace
Messages not arriving
- Verify your webhook URL is reachable and returns
200 OK - Check that the event types you need are subscribed in the Zalo Bot dashboard
"Zalo API error" on send
- Confirm
ZALO_BOT_TOKENis correct — it should be in12345689:abc-xyzformat - The adapter calls
getMeduringinitialize()to validate the token; check logs for initialization errors
License
MIT