@builderbot/provider-baileys
v1.5.2
Published
Now I'm the model of a modern major general / The venerated Virginian veteran whose men are all / Lining up, to put me up on a pedestal / Writin' letters to relatives / Embellishin' my elegance and eloquence / But the elephant is in the room / The truth i
Readme
Documentation
Visit builderbot to view the full documentation.
WhatsApp Web version
Leave version unset: the provider resolves it on every connection, in this order:
- Manual version:
WA_VERSIONenv var, then theversionoption. - The version recommended by the Baileys maintainers (
fetchLatestBaileysVersion). - The live WhatsApp Web version (
fetchLatestWaWebVersion). - The version bundled with Baileys.
Each lookup has a 5 s timeout, and baileys.log records which source was used.
When WhatsApp rejects the version (405 Connection Failure), the provider reconnects
with the live WhatsApp Web version, skipping the manual one, up to 3 times.
Manual fix. If the 405 persists, copy the latest version from https://wppconnect.io/whatsapp-versions/ and pass it as is:
const adapterProvider = createProvider(Provider, { version: '2.3000.1054953954-alpha' })or without touching code, in .env:
WA_VERSION=2.3000.1054953954Accepted formats: [2, 3000, 1054953954], '2.3000.1054953954', '2.3000.1054953954-alpha',
'2,3000,1054953954'. Remove the manual version once a provider update fixes the issue:
a pinned version goes stale within weeks.
Shutdown and session safety
By default, captureProcessSignals is false: the application owns its process
signals. Call await provider.destroy() in your shutdown handler. It cancels
pending reconnects, waits for initialization and socket shutdown, flushes the LID
cache and logs, and closes the provider HTTP server. Concurrent calls share the
same shutdown promise. A destroyed provider cannot be started again; create a
new instance instead.
Standalone applications may opt into captureProcessSignals: true. The provider
then handles shutdown signals and exits after its cleanup completes. Do not opt
in when another component owns process shutdown.
releaseSessionFiles() and timeRelease only remove regular files in the reserved
builderbot-temp-<id>.tmp namespace. They preserve credentials, Signal keys, LID
mappings, caches and all unknown files. Authentication files are not temporary
files and must not be deleted to reclaim disk space.
Tests use separate temporary workspaces; they never clean application sessions or logs.
Usernames and LID senders
WhatsApp users with a username are addressed by a LID (<id>@lid) instead of a
phone-number JID. Baileys surfaces the username fields (upstream PR #2480, present
since rc13), and the provider forwards them on the message event:
| Field | Meaning |
|---|---|
| username | Username of the chat counterpart, when WhatsApp sends it (key.remoteJidUsername) |
| participantUsername | Username of the group author, groups only (key.participantUsername) |
bot.on('message', async (ctx) => {
// ctx.from may legitimately be a LID such as '122299361538159@lid'
console.log(ctx.from, ctx.username, ctx.participantUsername)
})Important
- Treat
fromas an opaque, stable key: it can be a@lid. Do not parse it as a phone number. - In private chats WhatsApp often sends only the LID (
remoteJidAltandremoteJidUsernamecan both beundefined). Replying still works: the provider resolves LID→PN through the cache andsignalRepository.lidMapping, and sends to the@liddirectly when no PN mapping exists. - Sending to a username is not supported by Baileys (the upstream lookup API was never merged): send to a PN or a LID.
Group messages (opt-in)
Group messages are off by default. Enable them with allowGroups: true:
createBot({ /* ... */ }, { allowGroups: true })When enabled:
fromis the group JID ([email protected])participantandsendercarry the author JIDallowGroupstakes precedence overgroupsIgnorefor groups only; status broadcasts still followgroupsIgnore
Legacy groupsIgnore (default true) keeps ignoring groups and broadcasts when
allowGroups is not set.
Live validation (manual, opt-in)
Automated tests mock Baileys, so they cannot catch packaging or protocol issues.
scripts/live-smoke.cjs links a real device and exercises the built provider:
pnpm --filter @builderbot/provider-baileys build
cd packages/provider-baileys
node scripts/live-smoke.cjs # QR pairing (NV1)
SEND=1 node scripts/live-smoke.cjs # + text and image (NV2/NV3)
PHASE=resume SEND=1 node scripts/live-smoke.cjs # restart with saved creds + reconnect (NV4/NV5)
MEDIA=1 SEND=1 node scripts/live-smoke.cjs # full outbound media batch- Runs in its own temporary cwd (
/tmp/baileys-live-smokeby default, override withSMOKE_ROOT); it never touches your application directories or sessions. - Prints the QR to the terminal and to
<SMOKE_ROOT>/qr-blocks.log; results land in<SMOKE_ROOT>/result-<phase>.json. - Sends only to the linked account's own chat unless you set
DEST. Do not point it at third parties: WhatsApp restricts accounts for cold outreach. - It links a real device to your account — unlink it in WhatsApp afterwards.
Multi-session deployments (memory)
Baileys rc14 still creates one AsyncLocalStorage per socket and never
releases it (upstream #2806,
fix PR #2807 open).
Heap then grows with sockets ever created, including every reconnect.
Until upstream merges the fix:
- Prefer one process per session (process isolation).
- Recycle long-running processes after repeated reconnects (the provider logs a
hint when
maxReconnectAttemptsis reached). - A single-session bot is not meaningfully affected.
Resilience options
baileysLogLevel(default'error'): level of the internal Baileys pino logger.'fatal'restores the old silent behavior but hides decrypt failures (Bad MAC, No session).clearAuthOnLogout(defaultfalse): when WhatsApp logs the session out (401), auth files are preserved and anauth_failureevent is emitted. Settrueto wipe<name>_sessionsand re-pair automatically (legacy behavior).connectionReplaced(440) never auto-reconnects: another live socket owns the session and retrying starts a tug-of-war that can escalate to a ban. Anauth_failureevent is emitted instead.- Reconnects use exponential backoff (1s base, 30s cap) with ±20% jitter.
- Pairing codes are requested with the digits-only phone number, and socket listeners are attached before the pairing request resolves.
Official Course
If you want to discover all the functions and features offered by the library you can take the course. View Course
