Baileys - Typescript/Javascript WhatsApp Web API
WhatsApp Baileys is an open-source library designed to help developers build automation solutions and integrations with WhatsApp efficiently and directly. Using websocket technology without the need for a browser, this library supports a wide range of features such as message management, chat handling, group administration, as well as interactive messages and action buttons for a more dynamic user experience.
Actively developed and maintained, baileys continuously receives updates to enhance stability and performance. One of the main focuses is to improve the pairing and authentication processes to be more stable and secure. Pairing features can be customized with your own codes, making the process more reliable and less prone to interruptions.
This library is highly suitable for building business bots, chat automation systems, customer service solutions, and various other communication automation applications that require high stability and comprehensive features. With a lightweight and modular design, baileys is easy to integrate into different systems and platforms.
Main Features and Advantages
- Supports automatic and custom pairing processes
- Fixes previous pairing issues that often caused failures or disconnections
- Supports interactive messages, action buttons, and dynamic menus
- Efficient automatic session management for reliable operation
- Compatible with the latest multi-device features from WhatsApp
- Lightweight, stable, and easy to integrate into various systems
- Suitable for developing bots, automation, and complete communication solutions
- Comprehensive documentation and example codes to facilitate development
Getting Started
Begin by installing the library via your preferred package manager, then follow the provided configuration guide. You can also utilize the ready-made example codes to understand how the features work. Use session storage and interactive messaging features to build complete, stable solutions tailored to your business or project needs.
Table of Contents
Requirements
- Node.js >= 20
- Optional peer deps depending on the features you use:
sharp or jimp (image processing), link-preview-js (link previews), audio-decode (audio waveform)
Install
npm install @alannxd/baileys
Or alias it as baileys / @whiskeysockets/baileys in your package.json:
{
"dependencies": {
"@alannxd/baileys": "latest"
}
}
import makeWASocket from '@alannxd/baileys'
const { default: makeWASocket } = require('@alannxd/baileys')
Quick Start
Login with QR Code
import makeWASocket, { Browsers, useMultiFileAuthState } from '@alannxd/baileys'
const { state, saveCreds } = await useMultiFileAuthState('auth_info')
const client = makeWASocket({
browser: Browsers.ubuntu('Chrome'),
printQRInTerminal: true,
auth: state
})
client.ev.on('creds.update', saveCreds)
Login with Pairing Code
import makeWASocket, { Browsers, fetchLatestWAWebVersion, useMultiFileAuthState } from '@alannxd/baileys'
const { state, saveCreds } = await useMultiFileAuthState('auth_info')
const { version } = await fetchLatestWAWebVersion()
const client = makeWASocket({
browser: Browsers.ubuntu('Chrome'),
printQRInTerminal: false,
version,
auth: state
})
client.ev.on('creds.update', saveCreds)
if (!client.authState?.creds?.registered) {
const phoneNumber = '628XXXXXXXXXX'
const code = await client.requestPairingCode(phoneNumber)
console.log('Pairing code:', code)
}
Store
makeInMemoryStore builds a local cache of chats/contacts/messages, which
Baileys does not persist automatically by default.
import makeWASocket, { makeInMemoryStore } from '@alannxd/baileys'
import pino from 'pino'
const store = makeInMemoryStore({
logger: pino().child({ level: 'silent', stream: 'store' })
})
const client = makeWASocket({ })
store.bind(client.ev)
client.ev.on('contacts.upsert', () => {
console.log('New contact:', Object.values(store.contacts))
})
Need a persistent store (Redis, etc.)? Use makeCacheManagerStore — see API Reference.
Saving the store to a file
makeInMemoryStore can read/write its state to a local JSON file, so it
survives restarts without needing an external database:
const store = makeInMemoryStore({ })
const stopAutoSave = store.writeToFileInterval('./store.json')
process.on('SIGINT', () => {
stopAutoSave()
process.exit(0)
})
Or handle it manually with store.readFromFile(path) / store.writeToFile(path) — see API Reference for details.
Sending Messages
Generic send / relay
await client.relayMessage(jid, { conversation: 'Hello from Baileys' }, {})
await client.sendMessage(jid, { text: 'Hello from Baileys' })
Simple senders
All the sendX functions below are shortcuts on top of sendMessage.
await client.sendText(jid, 'Hi!', { contextInfo: { mentionedJid: [jid] } })
await client.sendImage(jid, { url: './photo.jpg' }, 'image caption')
await client.sendVideo(jid, { url: './clip.mp4' }, 'video caption')
await client.sendAudio(jid, { url: './clip.mp3' })
await client.sendLocation(jid, 'Location name', -6.2, 106.8, 'https://maps.example', '1234567890')
await client.sendPoll(jid, 'Pick one', ['Option 1', 'Option 2', 'Option 3'], true)
await client.sendQuiz(jid, 'Correct answer?', ['1', '2', '3'], '2')
Special message types
Handled internally by the Socket/luxu.js helper, invoked automatically via
sendMessage/relayMessage whenever the content includes one of the fields below.
await client.relayMessage(jid, {
productMessage: {
title: 'Product Name',
description: 'Product description',
thumbnail: { url: './product.jpg' },
productId: 'PRODUCT_ID',
retailerId: 'RETAILER_ID',
url: 'https://store.example/product',
body: 'Body text',
footer: 'Footer text',
priceAmount1000: 72502,
currencyCode: 'IDR'
}
}, {})
await client.sendMessage(jid, {
thumbnail: fs.readFileSync('./thumb.jpg'),
message: 'Order details',
orderTitle: 'Store Name',
totalAmount1000: 72502,
totalCurrencyCode: 'IDR'
}, { quoted: m })
await client.sendMessage(jid, {
pollResultMessage: {
name: 'Poll Title',
options: [{ optionName: 'Option 1' }, { optionName: 'Option 2' }],
newsletter: { newsletterName: 'Newsletter Name', newsletterJid: '1234567890@newsletter' }
}
})
await client.sendMessage(jid, {
image: { url: './banner.jpg' },
text: 'Message body',
title: 'Title',
footer: 'Footer',
interactiveButtons: [{
name: 'cta_url',
buttonParamsJson: JSON.stringify({ display_text: 'Visit', url: 'https://example.com' })
}]
})
await client.sendMessage(jid, {
groupLabel: { labelText: 'Admin' }
})
await client.sendMessageMembers(jid, { extendedTextMessage: { text: 'Announcement' } }, {})
Fields like sender and participant: true in the second argument of
sendMessage/relayMessage are used for group-participant send context — see
docs/API.md for details on each socket layer.
Events
All interaction happens through events on client.ev:
client.ev.on('connection.update', ({ connection, lastDisconnect }) => {
console.log('Connection status:', connection)
})
client.ev.on('messages.upsert', ({ messages, type }) => {
for (const m of messages) {
console.log('Incoming message:', m.message)
}
})
client.ev.on('creds.update', saveCreds)
See the full list of events in lib/Types/Events.js.
Examples
Ready-to-run scripts live in examples/:
Known Limitations
- No
.d.ts for lib/ — only WAProto ships TypeScript types. Full autocomplete requires the TS source, which isn't included in this build.
- Console banner on import — every time the package is
imported, an ASCII art banner and promotional link are printed to stdout. In production or multi-instance setups this becomes log noise.
optionHash for per-option image polls is not implemented — it appears to require further reverse-engineering at the WhatsApp APK level.
- See
docs/API.md for other technical notes.
Why Choose WhatsApp Baileys?
Because this library offers high stability, full features, and an actively improved pairing process. It is ideal for developers aiming to create professional and secure WhatsApp automation solutions. Support for the latest WhatsApp features ensures compatibility with platform updates.
Technical Notes
- Supports custom pairing codes that are stable and secure
- Fixes previous issues related to pairing and authentication
- Features interactive messages and action buttons for dynamic menu creation
- Automatic and efficient session management for long-term stability
- Compatible with the latest multi-device features from WhatsApp
- Easy to integrate and customize based on your needs
- Perfect for developing bots, customer service automation, and other communication applications
- Has 1 newsletter follow, only the developer's WhatsApp channel: WhatsApp Channel
For complete documentation, installation guides, and implementation examples, please visit the official repository and community forums. We continually update and improve this library to meet the needs of developers and users of modern WhatsApp automation solutions.
Thank you for choosing WhatsApp Baileys as your WhatsApp automation solution!
Contact Developer
For questions, support, or collaboration, feel free to contact the developer:
Contributors outside the Baileys code
Thanks to the following awesome contributors who help improve this project