Skip to content

owensdev1/baileys

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ WhatsApp Web API

WhatsApp API Banner

npm version Downloads GitHub stars License

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

πŸ“– Documentation β€’ πŸš€ Quick Start β€’ πŸ’¬ Support β€’ 🀝 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

# πŸ“¦ Using npm (stable version) **not available**
npm install @owensdev1/baileys

# 🧢 Using yarn (edge version)
yarn add @owensdev1/baileys

πŸ”Œ Basic Usage

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();


πŸ”Œ Connecting Account

πŸ“± Starting socket with QR-CODE

[!TIP] Pro Tip: Customize browser name using the Browser constant. See available browsers.

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

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:

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

await sock.sendMessage(jid, { text: 'Hello World! 🌍' });

πŸ”˜ Button Message

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

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

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

await sock.sendMessage(jid, {
    image: { url: './path/to/image.jpg' },
    caption: 'Beautiful image! πŸ“Έ'
});

πŸŽ₯ Video Message

await sock.sendMessage(jid, {
    video: { url: './path/to/video.mp4' },
    caption: 'Check this out! 🎬',
    ptv: false // Set to true for video note
});

🎡 Audio Message

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!

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

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

await sock.groupParticipantsUpdate(
    groupJid,
    ['1234567890@s.whatsapp.net'],
    'add' // 'remove', 'promote', 'demote'
);

βš™οΈ Change Group Settings

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

// Block user
await sock.updateBlockStatus(jid, 'block');

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

βš™οΈ Privacy Settings

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

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

🎯 Custom Event Handlers

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


🀝 Contributing

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

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
Loading
  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 file for details.

License: GPL v3


πŸ™ Acknowledgments

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

πŸ‘‘ Owens

Project Owner
Lead Developer

GitHub

πŸ› οΈ KyzRyzz

Technical Support
Community Management

Support

πŸ§ͺ Yousoo

Development Support
Testing & QA

Testing

πŸ’» Valzy

Development
Base Source

Development

πŸ”§ Technical Credits

  • Built with ❀️ using libsignal-node
  • Special thanks to the WhatsApp Web reverse engineering community

⭐ Star this repo if it helped you!

GitHub stars GitHub forks GitHub watchers


πŸ“Š Project Stats

GitHub repo size GitHub language count GitHub top language


Made with πŸ’» and β˜• by the community

Β© 2025 Baileys WhatsApp API - Building the future of WhatsApp automation

About

Lightweight full-featured typescript/javascript WhatsApp Web API

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published