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
- Host: GitHub
- URL: https://github.com/owensdev1/baileys
- Owner: owensdev1
- License: mit
- Created: 2025-05-16T05:45:15.000Z (8 months ago)
- Default Branch: master
- Last Pushed: 2025-08-12T03:00:32.000Z (5 months ago)
- Last Synced: 2025-08-12T04:20:15.075Z (5 months ago)
- Topics: baileys, baileys-api, baileys-bot, baileys-md, bot, modification, whatsapp, whatsapp-api, whatsapp-bot
- Language: JavaScript
- Homepage: https://latribu.ci/ows/
- Size: 1.02 MB
- Stars: 3
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
README
# ๐ WhatsApp Web API

[](https://www.npmjs.com/package/@owensdev1/baileys)
[](https://www.npmjs.com/package/@owensdev1/baileys)
[](https://github.com/owensdev1/baileys/stargazers)
[](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.
[](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*
[](https://github.com/owensdev1)
### ๐ ๏ธ KyzRyzz
**Technical Support**
*Community Management*
[](#)
### ๐งช Yousoo
**Development Support**
*Testing & QA*
[](#)
### ๐ป Valzy
**Development**
*Base Source*
[](#)
### ๐ง 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!
[](https://github.com/owensdev1/baileys/stargazers)
[](https://github.com/owensdev1/baileys/network)
[](https://github.com/owensdev1/baileys/watchers)
---
### ๐ Project Stats



---
**Made with ๐ป and โ by the community**
*ยฉ 2025 Baileys WhatsApp API - Building the future of WhatsApp automation*