@saazkira/baileys
v2.1.5
Published
Baileys is a lightweight JavaScript library for interacting with the WhatsApp Web API using WebSocket.
Maintainers
Readme
📚 Table of Contents
✨ What's Different
This fork (S44ZKIRA Baileys) extends the original Baileys with several custom patches:
| Feature | Description |
|---------|-------------|
| 🤖 Code Block Message | Send syntax-highlighted code blocks via { code, language } — rendered as AI bot messages in WhatsApp |
| 🪪 Custom Message ID | All outgoing message IDs prefixed with S44ZKIRA instead of the default |
| 🐛 LID Bug Fixes | Full fix for participant, mentionedJid, sender, and group admin LID resolution |
| 📦 makeInMemoryStore Fix | Corrected store behavior for stable session handling |
| 📣 Newsletter Support | Full channel/newsletter create, follow, react, and admin management |
| 🤖 AI Logo Message | Support for AI bot avatar in message context |
| 📊 Logger Buffer Clear | Prevents memory buildup from log buffers |
| 👥 LID → JID Conversion | Auto-converts LID mentions, sender LID, and group member LID to JID |
🌟 Features
- ✅ Multi-Device Support
- 🔄 Real-Time Messaging (text, media, polls, buttons, code blocks)
- 🛠️ Group & Channel Management (create, modify, invite)
- 🔒 End-to-End Encryption
- 📦 Session Persistence
- 🤖 Rich Message Types (code blocks, interactive, carousels)
⚡ Contact Admin
📜 License
- This project is licensed for personal and non-commercial use only.
- Redistribution, modification, or renaming for personal purposes is allowed.
- Commercial use, resale, or name-hunting is strictly prohibited.
🤝 Contribution Guidelines
We welcome contributions to improve this project. To contribute:
- Fork the repository
- Create a new branch for your feature or fix
- Submit a pull request with a clear explanation of the changes
All contributions will be reviewed before merging.
📥 Installation
npm install @saazkira/baileys
# or
yarn add @saazkira/baileys🚀 Quick Start
const {
default: makeWASocket,
useMultiFileAuthState,
} = require('@saazkira/baileys');
const {
state,
saveCreds
} = await useMultiFileAuthState("./path/to/sessions/folder")
const sock = makeWASocket({
printQRInTerminal: true,
auth: state
})
sock.ev.on('creds.update', saveCreds)
sock.ev.on('messages.upsert', ({ messages }) => {
console.log('New message:', messages[0].message);
});📖 Documentation
🔌 Connecting Account
const sock = makeWASocket({
printQRInTerminal: true, // true to display QR Code
auth: state
})const sock = makeWASocket({
printQRInTerminal: false,
auth: state
})
if (!sock.authState.creds.registered) {
const number = "62xxxx"
// default pairing code
const code = await sock.requestPairingCode(number)
// custom 8-digit pairing code
const customCode = "S44ZKIRA"
const code = await sock.requestPairingCode(number, customCode)
console.log(code)
}📡 Handling Events
sock.ev.on('messages.upsert', ({ messages }) => {
console.log('New message:', messages[0].message);
});sock.ev.on('messages.update', (m) => {
if (m.pollUpdates) console.log('Poll vote:', m.pollUpdates);
});📨 Sending Messages
/**
* @param {string} jid - Recipient JID (WhatsApp ID or group)
* @param {Object} content - Message content
* @param {Object} [options] - Options: quoted, ephemeral, etc.
*/
sock.sendMessage(jid, content, options)// Simple Text
await sock.sendMessage(jid, { text: 'Hello!' });
// With Quoted Reply
await sock.sendMessage(jid, { text: 'Hello!' }, { quoted: message });
// With link preview
await sock.sendMessage(jid, {
text: 'Visit https://example.com',
linkPreview: {
'canonical-url': 'https://example.com',
title: 'Example Domain',
description: 'A demo website',
jpegThumbnail: fs.readFileSync('preview.jpg')
}
});Renders as a syntax-highlighted code block in WhatsApp (AI bot style).
// JavaScript code block
await sock.sendMessage(jid, {
code: 'console.log("Hello World")',
language: 'javascript'
}, { quoted: message });
// Python code block
await sock.sendMessage(jid, {
code: 'print("Hello World")',
language: 'python'
}, { quoted: message });
// Bash / terminal output
await sock.sendMessage(jid, {
code: stderr.trim(),
language: 'bash'
}, { quoted: message });Supported languages:
| Language | Key |
|----------|-----|
| JavaScript | javascript, js |
| TypeScript | typescript, ts |
| Python | python, py |
| Bash/Shell | bash, sh, zsh |
| Go | go, golang |
| Rust | rust, rs |
| C | c, h |
| C++ | cpp, c++ |
| C# | csharp, cs |
| CSS | css |
| HTML | html |
| PowerShell | powershell, ps1 |
| CMD | cmd, bat |
// With local file buffer
await sock.sendMessage(jid, {
image: fs.readFileSync('image.jpg'),
caption: 'My cat!',
mentions: ['[email protected]']
});
// With URL
await sock.sendMessage(jid, {
image: { url: 'https://example.com/image.jpg' },
caption: 'Downloaded image'
});// With Local File
await sock.sendMessage(jid, {
video: fs.readFileSync('video.mp4'),
caption: 'Funny clip!'
});
// View Once
await sock.sendMessage(jid, {
video: fs.readFileSync('secret.mp4'),
viewOnce: true
});// Regular audio
await sock.sendMessage(jid, {
audio: fs.readFileSync('audio.mp3'),
ptt: false
});
// Push-to-talk voice note
await sock.sendMessage(jid, {
audio: fs.readFileSync('voice.ogg'),
ptt: true,
waveform: [0, 1, 0, 1, 0]
});const vcard = 'BEGIN:VCARD\n'
+ 'VERSION:3.0\n'
+ 'FN:Jeff Singh\n'
+ 'ORG:Ashoka Uni\n'
+ 'TELtype=CELLtype=VOICEwaid=911234567890:+91 12345 67890\n'
+ 'END:VCARD'
await sock.sendMessage(jid, {
contacts: {
displayName: 'Your Name',
contacts: [{ vcard }]
}
})await sock.sendMessage(jid, {
react: {
text: '👍', // empty string to remove
key: message.key
}
})| Time | Seconds | |------|---------| | 24h | 86400 | | 7d | 604800 | | 30d | 2592000 |
// Pin
await sock.sendMessage(jid, {
pin: { type: 1, time: 86400, key: message.key }
})
// Keep
await sock.sendMessage(jid, {
keep: { key: message.key, type: 1 }
})// Static
await sock.sendMessage(jid, {
location: {
degreesLatitude: 37.422,
degreesLongitude: -122.084,
name: 'Google HQ'
}
});
// Live location
await sock.sendMessage(jid, {
location: {
degreesLatitude: 37.422,
degreesLongitude: -122.084,
accuracyInMeters: 10
},
live: true,
caption: "I'm here!"
});await sock.sendMessage(jid, {
call: { name: 'Call message', type: 1 } // 2 for video
})await sock.sendMessage(jid, {
poll: {
name: 'Favorite color?',
values: ['Red', 'Blue', 'Green'],
selectableCount: 1
}
});await sock.sendAlbumMessage(jid,
[
{ image: { url: 'https://example.com/image.jpg' }, caption: 'Hello World' },
{ video: { url: 'https://example.com/video.mp4' }, caption: 'Hello World' }
],
{ quoted: message, delay: 3000 }
)await sock.sendMessage(jid, {
groupInvite: {
jid: '[email protected]',
name: 'Group Name!',
caption: 'Invitation To Join My Whatsapp Group',
code: 'xYz3yAtf...',
expiration: 86400,
jpegThumbnail: fs.readFileSync('preview.jpg')
}
})await sock.sendMessage(jid, {
text: 'Here is body message',
title: 'Here is title',
subtitle: 'Here is subtitle',
footer: '© S44ZKIRA Baileys',
viewOnce: true,
shop: {
surface: 1,
id: 'facebook_store_name'
}
})const native_flow_button = [{
name: 'quick_reply',
buttonParamsJson: JSON.stringify({
display_text: 'Quick Reply',
id: '123'
})
}]
await sock.sendMessage(jid, {
text: 'Choose:',
title: 'Title',
footer: '© S44ZKIRA Baileys',
interactive: native_flow_button
})await sock.sendMessage(jid, {
text: 'Here is body message',
title: 'Here is title',
footer: '© S44ZKIRA Baileys',
cards: [{
image: { url: 'https://www.example.com/image.jpg' },
title: 'Card title',
body: 'Card body',
footer: '© S44ZKIRA',
buttons: [{
name: 'quick_reply',
buttonParamsJson: JSON.stringify({ display_text: 'Select', id: '123' })
}]
}]
})await sock.sendMessage(jid, {
text: 'Menu:',
sections: [
{ title: 'Food', rows: [
{ title: 'Pizza', rowId: 'pizza' },
{ title: 'Burger', rowId: 'burger' }
]}
],
buttonText: 'Browse'
});📣 Newsletter
const newsletter = await sock.newsletterMetadata("invite", "0029Vaf0HPMLdQeZsp3XRp2T")
// or by jid
const newsletter = await sock.newsletterMetadata("jid", "120363282083849178@newsletter")await sock.newsletterFollow("120363282083849178@newsletter")
await sock.newsletterUnfollow("120363282083849178@newsletter")
await sock.newsletterMute("120363282083849178@newsletter")
await sock.newsletterUnmute("120363282083849178@newsletter")const newsletter = await sock.newsletterCreate(
"Newsletter Name",
"Description here",
{ url: 'https://example.com/image.jpg' }
)await sock.newsletterReactMessage("120363282083849178@newsletter", "12", "🦖")🛠️ Groups
const group = await sock.groupCreate("Group Title", ["[email protected]"]);await sock.groupSettingUpdate(jid, 'announcement') // only admins send
await sock.groupSettingUpdate(jid, 'not_announcement') // everyone send
await sock.groupSettingUpdate(jid, 'locked') // only admins edit info
await sock.groupSettingUpdate(jid, 'unlocked') // everyone edit infoawait sock.groupParticipantsUpdate(jid, ['[email protected]'], 'add')
await sock.groupParticipantsUpdate(jid, ['[email protected]'], 'remove')
await sock.groupParticipantsUpdate(jid, ['[email protected]'], 'promote')
await sock.groupParticipantsUpdate(jid, ['[email protected]'], 'demote')const code = await sock.groupInviteCode(jid)
console.log('https://chat.whatsapp.com/' + code)
// Revoke
const newCode = await sock.groupRevokeInvite(jid)const metadata = await sock.groupMetadata(jid)
console.log(metadata.subject, metadata.desc)🔒 Privacy
await sock.updateProfilePicture(jid, { url: 'https://example.com/image.jpg' })
await sock.removeProfilePicture(jid)await sock.updateBlockStatus(jid, 'block')
await sock.updateBlockStatus(jid, 'unblock')await sock.updateLastSeenPrivacy("all") // or "contacts", "none"
await sock.updateOnlinePrivacy("all") // or "match_last_seen"
await sock.updateProfilePicturePrivacy("all") // or "contacts", "none"
await sock.updateReadReceiptsPrivacy("all") // or "none"
await sock.updateGroupsAddPrivacy("all") // or "contacts"
await sock.updateDefaultDisappearingMode(86400) // 0 to disable⚙️ Advanced
const sock = makeWASocket({ logger: { level: 'debug' } });sock.ws.on('CB:presence', (json) => console.log(json));
sock.ws.on('CB:edge_routing', (node) => console.log(node));⚠️ Disclaimer
This project is not affiliated with WhatsApp/Meta. Use at your own risk.
Refer to WhatsApp's Terms for compliance.
🔗 Full Documentation
Explore all features in the Baileys GitHub Wiki
