Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

@chatunity/baileytest

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chatunity/baileytest

whatsapp api multidevice by ChatUnity

latest
npmnpm
Version
1.4.2
Version published
Maintainers
1
Created
Source

ChatUnity Baileys

TypeScript & Node.js WhatsApp Web API

Header Image

NPM Downloads Latest Release Code Size License Stars Forks

Lightweight WhatsApp Web API • No Selenium • WebSocket-based • Multi-device Support

Based on @itsukichann's original work

🎯 Why Baileys?

Baileys connects to WhatsApp Web using WebSockets instead of Selenium/Chromium, saving ~500MB of RAM [web:8]. It supports both multi-device and web versions of WhatsApp with full TypeScript support.

[!IMPORTANT]
The original repository was removed by the main author. Development continues officially in this community-maintained version.

📦 Installation

# Stable version
yarn add @chatunitycenter/baileys

# Edge version (latest features)
yarn add github:chatunitycenter/baileys
import makeWASocket from '@chatunitycenter/baileys'

🚀 Quick Start

📱 Connect with QR Code
import makeWASocket, { useMultiFileAuthState, Browsers } from '@chatunitycenter/baileys'

const { state, saveCreds } = await useMultiFileAuthState('./auth_info_baileys')
const sock = makeWASocket({
    auth: state,
    browser: Browsers.ubuntu('ChatUnity'),
    printQRInTerminal: true
})

sock.ev.on('creds.update', saveCreds)
🔢 Connect with Pairing Code

[!NOTE] Phone number format: country code + number (e.g., 393123456789)

import makeWASocket from '@chatunitycenter/baileys'

const sock = makeWASocket({ printQRInTerminal: false })

if (!sock.authState.creds.registered) {
    const number = '393123456789' // Your number
    const code = await sock.requestPairingCode(number)
    console.log(`Pairing code: ${code}`)
}
📜 Receive Full History
const sock = makeWASocket({
    browser: Browsers.macOS('Desktop'),
    syncFullHistory: true
})

⚙️ Configuration

💾 Save & Restore Sessions
import makeWASocket, { useMultiFileAuthState } from '@chatunitycenter/baileys'

const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
const sock = makeWASocket({ auth: state })

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

Alternative storage methods:

  • useSingleFileAuthState - Single JSON file
  • useMongoFileAuthState - MongoDB storage
📊 Cache Group Metadata
import NodeCache from '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)
})
🔔 Receive Phone Notifications
const sock = makeWASocket({
    markOnlineOnConnect: false
})

🎪 Event Handling

📨 Basic Message Handler
import { Boom } from '@hapi/boom'
import makeWASocket, { DisconnectReason } from '@chatunitycenter/baileys'

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
            if(shouldReconnect) connectToWhatsApp()
        } else if(connection === 'open') {
            console.log('Connected!')
        }
    })

    sock.ev.on('messages.upsert', async ({ messages }) => {
        for (const m of messages) {
            console.log('New message:', m.key.remoteJid)
            await sock.sendMessage(m.key.remoteJid!, { text: 'Hello World!' })
        }
    })

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

connectToWhatsApp()

View all events: BaileysEventMap Documentation

🗳️ Decrypt Poll Votes
import { makeInMemoryStore, getAggregateVotesInPollMessage } from '@chatunitycenter/baileys'

const store = makeInMemoryStore({})

sock.ev.on("messages.update", async (updates) => {
    for(const { key, update } of updates) {
        if(update.pollUpdates && key.fromMe) {
            const pollCreation = await store.loadMessage(key.remoteJid, key.id)
            if(pollCreation) {
                const pollUpdate = await getAggregateVotesInPollMessage({
                    message: pollCreation.message,
                    pollUpdates: update.pollUpdates,
                })
                console.log('Poll votes:', pollUpdate)
            }
        }
    }
})

💬 Sending Messages

✉️ Text & Basic Messages
// Simple text
await sock.sendMessage(jid, { text: 'Hello World' })

// With quote
await sock.sendMessage(jid, { text: 'Reply' }, { quoted: message })

// Mention users
await sock.sendMessage(jid, {
    text: '@393123456789',
    mentions: ['393123456789@s.whatsapp.net']
})

// Reaction
await sock.sendMessage(jid, {
    react: { text: '💖', key: message.key }
})

// Location
await sock.sendMessage(jid, {
    location: {
        degreesLatitude: 24.121231,
        degreesLongitude: 55.1121221
    }
})
🎨 Media Messages
// Image
await sock.sendMessage(jid, {
    image: { url: './image.png' },
    caption: 'Beautiful image'
})

// Video
await sock.sendMessage(jid, {
    video: { url: './video.mp4' },
    caption: 'Cool video'
})

// Audio (convert to OGG first)
await sock.sendMessage(jid, {
    audio: { url: './audio.ogg' },
    mimetype: 'audio/ogg; codecs=opus'
})

// GIF
await sock.sendMessage(jid, {
    video: fs.readFileSync('gif.mp4'),
    gifPlayback: true
})

// Album (multiple images/videos)
await sock.sendMessage(jid, {
    album: [
        { image: { url: 'img1.jpg' }, caption: 'Photo 1' },
        { video: { url: 'vid1.mp4' }, caption: 'Video 1' }
    ]
})
🗳️ Interactive Messages
// Poll
await sock.sendMessage(jid, {
    poll: {
        name: 'Favorite color?',
        values: ['Red', 'Blue', 'Green'],
        selectableCount: 1
    }
})

// Buttons
await sock.sendMessage(jid, {
    text: 'Choose an option',
    footer: 'Powered by ChatUnity',
    buttons: [
        { buttonId: 'id1', buttonText: { displayText: 'Option 1' } },
        { buttonId: 'id2', buttonText: { displayText: 'Option 2' } }
    ]
})

// List
await sock.sendMessage(jid, {
    text: 'Select from menu',
    buttonText: 'View Menu',
    sections: [{
        title: 'Section 1',
        rows: [
            { title: 'Option 1', rowId: 'opt1' },
            { title: 'Option 2', rowId: 'opt2', description: 'Description' }
        ]
    }]
})
🎯 Advanced Messages
// Contact card
const vcard = 'BEGIN:VCARD\nVERSION:3.0\nFN:John Doe\nTEL;type=CELL:+393123456789\nEND:VCARD'
await sock.sendMessage(jid, {
    contacts: {
        displayName: 'John',
        contacts: [{ vcard }]
    }
})

// Forward
await sock.sendMessage(jid, { forward: message, force: true })

// Delete message
await sock.sendMessage(jid, { delete: message.key })

// Edit message
await sock.sendMessage(jid, { edit: message.key, text: 'Edited text' })

🔧 Utility Functions

Message Helpers:

  • getContentType(message) - Get message type
  • downloadMediaMessage(message) - Download media content
  • getDevice(message) - Get sender's device info

Full documentation: Baileys Types

📋 WhatsApp ID Format

  • Personal: [country_code][number]@s.whatsapp.net (e.g., 393123456789@s.whatsapp.net)
  • Groups: [group_id]@g.us
  • Channels: [channel_id]@newsletter
  • Broadcast: status@broadcast

📚 Additional Resources

View all documentation sections

⚖️ License & Responsibility

Licensed under MIT License. The developers cannot be held responsible for misuse. Please respect WhatsApp's Terms of Service [web:8].

Credits: Based on the original Baileys library by @itsukichann

Maintained by: ChatUnity Center

Made with ❤️ by the community

```

Keywords

baileys

FAQs

Package last updated on 26 Dec 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts