npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@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:

  1. Manual version: WA_VERSION env var, then the version option.
  2. The version recommended by the Baileys maintainers (fetchLatestBaileysVersion).
  3. The live WhatsApp Web version (fetchLatestWaWebVersion).
  4. 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.1054953954

Accepted 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 from as 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 (remoteJidAlt and remoteJidUsername can both be undefined). Replying still works: the provider resolves LID→PN through the cache and signalRepository.lidMapping, and sends to the @lid directly 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:

  • from is the group JID ([email protected])
  • participant and sender carry the author JID
  • allowGroups takes precedence over groupsIgnore for groups only; status broadcasts still follow groupsIgnore

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-smoke by default, override with SMOKE_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 maxReconnectAttempts is 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 (default false): when WhatsApp logs the session out (401), auth files are preserved and an auth_failure event is emitted. Set true to wipe <name>_sessions and 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. An auth_failure event 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

Contact Us