New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more β†’
Get Started

@ryuhan/baileys

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ryuhan/baileys

πŸ’§ Rimuru Baileys - WhatsApp Multi-Device Library with intelligent @lid/@jid mapping

latest
Source
npmnpm
Version
2.0.2
Version published
Weekly downloads
42
-44.74%
Maintainers
1
Weekly downloads
Β 
Created
Source

Rimuru Bot

πŸ’§ Rimuru Baileys

TypeScript-based WhatsApp Multi-Device Library
With intelligent @lid/@jid mapping and advanced message handling

GitHub Stars GitHub Issues npm Version npm Downloads License

🌟 Features

Core Features

  • πŸ’§ Intelligent @lid and @jid Mapping - Automatic resolution of LID to phone JID
  • πŸ’§ Multi-Device Support - Full support for WhatsApp multi-device protocol
  • πŸ’§ End-to-End Encryption - Complete E2EE support for secure messaging
  • πŸ’§ All Message Types - Support for text, media, polls, reactions, and more
  • πŸ’§ TypeScript Based - Type-safe with modern TypeScript
  • πŸ’§ High Performance - Optimized for speed and efficiency

Advanced Features

  • πŸ’§ Media Handling - Send/receive images, videos, audio, stickers, documents
  • πŸ’§ Pairing Code Login - Easy authentication with custom pairing code "MURUSAMA"
  • πŸ’§ Newsletter/Channel Support - Full support for WhatsApp channels
  • πŸ’§ Group Management - Complete group controls and administration
  • πŸ’§ Story/Broadcast - Send and manage stories and broadcast lists
  • πŸ’§ Business API - Support for WhatsApp Business features
  • πŸ’§ Poll Messages - Create and manage poll messages with vote tracking
  • πŸ’§ Reaction Messages - Send and receive emoji reactions
  • πŸ’§ Pin Messages - Pin important messages in chats
  • πŸ’§ Disappearing Messages - Configure ephemeral messages
  • πŸ’§ Contact Messages - Send vCard contacts
  • πŸ’§ Location Messages - Share live and static locations
  • πŸ’§ Button Messages - Interactive button messages (where supported)
  • πŸ’§ List Messages - Interactive list messages
  • πŸ’§ Template Messages - Pre-defined message templates

Developer Friendly

  • πŸ’§ Clean API - Simple and intuitive API design
  • πŸ’§ Event-Driven - Comprehensive event system for all actions
  • πŸ’§ Auth Storage - Multi-file and single-file auth state options
  • πŸ’§ In-Memory Store - Built-in store for chats, contacts, messages
  • πŸ’§ Customizable - Easy to extend and customize
  • πŸ’§ Well Documented - Comprehensive documentation and examples

πŸ“¦ Installation

npm

npm install @ryuhan/baileys

yarn

yarn add @ryuhan/baileys

pnpm

pnpm add @ryuhan/baileys

πŸš€ Quick Start

Basic Example

import makeWASocket, { DisconnectReason, useMultiFileAuthState } from '@ryuhan/baileys'
import { Boom } from '@hapi/boom'

async function connectToWhatsApp() {
    const { state, saveCreds } = await useMultiFileAuthState('auth_info')
    
    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 to WhatsApp!')
        }
    })

    sock.ev.on('messages.upsert', async ({ messages }) => {
        for (const m of messages) {
            if (!m.message) continue
            console.log('πŸ“± New message:', m.key.remoteJid)
            
            // Reply to message
            await sock.sendMessage(m.key.remoteJid!, { 
                text: 'Hello! I am Rimuru Bot πŸ’§' 
            })
        }
    })

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

connectToWhatsApp()

πŸ” Authentication

import makeWASocket from '@ryuhan/baileys'

const sock = makeWASocket({
    printQRInTerminal: false
})

// Request pairing code
if (!sock.authState.creds.registered) {
    const phoneNumber = '6285134816783' // Your phone number with country code
    const code = await sock.requestPairingCode(phoneNumber, "MURUSAMA")
    console.log('πŸ’§ Pairing Code:', code)
}

QR Code

import makeWASocket, { Browsers } from '@ryuhan/baileys'

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

πŸ“š Common Use Cases

Send Text Message

await sock.sendMessage(jid, { text: 'Hello World! πŸ’§' })

Send Image

await sock.sendMessage(jid, {
    image: { url: './image.jpg' },
    caption: 'Check this out!'
})

Send Video

await sock.sendMessage(jid, {
    video: { url: './video.mp4' },
    caption: 'Amazing video!',
    mimetype: 'video/mp4'
})

Send Audio

await sock.sendMessage(jid, {
    audio: { url: './audio.mp3' },
    mimetype: 'audio/mp4'
})

Send Sticker

await sock.sendMessage(jid, {
    sticker: { url: './sticker.webp' }
})

Send Document

await sock.sendMessage(jid, {
    document: { url: './document.pdf' },
    mimetype: 'application/pdf',
    fileName: 'document.pdf'
})

Send Location

await sock.sendMessage(jid, {
    location: {
        degreesLatitude: -6.2088,
        degreesLongitude: 106.8456
    }
})

Send Contact

const vcard = `BEGIN:VCARD
VERSION:3.0
FN:John Doe
TEL;type=CELL;type=VOICE;waid=6281234567890:+62 812-3456-7890
END:VCARD`

await sock.sendMessage(jid, {
    contacts: {
        displayName: 'John Doe',
        contacts: [{ vcard }]
    }
})

Send Poll

await sock.sendMessage(jid, {
    poll: {
        name: 'Favorite Color?',
        values: ['Red', 'Blue', 'Green'],
        selectableCount: 1
    }
})

Send Reaction

await sock.sendMessage(jid, {
    react: {
        text: 'πŸ’§',
        key: message.key
    }
})

Reply/Quote Message

await sock.sendMessage(jid, {
    text: 'This is a reply'
}, {
    quoted: message
})

Mention Users

await sock.sendMessage(jid, {
    text: 'Hello @6281234567890!',
    mentions: ['6281234567890@s.whatsapp.net']
})

Forward Message

await sock.sendMessage(jid, {
    forward: message
})

Delete Message (For Everyone)

const msg = await sock.sendMessage(jid, { text: 'test' })
await sock.sendMessage(jid, { delete: msg.key })

Edit Message

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

Pin Message

await sock.sendMessage(jid, {
    pin: {
        type: 1, // 1=24h, 2=7d, 3=30d
        time: 86400,
        key: message.key
    }
})

View Once Message

await sock.sendMessage(jid, {
    image: { url: './image.jpg' },
    viewOnce: true
})

πŸ‘₯ Group Management

Create Group

const group = await sock.groupCreate('My Group', ['6281234567890@s.whatsapp.net'])
console.log('Group created:', group.id)

Add Participants

await sock.groupParticipantsUpdate(groupId, ['6281234567890@s.whatsapp.net'], 'add')

Remove Participants

await sock.groupParticipantsUpdate(groupId, ['6281234567890@s.whatsapp.net'], 'remove')

Promote to Admin

await sock.groupParticipantsUpdate(groupId, ['6281234567890@s.whatsapp.net'], 'promote')

Demote Admin

await sock.groupParticipantsUpdate(groupId, ['6281234567890@s.whatsapp.net'], 'demote')

Update Group Name

await sock.groupUpdateSubject(groupId, 'New Group Name')

Update Group Description

await sock.groupUpdateDescription(groupId, 'New Description')

Get Invite Code

const code = await sock.groupInviteCode(groupId)
const inviteLink = 'https://chat.whatsapp.com/' + code

Join Group

await sock.groupAcceptInvite('inviteCode')

Leave Group

await sock.groupLeave(groupId)

πŸ“ž Call Handling

Reject Call

sock.ev.on('call', async (calls) => {
    for (const call of calls) {
        await sock.rejectCall(call.id, call.from)
    }
})

πŸ‘€ User Operations

Check If Number Exists on WhatsApp

const [result] = await sock.onWhatsApp('6281234567890')
if (result?.exists) {
    console.log('Number exists:', result.jid)
}

Get Profile Picture

// Low resolution
const ppUrl = await sock.profilePictureUrl(jid)

// High resolution
const ppUrl = await sock.profilePictureUrl(jid, 'image')

Get Status

const status = await sock.fetchStatus(jid)
console.log('About:', status?.status)

Get Business Profile

const profile = await sock.getBusinessProfile(jid)
console.log('Business:', profile)

πŸ“ Chat Operations

Archive Chat

const lastMsg = await getLastMessage(jid)
await sock.chatModify({ archive: true, lastMessages: [lastMsg] }, jid)

Mute Chat

await sock.chatModify({ mute: 8 * 60 * 60 * 1000 }, jid) // 8 hours

Unmute Chat

await sock.chatModify({ mute: null }, jid)

Mark as Read

await sock.readMessages([message.key])

Delete Chat

await sock.chatModify({ delete: true, lastMessages: [lastMsg] }, jid)

Star Message

await sock.chatModify({
    star: {
        messages: [{ id: 'messageID', fromMe: true }],
        star: true
    }
}, jid)

Disappearing Messages

// Enable
await sock.sendMessage(jid, {
    disappearingMessagesInChat: 7 * 24 * 60 * 60 // 7 days
})

// Disable
await sock.sendMessage(jid, {
    disappearingMessagesInChat: false
})

🎨 Profile Management

Update Profile Name

await sock.updateProfileName('New Name')

Update Profile Status

await sock.updateProfileStatus('New Status πŸ’§')

Update Profile Picture

await sock.updateProfilePicture(jid, { url: './new-pp.jpg' })

Remove Profile Picture

await sock.removeProfilePicture(jid)

πŸ“Š Events

Connection Events

sock.ev.on('connection.update', (update) => {
    console.log('Connection:', update)
})

Message Events

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

sock.ev.on('messages.update', (updates) => {
    console.log('Message updates:', updates)
})

sock.ev.on('messages.delete', (deletes) => {
    console.log('Messages deleted:', deletes)
})

Chat Events

sock.ev.on('chats.upsert', (chats) => {
    console.log('New chats:', chats)
})

sock.ev.on('chats.update', (updates) => {
    console.log('Chat updates:', updates)
})

Contact Events

sock.ev.on('contacts.upsert', (contacts) => {
    console.log('New contacts:', contacts)
})

sock.ev.on('contacts.update', (updates) => {
    console.log('Contact updates:', updates)
})

Group Events

sock.ev.on('groups.upsert', (groups) => {
    console.log('New groups:', groups)
})

sock.ev.on('groups.update', (updates) => {
    console.log('Group updates:', updates)
})

sock.ev.on('group-participants.update', (update) => {
    console.log('Participants update:', update)
})

Presence Events

sock.ev.on('presence.update', (presence) => {
    console.log('Presence:', presence)
})

πŸ—„οΈ Data Store

In-Memory Store

import makeWASocket, { makeInMemoryStore } from '@ryuhan/baileys'

const store = makeInMemoryStore()
store.readFromFile('./baileys_store.json')

setInterval(() => {
    store.writeToFile('./baileys_store.json')
}, 10000)

const sock = makeWASocket()
store.bind(sock.ev)

// Access stored data
console.log('Chats:', store.chats.all())
console.log('Contacts:', store.contacts)
console.log('Messages:', store.messages)

πŸ”§ Utilities

JID Helpers

import { jidEncode, jidDecode, isJidGroup, isJidBroadcast } from '@ryuhan/baileys'

// Encode JID
const jid = jidEncode('6281234567890', 's.whatsapp.net')

// Decode JID
const decoded = jidDecode(jid)

// Check JID type
const isGroup = isJidGroup(jid)
const isBroadcast = isJidBroadcast(jid)

Message Helpers

import { getContentType, getDevice, downloadMediaMessage } from '@ryuhan/baileys'

// Get content type
const type = getContentType(message)

// Get device
const device = getDevice(message)

// Download media
const buffer = await downloadMediaMessage(message, 'buffer')

πŸ’ Credits & Inspiration

This project is built upon the amazing work of:

Special thanks to all contributors and the WhatsApp community!

⚠️ Disclaimer

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

The maintainers of Rimuru Baileys do not endorse the use of this application for violating WhatsApp's Terms of Service. We emphasize the personal responsibility of users to use it fairly and responsibly.

Use wisely. Avoid spam. Do not use excessive automation.

πŸ“„ License

MIT License - see LICENSE for details.

Made with πŸ’§ by @ryuhandev

GitHub β€’ npm β€’ Issues

Keywords

whatsapp

FAQs

Package last updated on 28 Mar 2026

Related posts