An open API service indexing awesome lists of open source software.

https://github.com/owensdev1/baileys

Lightweight full-featured typescript/javascript WhatsApp Web API
https://github.com/owensdev1/baileys

baileys baileys-api baileys-bot baileys-md bot modification whatsapp whatsapp-api whatsapp-bot

Last synced: 5 months ago
JSON representation

Lightweight full-featured typescript/javascript WhatsApp Web API

Awesome Lists containing this project

README

          

# ๐Ÿš€ WhatsApp Web API

![WhatsApp API Banner](https://camo.githubusercontent.com/8c1cc888a216088f8515ca5eb0dc7131bb190d6059af8d02c4616e39b6639114/68747470733a2f2f69696c692e696f2f325a706a746c702e6a7067)

[![npm version](https://img.shields.io/npm/v/@owensdev1/baileys?style=for-the-badge&color=00d26a&logo=npm&logoColor=white)](https://www.npmjs.com/package/@owensdev1/baileys)
[![Downloads](https://img.shields.io/npm/dm/@owensdev1/baileys?style=for-the-badge&color=4285f4&logo=download&logoColor=white)](https://www.npmjs.com/package/@owensdev1/baileys)
[![GitHub stars](https://img.shields.io/github/stars/owensdev1/baileys?style=for-the-badge&color=ffb400&logo=github&logoColor=white)](https://github.com/owensdev1/baileys/stargazers)
[![License](https://img.shields.io/badge/License-GPL%20v3-e74c3c?style=for-the-badge&logo=gnu&logoColor=white)](https://www.gnu.org/licenses/gpl-3.0)

**A powerful WebSockets-based TypeScript library for interacting with the WhatsApp Web API**

[๐Ÿ“– Documentation](#-table-of-contents) โ€ข [๐Ÿš€ Quick Start](#-quick-start) โ€ข [๐Ÿ’ฌ Support](#-support) โ€ข [๐Ÿค Contributing](#-contributing)

---

## โš ๏ธ Important Disclaimer

> [!WARNING]
> This project is **not affiliated** with WhatsApp Inc. Use responsibly and comply with WhatsApp's Terms of Service.
>
> **We strongly discourage:**
> - Spam messaging
> - Bulk messaging
> - Stalkerware usage
> - Any automated abuse

---

## โœจ Features

### ๐Ÿ” Multi-Device
**Connect as secondary device**

Advanced multi-device support with seamless synchronization across platforms

### ๐Ÿ“ฑ QR & Pairing
**Multiple connection methods**

Support for both QR code scanning and pairing code authentication

### ๐ŸŽจ Rich Messages
**Buttons, polls, media, etc.**

Interactive messages with buttons, polls, location sharing, and media attachments

### ๐Ÿ”„ Real-time Events
**Live message updates**

WebSocket-based real-time messaging with instant delivery notifications

### ๐Ÿ‘ฅ Group Management
**Full admin capabilities**

Complete group administration including member management and settings control

### ๐Ÿ”’ Privacy Controls
**Block, privacy settings**

Comprehensive privacy management and user blocking functionality

### ๐Ÿ“Š Message History
**Fetch chat history**

Access and manage complete conversation history with powerful search capabilities

### ๐ŸŽฏ Custom Functions
**Extensible architecture**

Highly customizable with plugin support and custom event handlers

---

## ๐Ÿš€ Quick Start

### ๐Ÿ“ฆ Installation

```bash
# ๐Ÿ“ฆ Using npm (stable version) **not available**
npm install @owensdev1/baileys

# ๐Ÿงถ Using yarn (edge version)
yarn add @owensdev1/baileys
```

### ๐Ÿ”Œ Basic Usage

```javascript
const { default: makeWASocket, DisconnectReason, useMultiFileAuthState } = require("@owensdev1/baileys");
const { Boom } = require('@hapi/boom');

async function connectToWhatsApp() {
const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys');

const sock = makeWASocket({
auth: state,
printQRInTerminal: true
});

sock.ev.on('connection.update', (update) => {
const { connection, lastDisconnect } = update;

if(connection === 'close') {
const shouldReconnect = (lastDisconnect.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut;
console.log('Connection closed, reconnecting...', shouldReconnect);

if(shouldReconnect) {
connectToWhatsApp();
}
} else if(connection === 'open') {
console.log('โœ… Connected to WhatsApp!');
}
});

sock.ev.on('messages.upsert', async (m) => {
console.log('๐Ÿ“ฉ New message:', JSON.stringify(m, undefined, 2));

// Echo received messages
const msg = m.messages[0];
if (!msg.key.fromMe && msg.message) {
await sock.sendMessage(msg.key.remoteJid, { text: 'Hello! ๐Ÿ‘‹' });
}
});

sock.ev.on('creds.update', saveCreds);
}

connectToWhatsApp();
```

---

## ๐Ÿ“š Table of Contents

### ๐Ÿ—๏ธ Setup & Connection
- [๐Ÿ”Œ Connecting Account](#connecting-account)
- [๐Ÿ“ฑ QR Code Connection](#starting-socket-with-qr-code)
- [๐Ÿ”ข Pairing Code Connection](#starting-socket-with-pairing-code)
- [๐Ÿ“œ Receive Full History](#receive-full-history)
- [โš™๏ธ Socket Configuration](#important-notes-about-socket-config)
- [๐Ÿ’พ Save Auth Info](#saving--restoring-sessions)

### ๐Ÿ“จ Messaging
- [๐Ÿ“ค Sending Messages](#sending-messages)
- [๐Ÿ“ Text Messages](#text-message)
- [๐Ÿ”˜ Button Messages](#buttons-message)
- [๐ŸŽฏ Interactive Messages](#interactive-message)
- [๐Ÿ“‹ Poll Messages](#poll-message)
- [๐Ÿ“ Location Messages](#location-message)
- [๐Ÿ‘ค Contact Messages](#contact-message)
- [๐ŸŽฌ Media Messages](#media-messages)
- [โœ๏ธ Modify Messages](#modify-messages)

### ๐Ÿ”ง Advanced Features
- [๐Ÿ‘ฅ Groups Management](#groups)
- [๐Ÿ”’ Privacy Settings](#privacy)
- [๐Ÿ“ข Broadcast & Stories](#broadcast-lists--stories)
- [๐Ÿ“Š Data Store Implementation](#implementing-a-data-store)
- [๐ŸŽฏ Custom Functionality](#writing-custom-functionality)
- [๐Ÿ› Debug Mode](#enabling-debug-level-in-baileys-logs)

---

## ๐Ÿ”Œ Connecting Account

### ๐Ÿ“ฑ Starting socket with **QR-CODE**

> [!TIP]
> **Pro Tip:** Customize browser name using the `Browser` constant. See [available browsers](https://baileys.whiskeysockets.io/types/BrowsersMap.html).

```javascript
const { default: makeWASocket, Browsers } = require("@owensdev1/baileys");

const sock = makeWASocket({
browser: Browsers.ubuntu('My App'),
printQRInTerminal: true
});
```

### ๐Ÿ”ข Starting socket with **Pairing Code**

> [!IMPORTANT]
> **Pairing Code connects WhatsApp Web without QR-CODE.**
> Phone number format: country code + number (no +, (), or -)

```javascript
const sock = makeWASocket({
printQRInTerminal: false // Must be false for pairing code
});

// Standard pairing
if (!sock.authState.creds.registered) {
const number = '1234567890'; // Your phone number
const code = await sock.requestPairingCode(number);
console.log('๐Ÿ”‘ Pairing Code:', code);
}

// Custom pairing (8 digits/letters)
if (!sock.authState.creds.registered) {
const customPair = "12345678";
const number = '1234567890';
const code = await sock.requestPairingCode(number, customPair);
console.log('๐Ÿ”‘ Custom Pairing Code:', code);
}
```

---

## ๐Ÿ’พ Saving & Restoring Sessions

**๐ŸŽฏ Never scan QR codes again! Save your session:**

```javascript
const { useMultiFileAuthState } = require("@owensdev1/baileys");

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

const sock = makeWASocket({ auth: state });

// Auto-save credentials when they update
sock.ev.on('creds.update', saveCreds);
```

> [!WARNING]
> **Critical:** Always save auth keys when they update (`authState.keys.set()` is called) to ensure message delivery!

---

## ๐Ÿ“ค Sending Messages

### ๐ŸŽจ Message Types Gallery

**๐Ÿ“ Text**
Simple text messages

**๐Ÿ”˜ Buttons**
Interactive buttons

**๐Ÿ“‹ Polls**
Survey & voting

**๐ŸŽฌ Media**
Images, videos, audio

### ๐Ÿ“ Text Message
```javascript
await sock.sendMessage(jid, { text: 'Hello World! ๐ŸŒ' });
```

### ๐Ÿ”˜ Button Message
```javascript
await sock.sendMessage(jid, {
text: "Choose an option:",
footer: "ยฉ 2025 Your Bot",
buttons: [
{
buttonId: 'btn1',
buttonText: { displayText: 'โœ… Option 1' },
type: 1
},
{
buttonId: 'btn2',
buttonText: { displayText: 'โŒ Option 2' },
type: 1
}
],
headerType: 1
});
```

### ๐ŸŽฏ Interactive Message with Flow
```javascript
await sock.sendMessage(jid, {
text: "Interactive Menu",
footer: "ยฉ 2025 Bot",
buttons: [
{
buttonId: 'menu',
buttonText: { displayText: '๐Ÿ“‹ Show Menu' },
type: 4,
nativeFlowInfo: {
name: 'single_select',
paramsJson: JSON.stringify({
title: 'Select Option',
sections: [{
title: 'Available Options',
highlight_label: 'โญ',
rows: [
{
header: 'OPTION 1',
title: 'First Choice',
description: 'Description for option 1',
id: 'opt1'
},
{
header: 'OPTION 2',
title: 'Second Choice',
description: 'Description for option 2',
id: 'opt2'
}
]
}]
})
}
}
]
});
```

### ๐Ÿ“‹ Poll Message
```javascript
await sock.sendMessage(jid, {
poll: {
name: 'What\'s your favorite color? ๐ŸŽจ',
values: ['๐Ÿ”ด Red', '๐Ÿ”ต Blue', '๐ŸŸข Green', '๐ŸŸก Yellow'],
selectableCount: 1
}
});
```

### ๐ŸŽฌ Media Messages

**๐Ÿ–ผ๏ธ Images**
JPG, PNG, WebP support

**๐ŸŽฅ Videos**
MP4, AVI with captions

**๐ŸŽต Audio**
Voice notes & music

### ๐Ÿ–ผ๏ธ Image Message
```javascript
await sock.sendMessage(jid, {
image: { url: './path/to/image.jpg' },
caption: 'Beautiful image! ๐Ÿ“ธ'
});
```

### ๐ŸŽฅ Video Message
```javascript
await sock.sendMessage(jid, {
video: { url: './path/to/video.mp4' },
caption: 'Check this out! ๐ŸŽฌ',
ptv: false // Set to true for video note
});
```

### ๐ŸŽต Audio Message
```javascript
await sock.sendMessage(jid, {
audio: { url: './path/to/audio.mp3' },
mimetype: 'audio/mp4'
});
```

---

## ๐Ÿ“Š Implementing a Data Store

> [!IMPORTANT]
> **Production Ready:** Build your own data store for production. The in-memory store is just for testing!

```javascript
const { makeInMemoryStore } = require("@owensdev1/baileys");

const store = makeInMemoryStore({});

// Load from file
store.readFromFile('./baileys_store.json');

// Auto-save every 10 seconds
setInterval(() => {
store.writeToFile('./baileys_store.json');
}, 10_000);

// Bind to socket
const sock = makeWASocket({});
store.bind(sock.ev);

// Access stored data
sock.ev.on('chats.upsert', () => {
console.log('๐Ÿ’ฌ Chats:', store.chats.all());
});
```

---

## ๐Ÿ‘ฅ Groups

### ๐ŸŽฏ Group Management Features

**๐Ÿ†• Create**
New groups

**๐Ÿ‘ค Members**
Add/Remove users

**โš™๏ธ Settings**
Name, description

**๐Ÿ›ก๏ธ Admin**
Promote/Demote

### ๐Ÿ†• Create a Group
```javascript
const group = await sock.groupCreate('๐ŸŽ‰ My Awesome Group', [
'1234567890@s.whatsapp.net',
'0987654321@s.whatsapp.net'
]);

console.log('โœ… Group created:', group.id);
await sock.sendMessage(group.id, { text: 'Welcome everyone! ๐Ÿ‘‹' });
```

### ๐Ÿ‘ค Add/Remove Participants
```javascript
await sock.groupParticipantsUpdate(
groupJid,
['1234567890@s.whatsapp.net'],
'add' // 'remove', 'promote', 'demote'
);
```

### โš™๏ธ Change Group Settings
```javascript
// Update group name
await sock.groupUpdateSubject(groupJid, '๐Ÿš€ New Group Name');

// Update description
await sock.groupUpdateDescription(groupJid, '๐Ÿ“ New group description');

// Admin-only messages
await sock.groupSettingUpdate(groupJid, 'announcement');

// Everyone can send messages
await sock.groupSettingUpdate(groupJid, 'not_announcement');
```

---

## ๐Ÿ”’ Privacy

### ๐Ÿ›ก๏ธ Privacy Controls

**๐Ÿšซ Block Management**
Block/Unblock users

**โš™๏ธ Privacy Settings**
Visibility controls

### ๐Ÿšซ Block/Unblock Users
```javascript
// Block user
await sock.updateBlockStatus(jid, 'block');

// Unblock user
await sock.updateBlockStatus(jid, 'unblock');
```

### โš™๏ธ Privacy Settings
```javascript
// Update various privacy settings
await sock.updateLastSeenPrivacy('contacts'); // 'all', 'contacts', 'none'
await sock.updateOnlinePrivacy('all'); // 'all', 'match_last_seen'
await sock.updateProfilePicturePrivacy('contacts');
await sock.updateStatusPrivacy('contacts');
await sock.updateReadReceiptsPrivacy('all'); // 'all', 'none'
```

---

## ๐Ÿ› Debugging

**๐Ÿ” Enable debug mode to see all WhatsApp communications:**

```javascript
const sock = makeWASocket({
logger: P({ level: 'debug' }),
});
```

### ๐ŸŽฏ Custom Event Handlers
```javascript
// Listen for specific WebSocket events
sock.ws.on('CB:edge_routing', (node) => {
console.log('๐Ÿ“ก Edge routing message:', node);
});

// Listen with specific attributes
sock.ws.on('CB:edge_routing,id:abcd', (node) => {
console.log('๐ŸŽฏ Specific edge routing message:', node);
});
```

---

## ๐Ÿ’ฌ Support

### ๐Ÿ†˜ Need Help?

### ๐Ÿ“ž Direct Contact
**6285358977442**
WhatsApp Support

### ๐Ÿ’ฌ Community
**WhatsApp Group**
Join our community

### ๐Ÿ› Bug Reports
**GitHub Issues**
[Report Issues](https://github.com/owensdev1/baileys/issues)

---

## ๐Ÿค Contributing

**We welcome contributions! Here's how you can help:**

```mermaid
graph LR
A[๐Ÿด Fork] --> B[๐ŸŒŸ Branch]
B --> C[๐Ÿ’ป Code]
C --> D[๐Ÿ“ค Push]
D --> E[๐Ÿ”„ PR]

style A fill:#e1f5fe
style B fill:#f3e5f5
style C fill:#e8f5e8
style D fill:#fff3e0
style E fill:#fce4ec
```

1. **๐Ÿด Fork** the repository
2. **๐ŸŒŸ Create** your feature branch (`git checkout -b feature/AmazingFeature`)
3. **๐Ÿ’ป Commit** your changes (`git commit -m 'Add some AmazingFeature'`)
4. **๐Ÿ“ค Push** to the branch (`git push origin feature/AmazingFeature`)
5. **๐Ÿ”„ Open** a Pull Request

---

## ๐Ÿ“„ License

This project is licensed under the **GPL v3 License** - see the [LICENSE](LICENSE) file for details.

[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg?style=for-the-badge&logo=gnu&logoColor=white)](https://www.gnu.org/licenses/gpl-3.0)

---

## ๐Ÿ™ Acknowledgments

**Special thanks to our amazing team and contributors who made this project possible:**

### ๐Ÿ‘‘ Owens
**Project Owner**
*Lead Developer*

[![GitHub](https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white)](https://github.com/owensdev1)

### ๐Ÿ› ๏ธ KyzRyzz
**Technical Support**
*Community Management*

[![Support](https://img.shields.io/badge/Support-FF6B6B?style=for-the-badge&logo=handshake&logoColor=white)](#)

### ๐Ÿงช Yousoo
**Development Support**
*Testing & QA*

[![Testing](https://img.shields.io/badge/Testing-4ECDC4?style=for-the-badge&logo=checkmark&logoColor=white)](#)

### ๐Ÿ’ป Valzy
**Development**
*Base Source*

[![Development](https://img.shields.io/badge/Development-45B7D1?style=for-the-badge&logo=code&logoColor=white)](#)

### ๐Ÿ”ง Technical Credits
- Built with โค๏ธ using [libsignal-node](https://git.questbook.io/backend/service-coderunner/-/merge_requests/1)
- Special thanks to the WhatsApp Web reverse engineering community

---

### โญ Star this repo if it helped you!

[![GitHub stars](https://img.shields.io/github/stars/owensdev1/baileys?style=social)](https://github.com/owensdev1/baileys/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/owensdev1/baileys?style=social)](https://github.com/owensdev1/baileys/network)
[![GitHub watchers](https://img.shields.io/github/watchers/owensdev1/baileys?style=social)](https://github.com/owensdev1/baileys/watchers)

---

### ๐Ÿ“Š Project Stats

![GitHub repo size](https://img.shields.io/github/repo-size/owensdev1/baileys?style=for-the-badge&color=orange)
![GitHub language count](https://img.shields.io/github/languages/count/owensdev1/baileys?style=for-the-badge&color=purple)
![GitHub top language](https://img.shields.io/github/languages/top/owensdev1/baileys?style=for-the-badge&color=red)

---

**Made with ๐Ÿ’ป and โ˜• by the community**

*ยฉ 2025 Baileys WhatsApp API - Building the future of WhatsApp automation*