Baileys

A TypeScript library that talks to WhatsApp Web directly over WebSockets, no browser or Selenium required.

SDK
npm
v7.0.0-rc14
10,969stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
83/100Excellent
Development Activity76
Maintenance72
Community88
Maturity56
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
74/100Good
Architecture82
Code Quality78
Innovation80
Learning Curve55

Baileys is a WebSockets-based TypeScript library that implements the WhatsApp Web multi-device protocol directly, letting a Node.js process authenticate as a linked WhatsApp device and exchange encrypted messages, media, and metadata without driving a real or headless browser. It reimplements the noise-protocol handshake, binary XML-like node encoding, and the Signal double-ratchet encryption WhatsApp Web itself relies on, so it can be embedded in a server process at a fraction of the memory cost of a Puppeteer/Selenium-based approach.

The library exposes a single makeWASocket entry point that returns an event-driven socket covering messaging (text, media, polls, reactions, edits, deletions), groups and communities, business profiles, newsletters, presence, and auth-state persistence. Because it speaks the protocol natively rather than scripting a browser, it is widely used as the foundation for WhatsApp chatbots, notification systems, and automation tooling in the Node.js ecosystem, with an active community maintaining compatibility as WhatsApp evolves its multi-device protocol.

What You Get

  • A makeWASocket() factory that returns a fully event-driven socket with typed connection, message, chat, and group update events
  • QR-code and pairing-code based device linking, with pluggable auth-state persistence (useMultiFileAuthState out of the box)
  • Full messaging surface: text, quoted/mentioned messages, media (image, video, audio, gif, view-once), polls, reactions, edits, and deletions
  • Group and community management: create/update groups, add/remove/promote participants, change settings, and read group metadata
  • Business features: fetching business profiles, catalogs, and newsletter/channel interactions via the WAM/WAUSync query layers
  • Low-level building blocks (binary node codec, noise handshake, Signal session store) exposed for advanced/custom protocol usage

Common Use Cases

  • Building WhatsApp chatbots and customer-support automations that run as a background Node.js service
  • Sending transactional or notification messages (order updates, OTPs, alerts) from a backend without a paid Business API contract
  • Building WhatsApp-based CRM, helpdesk, or broadcast tooling that needs programmatic access to chats and groups
  • Archiving, mirroring, or bridging WhatsApp conversations into another platform (e.g. a ticketing system or another chat network)
  • Prototyping WhatsApp integrations for internal tools without standing up a Selenium/Puppeteer-driven browser instance

Under The Hood

Architecture Baileys composes its socket as a chain of layered factory functions: makeWASocket in src/Socket/index.ts calls makeCommunitiesSocket, which internally calls makeNewsletterSocket, which calls makeBusinessSocket, down through makeGroupsSocket, makeChatsSocket, makeMessagesRecvSocket, and finally makeMessagesSocket/socket.ts at the core. Each layer destructures the inner socket, spreads it (...sock) into its own returned object, and adds its own methods and event listeners on top — an “onion” composition pattern that keeps core transport concerns (noise handshake, binary node I/O, WebSocket lifecycle in src/Socket/socket.ts and Client/) decoupled from higher-level concerns (group metadata parsing in communities.ts, message send/receive orchestration in messages-send.ts/messages-recv.ts). Swapping or reordering a layer only requires that layer’s return shape stay compatible with what the next layer up destructures from it.

Tech Stack The library targets Node.js 20+ and is written in strict-mode TypeScript (ES2020 target, ESM output), depending on @hapi/boom for structured errors, protobufjs plus a generated WAProto module for WhatsApp’s protobuf wire format, libsignal for the Signal encryption primitives, ws for the raw WebSocket transport, lru-cache/@cacheable/node-cache for in-memory caching, p-queue/async-mutex for serializing concurrent operations, and pino for structured logging. Media handling (jimp, link-preview-js, audio-decode, sharp) is pushed to optional peer dependencies so consumers only install what they actually use. The build pipeline compiles with tsc plus tsc-esm-fix for ESM interop, and the project is distributed as a plain npm package with no bundler.

Code Quality The repo has a substantial Jest test suite (28 test files under src/__tests__, covering Signal/, Socket/, Utils/, and binary-node encode/decode logic) run via --experimental-vm-modules, plus a separate test:e2e suite gated behind its own Jest config. tsconfig.json enables strict, strictNullChecks, noUncheckedIndexedAccess, and noFallthroughCasesInSwitch, and CI (.github/workflows) runs dedicated lint.yml, build.yml, test.yml, and e2e.yml jobs on every change, backed by a shared @whiskeysockets/eslint-config and Prettier formatting enforced via lint:fix. Core files favor explicit typed function signatures and Boom-based structured errors over silent failure, though some binary-parsing code paths still lean on non-null assertions (attrs.jid!) where the wire format is trusted.

API Design The entire public surface reduces to one call — makeWASocket(config) — returning a single event-emitting socket object, so getting a working connection requires only a config object and an auth state provider (useMultiFileAuthState covers the common case out of the box). Method and event names read naturally (sock.sendMessage, sock.groupMetadata, ev.on('messages.upsert', ...)), and TypeScript types are re-exported from a single root index.ts so consumers get full autocomplete without hunting through submodules. The tradeoff is a steep initial learning curve: WhatsApp’s own protocol concepts (JIDs, LIDs, noise handshake states, auth-state shape) leak into the public API, and the 1,300-line README is the primary onboarding path rather than generated API docs.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search