npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

zenzxz

v0.0.8

Published

WhatsApp Web API Library

Readme

zenzxz/baileys

npm version License Downloads

💝 Donation

Support the development of this project:

Solana Address:

8xN639anSq5q64793tseCjPaXNgXEPaKxr91CKEuggKd

zenzxz/baileys is a modern WebSocket-based TypeScript library for interacting with the WhatsApp Web API. This library has been enhanced to address issues with WhatsApp group @lid and @jid handling, ensuring robust performance.

✨ Key Features

  • 🚀 Modern & Fast - Built with TypeScript and cutting-edge technologies
  • 🔧 Fixed @lid & @jid - Resolved WhatsApp group @lid to @pn` issues
  • 📱 Multi-Device Support - Supports WhatsApp multi-device connections
  • 🔐 End-to-End Encryption - Fully encrypted communications
  • 📨 All Message Types - Supports all message types (text, media, polls, etc.)
  • 🎯 Easy to Use - Simple and intuitive API

⚠️ Disclaimer

This project is not affiliated, associated, authorized, endorsed by, or in any way officially connected with WhatsApp or any of its subsidiaries or affiliates. The official WhatsApp website can be found at whatsapp.com.

The maintainers of zenzxz/baileys do not condone the use of this application in practices that violate WhatsApp's Terms of Service. We urge users to exercise personal responsibility and use this application fairly and responsibly.

Use wisely. Avoid spamming. Refrain from excessive automated usage.

📦 Installation

Stable Version (Recommended)

npm i zenzxz/baileys

Edge Version (Latest Features)

npm i zenzxz/baileys@latest
# or
yarn add zenzxz/baileys@latest

Import in Code

const { default: makeWASocket } = require("zenzxz/baileys")
// or ES6
import makeWASocket from "zenzxz/baileys"

🚀 Quick Start

Example

Here is an example you can use: example.ts or follow this tutorial to run the zenzxz/baileys WhatsApp API code:

  1. cd path/to/zenzxz/baileys
  2. npm install
  3. node example.js

Basic Example

const { default: makeWASocket, DisconnectReason, useMultiFileAuthState } = require('zenzxz/baileys')
const { Boom } = require('@hapi/boom')

async function connectToWhatsApp() {
    const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
    
    const sock = makeWASocket({
        auth: state,
        printQRInTerminal: true,
        browser: ['zenzxz/baileys', 'Desktop', '3.0']
    })

    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 due to ', lastDisconnect.error, ', reconnecting ', shouldReconnect)
            if(shouldReconnect) {
                connectToWhatsApp()
            }
        } else if(connection === 'open') {
            console.log('✅ Successfully connected to WhatsApp!')
        }
    })

    sock.ev.on('messages.upsert', async ({ messages }) => {
        for (const m of messages) {
            if (!m.message) continue
            
            console.log('📱 New message:', JSON.stringify(m, undefined, 2))
            
            // Auto reply
            await sock.sendMessage(m.key.remoteJid!, { 
                text: 'Hello! I am a WhatsApp bot using zenzxz/baileys 🤖' 
            })
        }
    })

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

connectToWhatsApp()

Index

Connecting Account

WhatsApp provides a multi-device API that allows zenzxz/baileys to authenticate as a secondary WhatsApp client via QR code or pairing code.

Starting Socket with QR Code

[!TIP] Customize the browser name using the Browsers constant. See available configurations here.

const { default: makeWASocket, Browsers } = require("zenzxz/baileys")

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

Upon successful connection, a QR code will be printed in the terminal. Scan it with WhatsApp on your phone to log in.

Starting Socket with Pairing Code

[!IMPORTANT] Pairing codes are not part of the Mobile API. They allow connecting WhatsApp Web without a QR code, but only one device can be connected. See WhatsApp FAQ.

Phone numbers must exclude +, (), or -, and include the country code.

const { default: makeWASocket } = require("zenzxz/baileys")

const sock = makeWASocket({
    printQRInTerminal: false
})

// Normal Pairing
if (!sock.authState.creds.registered) {
    const number = '6285134816783'
    const code = await sock.requestPairingCode(number)
    console.log('🔑 Pairing Code:', code)
}

// Custom Pairing
if (!sock.authState.creds.registered) {
    const pair = "YP240125" // 8 characters
    const number = '6285134816783'
    const code = await sock.requestPairingCode(number, pair)
    console.log('🔑 Custom Pairing Code:', code)
}

Receive Full History

  1. Set syncFullHistory to true.
  2. By default, zenzxz/baileys uses Chrome browser config. For desktop-like connections (to receive more message history), use:
const { default: makeWASocket, Browsers } = require("zenzxz/baileys")

const sock = makeWASocket({
    browser: Browsers.macOS('Desktop'),
    syncFullHistory: true
})

Important Notes About Socket Config

Caching Group Metadata (Recommended)

For group usage, implement caching for group metadata:

const { default: makeWASocket } = require("zenzxz/baileys")
const NodeCache = require('node-cache')

const groupCache = new NodeCache({ stdTTL: 5 * 60, useClones: false })

const sock = makeWASocket({
    cachedGroupMetadata: async (jid) => groupCache.get(jid)
})

sock.ev.on('groups.update', async ([event]) => {
    const metadata = await sock.groupMetadata(event.id)
    groupCache.set(event.id, metadata)
})

sock.ev.on('group-participants.update', async (event) => {
    const metadata = await sock.groupMetadata(event.id)
    groupCache.set(event.id, metadata)
})

Improve Retry System & Decrypt Poll Votes

Enhance message sending and poll vote decryption with a store:

const sock = makeWASocket({
    getMessage: async (key) => await getMessageFromStore(key)
})

Receive Notifications in WhatsApp App

Disable online status to receive notifications:

const sock = makeWASocket({
    markOnlineOnConnect: false
})

Saving & Restoring Sessions

Avoid rescanning QR codes by saving credentials:

const makeWASocket = require("zenzxz/baileys").default
const { useMultiFileAuthState } = require("zenzxz/baileys")

async function connect() {
    const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
    const sock = makeWASocket({ auth: state })
    sock.ev.on('creds.update', saveCreds)
}

connect()

[!IMPORTANT] useMultiFileAuthState saves auth state in a folder. For production, use SQL/no-SQL databases and carefully manage key updates.

Handling Events

zenzxz/baileys uses EventEmitter for events, fully typed for IDE support.

[!IMPORTANT] See all events here.

const sock = makeWASocket()
sock.ev.on('messages.upsert', ({ messages }) => {
    console.log('Got messages:', messages)
})

Example to Start

const makeWASocket = require("zenzxz/baileys").default
const { DisconnectReason, useMultiFileAuthState } = require("zenzxz/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 due to ', lastDisconnect.error, ', reconnecting ', shouldReconnect)
            if(shouldReconnect) {
                connectToWhatsApp()
            }
        } else if(connection === 'open') {
            console.log('Opened connection')
        }
    })

    sock.ev.on('messages.upsert', async ({ messages }) => {
        for (const m of messages) {
            console.log(JSON.stringify(m, undefined, 2))
            console.log('Replying to', m.key.remoteJid)
            await sock.sendMessage(m.key.remoteJid!, { text: 'Hello World' })
        }
    })

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

connectToWhatsApp()

License

Distributed under the GPL-3.0 License. See LICENSE for more information.

Acknowledgments


Fork from baileys modified by zenzxz/baileys

zenzxz/baileys - Modern WhatsApp Web API with Fixed @lid To @pn