WABotJS supports two complementary login methods — QR code scanning and phone-number OTP pairing — so you can choose whichever fits your deployment. Either way, credentials are persisted automatically in an SQLite database under yourDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/jzszdznzzl/WABotJS/llms.txt
Use this file to discover all available pages before exploring further.
datadir, meaning your bot survives restarts without requiring a fresh scan or code entry each time.
QR Code Login
The default login flow displays a QR code that you scan with the WhatsApp mobile app. Provide anonQR handler before calling bot.login() to receive the raw QR string; you can render it in the terminal with the qrcode package.
onOpen fires with a baileys.Contact object describing the authenticated account. The user parameter exposes .id, .lid, .name, and .phoneNumber.
Phone Number (OTP) Login
If you pass a phone number (with country code) tobot.login() and no saved credentials exist yet, WABotJS skips the QR step and requests an 8-digit pairing code instead. Register an onOTP handler to receive the code, then enter it in WhatsApp → Linked devices → Link with phone number.
If credentials for this
datadir are already registered, the phone number is ignored and the
existing session is resumed directly — onOTP will not fire.Choosing Between QR and OTP
- QR Code
- Phone Number (OTP)
Session Persistence
WABotJS stores all credentials and signal keys in a single SQLite file at{datadir}/auth.sqlite. The Auth class writes to that database automatically every time WhatsApp fires a creds.update event — you never need to call a save function yourself.
On the next bot.login() call the stored session is loaded from disk, and the bot reconnects transparently without showing a QR code or sending an OTP. This means your bot can restart (e.g. after a deployment or crash) and reconnect in seconds.
Keep
datadir private and backed up. The auth.sqlite file contains your WhatsApp session
credentials. Anyone who has access to it can impersonate your linked device.Handling Disconnection
WABotJS distinguishes between transient and permanent disconnections. Transient disconnections trigger automatic reconnection managed by WABotJS. For most transient failures, reconnection uses exponential back-off: the delay starts at 5 seconds and doubles on each failure up to a maximum of 5 minutes. The one exception isrestartRequired — that code triggers an immediate reconnect with no delay. No action is required from your code in either case.
Permanent disconnections call your onClose handler and then invoke bot.logout() to clear the stored session. The status codes that trigger a permanent disconnect are:
| Status code | Meaning |
|---|---|
loggedOut | User removed the linked device in WhatsApp |
forbidden | Account action blocked by WhatsApp |
405 | Method not allowed (server-side rejection) |
400 | Bad request (usually an invalid session state) |
Logging Out vs. Closing
bot.logout()
Sends a logout request to WhatsApp, removes all event listeners, and deletes the
auth.sqlite file via auth.drop(). Use this when you want to unlink the device entirely.
The next bot.login() will start a fresh QR / OTP flow.