arizuko › components › whapd
whapd
whapd speaks WhatsApp Web through the Baileys library, and you pair it with a QR code or an 8-character code.
whapd connects WhatsApp to arizuko
whapd connects WhatsApp to arizuko, so the agent can read and reply in WhatsApp chats and groups.
whapd is the WhatsApp channel adapter. It speaks WhatsApp Web through the Baileys socket library, in TypeScript on Node. It posts inbound messages to routd and sends outbound messages through the same socket. The JID prefix is whatsapp:. A conversation has the JID whatsapp:<jid>, where jid is the native Baileys form: <phone>@s.whatsapp.net for a person or <group-id>@g.us for a group.
WhatsApp has no usable consumer API
WhatsApp has no consumer API that arizuko can use. The official Cloud API needs partner approval and has quotas, so other tools use a WhatsApp Web client. Baileys has no Go port, so whapd is written in TypeScript. whapd keeps the pairing credentials in $WHATSAPP_AUTH_DIR/creds.json, with an atomic .bak copy. A new install needs pairing.
whapd sits between WhatsApp and routd
WhatsApp (web.whatsapp.com socket)
│ Baileys multi-device socket
▼
whapd (LISTEN_ADDR=:8080, Node runtime)
│ POST /v1/messages (service:<daemon> ES256 bearer)
▼
routd
│ POST /send (callback to whapd)
▼
whapd (sock.sendMessage / reactMessage / delete)
│
▼
WhatsApp
The wired verbs are in whapd/src/server.ts:
sendsendMessage(jid, {text}), withreply_toas the Baileysquotedmessage.send_file- An image, video, audio file or document, chosen from the MIME type.
typing- The composing and paused presence, refreshed while the turn runs.
like- A reaction. The
reactionfield selects the emoji, 👍 by default. edit- Own messages, within 15 minutes.
delete- Removal of an own message.
forward- Best effort: whapd builds the forwarded text itself, because Baileys gives only
source_msg_id.
quote, repost, dislike and post return 501 with a hint. The hint for dislike points to like(reaction='👎').
whapd has no fetch_history. The history sync of Baileys is not reliable across the LID and JID translation of Meta, so routd uses its local cache.
Two pairing methods need no token
- QR code
- The default. whapd prints a QR code in ASCII to its log. Scan it with WhatsApp on the phone, in Settings, Linked devices, Link a device.
- Pairing code
--pair <phone>on the binary, or the self-service page/dash/channels/whatsapp/pair. The operator enters the phone number of the bot, and whapd prints an 8-character code. The operator types the code on the phone instead of scanning a QR code. Use it for deploys without a screen.
If creds.json is lost, the device is unlinked, and you must pair again. whapd writes a backup to creds.json.bak on every save and recovers from it after a crash. whapd keeps the outbound queue on disk and resumes it after a reconnect.
whapd runs alone with routd and an auth directory
export ROUTER_URL=http://routd:8080
export AUTHD_URL=http://authd:8080
export AUTHD_SERVICE_KEY=$(grep ^AUTHD_SERVICE_KEY .env | cut -d= -f2)
export LISTEN_ADDR=:8080
export WHATSAPP_AUTH_DIR=/srv/data/store/whatsapp-auth
export DATA_DIR=/srv/data/arizuko_demo
node dist/main.js
GET /health returns 503 while whapd waits for a QR or pairing-code scan, and while the Baileys socket is disconnected. The QR code is in the journal of the instance, because every service runs attached under the systemd unit of the instance. Run sudo journalctl -u arizuko_<inst> on the host.
Two sources cover the details
- components/channels: the verb table across adapters.
- [whapd/README.md]: the verb table, the file map and the edit and delete windows.