
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
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
If you'd like to financially support this project, you can do so by supporting the current maintainer here.
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.
[!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
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
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'
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)
[!TIP] You can customize browser name if you connect with QR-CODE, with
Browserconstant, 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!
[!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)
}
syncFullHistory as trueconst sock = makeWASocket({
...otherOpts,
// can use Windows, Ubuntu here too
browser: Browsers.macOS('Desktop'),
syncFullHistory: true
})
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) }) ```
getMessage config in socket like this:
ts
const sock = makeWASocket({
getMessage: async (key) => await getMessageFromStore(key)
})markOnlineOnConnect to false
ts
const sock = makeWASocket({
markOnlineOnConnect: false
})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]
useMultiFileAuthStateis 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
$ claude mcp add Baileys \
-- python -m otcore.mcp_server <graph>