MCPcopy Index your code
hub / github.com/WhiskeySockets/Baileys

github.com/WhiskeySockets/Baileys @v6.7.23

repository ↗ · DeepWiki ↗ · release v6.7.23 ↗ · Ask this repo → · + Follow
2,464 symbols 4,121 edges 97 files 1,255 documented · 51% 11 cross-repo links updated todayv7.0.0-rc13 · 2026-05-21★ 10,008283 open issues
README

Baileys logo

Baileys is a WebSockets-based TypeScript library for interacting with the WhatsApp Web API.

[!IMPORTANT] I made a survey for users of the project to ask questions, and provide Baileys valuable insights regarding its users. I will be publishing the results of this form (after filtering) as well so we can study and understand where we need to work.

The survey is anonymous and requires no personal info at all. You are required to sign-in with Google to keep responses to one person. You are able to edit your response after you submit. The deadline for this form is September 30, 2025.

I encourage you to put the effort, all it takes is 5-10 minutes and you get to ask me any questions you have.

- Rajeh (purpshell)

Fill in the survey via the link: https://whiskey.so/survey

Important Note

This is a temporary README.md, the new guide is in development and will this file will be replaced with .github/README.md (already a default on GitHub).

New guide link: https://baileys.wiki

Sponsor

If you'd like to financially support this project, you can do so by supporting the current maintainer here.

Disclaimer

This project is not affiliated, associated, authorized, endorsed by, or in any way officially connected with WhatsApp or any of its subsidiaries or its affiliates. The official WhatsApp website can be found at whatsapp.com. "WhatsApp" as well as related names, marks, emblems and images are registered trademarks of their respective owners.

The maintainers of Baileys do not in any way condone the use of this application in practices that violate the Terms of Service of WhatsApp. The maintainers of this application call upon the personal responsibility of its users to use this application in a fair way, as it is intended to be used. Use at your own discretion. Do not spam people with this. We discourage any stalkerware, bulk or automated messaging usage.

  • Baileys does not require Selenium or any other browser to be interface with WhatsApp Web, it does so directly using a WebSocket.
  • Not running Selenium or Chromium saves you like half a gig of ram :/
  • Baileys supports interacting with the multi-device & web versions of WhatsApp.
  • Thank you to @pokearaujo for writing his observations on the workings of WhatsApp Multi-Device. Also, thank you to @Sigalor for writing his observations on the workings of WhatsApp Web and thanks to @Rhymen for the go implementation.

[!IMPORTANT] The original repository had to be removed by the original author - we now continue development in this repository here. This is the only official repository and is maintained by the community. Join the Discord here

Example

Do check out & run example.ts to see an example usage of the library. The script covers most common use cases. To run the example script, download or clone the repo and then type the following in a terminal: 1. cd path/to/Baileys 2. yarn 3. yarn example

Install

Use the stable version:

yarn add @whiskeysockets/baileys

Use the edge version (no guarantee of stability, but latest fixes + features)

yarn add github:WhiskeySockets/Baileys

Then import your code using:

import makeWASocket from '@whiskeysockets/baileys'

Links

Index

Connecting Account

WhatsApp provides a multi-device API that allows Baileys to be authenticated as a second WhatsApp client by scanning a QR code or Pairing Code with WhatsApp on your phone.

[!NOTE] Here is a simple example of event handling

[!TIP] You can see all supported socket configs here (Recommended)

Starting socket with QR-CODE

[!TIP] You can customize browser name if you connect with QR-CODE, with Browser constant, we have some browsers config, see here

import makeWASocket from '@whiskeysockets/baileys'

const sock = makeWASocket({
    // can provide additional config here
    browser: Browsers.ubuntu('My App'),
    printQRInTerminal: true
})

If the connection is successful, you will see a QR code printed on your terminal screen, scan it with WhatsApp on your phone and you'll be logged in!

Starting socket with Pairing Code

[!IMPORTANT] Pairing Code isn't Mobile API, it's a method to connect Whatsapp Web without QR-CODE, you can connect only with one device, see here

The phone number can't have + or () or -, only numbers, you must provide country code

import makeWASocket from '@whiskeysockets/baileys'

const sock = makeWASocket({
    // can provide additional config here
    printQRInTerminal: false //need to be false
})

if (!sock.authState.creds.registered) {
    const number = 'XXXXXXXXXXX'
    const code = await sock.requestPairingCode(number)
    console.log(code)
}

Receive Full History

  1. Set syncFullHistory as true
  2. Baileys, by default, use chrome browser config
    • If you'd like to emulate a desktop connection (and receive more message history), this browser setting to your Socket config:
const sock = makeWASocket({
    ...otherOpts,
    // can use Windows, Ubuntu here too
    browser: Browsers.macOS('Desktop'),
    syncFullHistory: true
})

Important Notes About Socket Config

Caching Group Metadata (Recommended)

  • If you use baileys for groups, we recommend you to set cachedGroupMetadata in socket config, you need to implement a cache like this:

    ```ts const groupCache = new NodeCache({stdTTL: 5 * 60, useClones: false})

    const sock = makeWASocket({ cachedGroupMetadata: async (jid) => groupCache.get(jid) })

    sock.ev.on('groups.update', async ([event]) => { const metadata = await sock.groupMetadata(event.id) groupCache.set(event.id, metadata) })

    sock.ev.on('group-participants.update', async (event) => { const metadata = await sock.groupMetadata(event.id) groupCache.set(event.id, metadata) }) ```

Improve Retry System & Decrypt Poll Votes

  • If you want to improve sending message, retrying when error occurs and decrypt poll votes, you need to have a store and set getMessage config in socket like this: ts const sock = makeWASocket({ getMessage: async (key) => await getMessageFromStore(key) })

Receive Notifications in Whatsapp App

  • If you want to receive notifications in whatsapp app, set markOnlineOnConnect to false ts const sock = makeWASocket({ markOnlineOnConnect: false })

Saving & Restoring Sessions

You obviously don't want to keep scanning the QR code every time you want to connect.

So, you can load the credentials to log back in:

import makeWASocket, { useMultiFileAuthState } from '@whiskeysockets/baileys'

const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')

// will use the given state to connect
// so if valid credentials are available -- it'll connect without QR
const sock = makeWASocket({ auth: state })

// this will be called as soon as the credentials are updated
sock.ev.on('creds.update', saveCreds)

[!IMPORTANT] useMultiFileAuthState is a utility function to help save the auth state in a single folder, this function serves as a good guide to help write auth & key states for SQL/no-SQL databases, which I would recommend in any production grade system.

[!NOTE] When a message is received/sent, due to signal sessions needing updating, the auth keys (authState.keys) will update. Whenever that happens, you must save t

Extension points exported contracts — how you extend this code

USyncQueryProtocol (Interface)
(no doc) [6 implementers]
src/Types/USync.ts
IDetails (Interface)
Properties of a Details. [3 implementers]
WAProto/index.d.ts
Sender (Interface)
(no doc) [1 implementers]
src/Signal/Group/sender-key-name.ts
ILogger (Interface)
(no doc)
src/Utils/logger.ts
Label (Interface)
(no doc)
src/Types/Label.ts
INoiseCertificate (Interface)
Properties of a NoiseCertificate. [2 implementers]
WAProto/index.d.ts
SenderKeyStore (Interface)
(no doc)
src/Signal/Group/group_cipher.ts
LabelActionBody (Interface)
(no doc)
src/Types/Label.ts

Core symbols most depended-on inside this repo

create
called by 997
src/Signal/Group/group-session-builder.ts
getBinaryNodeChild
called by 122
src/WABinary/generic-utils.ts
toString
called by 87
src/Signal/Group/sender-key-name.ts
emit
called by 81
src/Types/Events.ts
debug
called by 60
src/Utils/logger.ts
info
called by 47
src/Utils/logger.ts
on
called by 43
src/Types/Events.ts
query
called by 39
src/Socket/socket.ts

Shape

Function 886
Class 879
Interface 447
Enum 127
Method 125

Languages

TypeScript100%

Modules by API surface

WAProto/index.d.ts1,375 symbols
WAProto/index.js418 symbols
src/Socket/chats.ts45 symbols
src/Utils/messages-media.ts34 symbols
src/Utils/generics.ts29 symbols
src/Socket/messages-recv.ts27 symbols
src/Socket/socket.ts24 symbols
src/Utils/messages.ts23 symbols
src/Utils/chat-utils.ts22 symbols
src/WABinary/decode.ts21 symbols
src/WABinary/encode.ts18 symbols
proto-extract/index.js17 symbols

Dependencies from manifests, versioned

@cacheable/node-cache1.4.0 · 1×
@eslint/eslintrc3.3.1 · 1×
@eslint/js9.31.0 · 1×
@hapi/boom9.1.3 · 1×
@types/jest30.0.0 · 1×
@types/node16.0.0 · 1×
@types/ws8.0.0 · 1×
@typescript-eslint/eslint-plugin8.32.0 · 1×
@whiskeysockets/eslint-configgithub:whiskeysocket · 1×
acorn6.4.1 · 1×
acorn-walk6.1.1 · 1×

For agents

$ claude mcp add Baileys \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact