Skip to content

Guide · Open source

How to use Baileys: install and send WhatsApp messages in code

Updated · written with AI from the project's own documentation and checked against our catalogue data

Baileys is an open-source library that lets your code talk to WhatsApp Web directly over a WebSocket, without Selenium or a browser. This guide is for developers who want to install it, understand the basic setup, and find the parts of the library they need. It is a code library with no end-user interface, so you will need to be comfortable writing TypeScript or JavaScript.

BaileysWhiskeySockets/Baileys · ★ 11.5k · MIT

Quick start

  1. 1Check your runtime. Make sure Node.js, Bun or Deno is installed. The README does not specify version numbers.
  2. 2Install the library. Run yarn add @whiskeysockets/baileys in your project, or the edge version from GitHub if you accept less stability.
  3. 3Import makeWASocket. Import makeWASocket from '@whiskeysockets/baileys' in your TypeScript or JavaScript file.
  4. 4Run the example. Clone the repo and run yarn and yarn example to see common use cases in Example/example.ts.
  5. 5Connect an account. Choose QR code or pairing code and follow the connection section in the docs at baileys.wiki.
  6. 6Handle events and store your session. Listen for events and save auth info so you can restore the session.

What Baileys is and who it is for

Baileys is a WebSockets-based TypeScript library for interacting with the WhatsApp Web API. According to its README, it does not require Selenium or any other browser, because it connects directly over a WebSocket. The README notes that not running Selenium or Chromium saves a large amount of RAM.

Developers use it to build bots and tools that connect to WhatsApp accounts, such as sending and receiving messages and managing groups. It is aimed at developers who are comfortable reading library docs and handling events and session storage themselves.

  • Good fit: developers who want to script WhatsApp message handling in TypeScript or JavaScript.
  • Good fit: teams that want to avoid running a headless browser for a WhatsApp Web integration.
  • Not a fit: non-developers looking for a ready-made app.
  • Not a fit: businesses that need an official WhatsApp integration. The project is not affiliated with WhatsApp.

Install Baileys with yarn

You need Node.js, Bun or Deno installed. The README does not specify version requirements. The README's install commands use yarn.

For the stable version, run the first command below. The README also offers an edge version with the second command, noting it has no guarantee of stability but includes the latest fixes and features.

After installing, import the library with the code shown below.

yarn add @whiskeysockets/baileys # Edge version (no stability guarantee): yarn add github:WhiskeySockets/Baileys import makeWASocket from '@whiskeysockets/baileys'

Run the bundled example

The repository includes an example script, Example/example.ts, which the README describes as covering most common use cases. To run it, download or clone the repo and run the commands below from a terminal.

  • Change into the Baileys folder.
  • Run yarn to install dependencies.
  • Run yarn example to start the example script.
cd path/to/Baileys yarn yarn example

Connect your account with a QR code or pairing code

The README's index lists two ways to connect an account: with a QR code, or with a pairing code. Read the connection sections of the docs at baileys.wiki for the exact setup for each method.

The README also lists a section on receiving full history when connecting.

  • Connect with QR code.
  • Connect with pairing code.
  • Receive full history.

Handle events and save your session

Your code reacts to events the library emits, such as incoming messages. The README includes a section on handling events, with an example to start and a summary of events on first connection.

Baileys does not handle session storage for you in the README's framing. The README has a section on saving and restoring sessions, and a section on implementing a data store. Plan to store your auth info so you do not need to reconnect each time.

  • Read the handling events section, including the example to start.
  • Save and restore sessions using the auth info section.
  • Implement a data store as described in the README.

Send messages and manage groups

The README's index covers a wide range of actions. These include sending text, quoted, forwarded, location, contact, reaction, pin, poll, media, and view-once messages, as well as editing and deleting messages.

Group features include creating a group, adding or removing participants, changing the subject or description, leaving a group, and managing invite codes and join requests. Use the Baileys docs for the exact function calls for each action.

  • Text, media, poll, location and contact messages.
  • Edit and delete messages.
  • Create groups, manage participants and invite codes.
  • Block and unblock users, and read privacy settings.

Follow the rules and avoid misuse

The README's disclaimer says the maintainers do not condone use that violates WhatsApp's Terms of Service. It asks users to use the library fairly and says not to spam people with it.

The README explicitly discourages stalkerware, bulk or automated messaging. Read the disclaimer before building anything that messages people.

What people use it for

  • Building a bot that receives and replies to WhatsApp messages.
  • Scripting group management such as adding participants or changing a group description.
  • Sending messages with media, polls or location from your own application.
  • Checking whether a number exists on WhatsApp before messaging it.

Frequently asked questions

Is Baileys free to use?

Baileys is released under the MIT licence, according to the project's summary. The MIT licence is permissive, but check the licence file in the repository for the full terms.

Do I need Selenium or a browser to use Baileys?

No. The README says Baileys does not require Selenium or any other browser, because it connects directly over a WebSocket. It also says this saves a large amount of RAM.

How do I install Baileys?

Run yarn add @whiskeysockets/baileys for the stable version. The README also lists yarn add github:WhiskeySockets/Baileys for the edge version, which has no stability guarantee.

Is Baileys an official WhatsApp library?

No. The README states the project is not affiliated, associated, authorized, or endorsed by WhatsApp. Businesses looking for an official integration should look elsewhere.

What are alternatives to Baileys?

The project's comparable projects are whatsapp-web.js, Evolution API and go-whatsapp. Compare them on the features you need, such as language and whether you want a library or a ready-made service.

Can I use Baileys for bulk or automated messaging?

The README explicitly discourages spam, bulk or automated messaging, and any stalkerware use. It says the maintainers do not condone practices that violate WhatsApp's Terms of Service.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

Baileys suits developers who want to script WhatsApp message handling in TypeScript or JavaScript without running a headless browser. If you need a ready-made app, an official WhatsApp integration, or plan bulk or automated messaging, pick a different tool.

Install options & downloads