@ryuhan/baileys
v2.0.2
Published
π§ Rimuru Baileys - WhatsApp Multi-Device Library with intelligent @lid/@jid mapping
Downloads
1,068
Maintainers
Readme
π Features
Core Features
- π§ Intelligent
@lidand@jidMapping - 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/baileysyarn
yarn add @ryuhan/baileyspnpm
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
Pairing Code (Recommended)
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: ['[email protected]']
})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', ['[email protected]'])
console.log('Group created:', group.id)Add Participants
await sock.groupParticipantsUpdate(groupId, ['[email protected]'], 'add')Remove Participants
await sock.groupParticipantsUpdate(groupId, ['[email protected]'], 'remove')Promote to Admin
await sock.groupParticipantsUpdate(groupId, ['[email protected]'], 'promote')Demote Admin
await sock.groupParticipantsUpdate(groupId, ['[email protected]'], '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/' + codeJoin 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 hoursUnmute 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:
- @blck-baileys - Original modified Baileys fork with advanced features
- @WhiskeySockets - Base Baileys library
- @itsukichan - Additional features and improvements
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.
