Environment variables
| Variable | Required | Description |
|---|---|---|
GATEWAY_ALLOWLIST | No | Comma-separated WhatsApp JIDs allowed to message the bot |
WhatsApp is enabled only when
GATEWAY_ALLOWLIST is non-empty. If the variable is empty, the gateway skips WhatsApp entirely.What is a JID?
A JID (Jabber ID) is the internal identifier WhatsApp uses for contacts. For individual contacts it takes the form:1234567890 is the phone number in international format without the + prefix. Group JIDs use a different suffix (@g.us) — the gateway processes individual chats only.
Setup
Set GATEWAY_ALLOWLIST to your JID
Add your own WhatsApp JID to You can add multiple JIDs separated by commas:
.env. Use your phone number in international format:Scan the QR code
The gateway prints a QR code in the terminal. On your phone, open WhatsApp and go to Settings → Linked Devices → Link a Device, then scan the QR code.The gateway logs
WhatsApp connected when the scan succeeds.The QR code expires after about 60 seconds. If it expires before you scan, restart the gateway to get a fresh one.
Session persistence
After a successful QR scan, Baileys saves authentication credentials toAUTH_DIR, which defaults to .gateway/auth/. This directory contains multi-file auth state — WhatsApp’s equivalent of a cookie session.
- The session survives gateway restarts. You only need to scan the QR code once.
- If you delete
.gateway/auth/or the session is invalidated on the WhatsApp side, the gateway logs out and exits with an error. Delete the auth directory and restart to pair again. - The gateway reconnects automatically after transient disconnections with a 3-second delay.
Allowlist behavior
The gateway evaluates every incoming message againstGATEWAY_ALLOWLIST:
- Empty allowlist — the gateway skips WhatsApp entirely. WhatsApp only starts when
GATEWAY_ALLOWLISThas at least one entry. - Populated allowlist — only messages from JIDs in the list are passed to the router. All other messages are silently ignored.
status@broadcast) are always ignored.
How messages are routed
Baileys emits amessages.upsert event for each incoming message. The gateway:
- Ignores non-
notifymessage types. - Skips broadcast messages and echoes of its own sent messages.
- Runs the allowlist check on the sender’s JID.
- Extracts text from
message.conversationormessage.extendedTextMessage.text. - Wraps the message with a
conversationIdof the formwhatsapp:<jid>and routes it to the agent.
Attachments
The agent may produce file attachments in its replies. If the reply includes unsupported attachments for WhatsApp, the gateway appends a notice to the text message indicating where the file was saved. The attachment root isATTACHMENTS_DIR, defaulting to .gateway/attachments/.