# <div align='center'>Baileys - Typescript/Javascript WhatsApp Web API</div>

<p align="center">
  <img src="https://img2.pixhost.to/images/9521/751472173_alan.jpg" alt="Thumbnail" />
</p>

<div align='center'>

![GitHub Downloads (all assets, all releases)](https://img.shields.io/github/downloads/whiskeysockets/baileys/total)
![NPM Downloads](https://img.shields.io/npm/dw/%40whiskeysockets%2Fbaileys?label=npm&color=%23CB3837)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/whiskeysockets/baileys)
![GitHub License](https://img.shields.io/github/license/whiskeysockets/baileys)
![Discord](https://img.shields.io/discord/725839806084546610?label=discord&color=%235865F2)
![GitHub Repo stars](https://img.shields.io/github/stars/whiskeysockets/baileys)
![GitHub forks](https://img.shields.io/github/forks/whiskeysockets/baileys)

</div>

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](#requirements)
- [Install](#install)
- [Quick Start](#quick-start)
  - [QR Code login](#login-with-qr-code)
  - [Pairing Code login](#login-with-pairing-code)
- [Store](#store)
- [Sending Messages](#sending-messages)
  - [Generic send / relay](#generic-send--relay)
  - [Simple senders](#simple-senders)
  - [Special message types](#special-message-types)
- [Events](#events)
- [Examples](#examples)
- [Known Limitations](#known-limitations)
- [Why Choose WhatsApp Baileys?](#why-choose-whatsapp-baileys?)
- [Technical Notes](#technical-notes)
- [Contact Developer](#contact-developer)
- [Contributors](#contributors-outside-the-baileys-code)

## 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

```bash
npm install @alannxd/baileys
```

Or alias it as `baileys` / `@whiskeysockets/baileys` in your `package.json`:

```json
{
  "dependencies": {
    "@alannxd/baileys": "latest"
  }
}
```

```js
import makeWASocket from '@alannxd/baileys'
// or, CommonJS:
const { default: makeWASocket } = require('@alannxd/baileys')
```

## Quick Start

### Login with QR Code

```js
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

```js
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' // international format, no '+'
  const code = await client.requestPairingCode(phoneNumber)
  // custom pairing code (8 characters):
  // const code = await client.requestPairingCode(phoneNumber, 'YYYYYYYY')
  console.log('Pairing code:', code)
}
```

## Store

`makeInMemoryStore` builds a local cache of chats/contacts/messages, which
Baileys does not persist automatically by default.

```js
import makeWASocket, { makeInMemoryStore } from '@alannxd/baileys'
import pino from 'pino'

const store = makeInMemoryStore({
  logger: pino().child({ level: 'silent', stream: 'store' })
})

const client = makeWASocket({ /* ...other options */ })
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](docs/API.md#store-libstore).

### 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:

```js
const store = makeInMemoryStore({ /* ... */ })

// load once on startup, then auto-save every 10s
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](docs/API.md#file-persistence-makeinmemorystore) for details.

## Sending Messages

### Generic send / relay

```js
// relayMessage — send a raw message object, bypassing the sendMessage pipeline
await client.relayMessage(jid, { conversation: 'Hello from Baileys' }, {})

// sendMessage — the common way to send a message
await client.sendMessage(jid, { text: 'Hello from Baileys' })
```

### Simple senders

All the `sendX` functions below are shortcuts on top of `sendMessage`.

```js
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'], /* multiSelect */ true)
await client.sendQuiz(jid, 'Correct answer?', ['1', '2', '3'], /* correctIndex */ '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.

```js
// Product message (catalog)
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, // price x 1000
    currencyCode: 'IDR'
  }
}, {})

// Order message
await client.sendMessage(jid, {
  thumbnail: fs.readFileSync('./thumb.jpg'),
  message: 'Order details',
  orderTitle: 'Store Name',
  totalAmount1000: 72502,
  totalCurrencyCode: 'IDR'
}, { quoted: m })

// Poll result snapshot (usually from a newsletter)
await client.sendMessage(jid, {
  pollResultMessage: {
    name: 'Poll Title',
    options: [{ optionName: 'Option 1' }, { optionName: 'Option 2' }],
    newsletter: { newsletterName: 'Newsletter Name', newsletterJid: '1234567890@newsletter' }
  }
})

// Interactive message (button)
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' })
  }]
})

// Group member label
await client.sendMessage(jid, {
  groupLabel: { labelText: 'Admin' }
})

// Broadcast to specific group members
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`](docs/API.md) for details on each socket layer.

## Events

All interaction happens through events on `client.ev`:

```js
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/`](examples):

- [`examples/qr-login.js`](examples/qr-login.js) — QR login with auto-reconnect
- [`examples/pairing-code.js`](examples/pairing-code.js) — pairing code login
- [`examples/store-usage.js`](examples/store-usage.js) — using the in-memory store

## 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 `import`ed, 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`](docs/API.md#️-important-notes) 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](https://whatsapp.com/channel/0029Vb3IiqTL7UVP9A9n0w1x)

---

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:

- **Telegram**: [Telegram Contact](https://t.me/alannxd)
- **Channel WhatsApp**: [Channel WhatsApp](https://whatsapp.com/channel/0029Vb3IiqTL7UVP9A9n0w1x) 

### Contributors outside the Baileys code

Thanks to the following awesome contributors who help improve this project

<table>
  <tr>
    <td align="center">
      <a href="https://github.com/alannzxd">
        <img src="https://github.com/alannzxd.png" width="80px;" style="border-radius:50%;" alt="Developer"/>
        <br />
        <sub><b>AlannXD</b></sub>
      </a>
    </td>
    <td align="center">
      <a href="https://github.com/Xazepysk">
        <img src="https://github.com/XazepysK.png" width="80px;" style="border-radius:50%;" alt="Contributor"/>
        <br /><sub><b>Xaz zepysK</b></sub>
      </a>
    </td>
<td align="center">
      <a href="https://github.com/kiuur">
        <img src="https://github.com/kiuur.png" width="80px;" style="border-radius:50%;" alt="Contributor"/>
        <br />
        <sub><b>KyuuRzy</b></sub>
      </a>
    </td>
    <td align="center">
      <a href="https://github.com/Xcoursed">
        <img src="https://github.com/Xcoursed.png" width="80px;" style="border-radius:50%;" alt="Contributor"/>
        <br />
        <sub><b>Xcoursed</b></sub>
      </a>
    </td>
  </tr>
</table>