@nozez-lab/baileys
v1.2.2
Published
Enhanced Baileys v7 with fixes for newsletter media uploads, plus support for interactive messages, albums, and additional message types.
Maintainers
Readme
⚡ @nozez-lab/baileys
📋 Table of Contents
- ✨ What's Different
- 🔧 Internal Fixes
- 📦 Installation
- 🚀 Quick Start
- 🗄️ Data Store
- 🪪 WhatsApp IDs
- ✉️ Sending Messages
- 🖼️ Media Messages
- 👉 Interactive Messages
- ♻️ Modify Messages
- 🧰 Utilities
- 🔗 Fork Base
- 📣 Credits
✨ What's Different
@nozez-lab/baileys adalah library WhatsApp yang dikustomisasi untuk kebutuhan bot modern:
- ✅ Native Interactive Messages — Buttons, Lists, Native Flows, Carousels, Templates
- ✅ Album Support — Kirim gambar/video dalam satu album
- ✅ Sticker Pack — Kirim sticker dalam satu paket
- ✅ Pairing Code — Koneksi mudah tanpa QR Code
- ✅ No Obfuscation — Kode bersih, mudah dibaca dan diaudit
- ✅ No Auto-Follow — Tidak ada behavior channel (newsletter) otomatis
🔧 Internal Fixes
- 🖼️ Perbaikan upload media ke newsletter (bug upstream)
- 🔄 Reimplementasi
makeInMemoryStoredengan adaptasi minimal ESM untuk Baileys v7 - 📦 FFmpeg dijalankan dengan
spawnbukanexecuntuk keamanan proses - 🗃️ Penambahan
@napi-rs/imagesebagai backend image processing digetImageProcessingLibrary() - 💬 Dukungan quote message di dalam channel (newsletter)
- 🎀 Dukungan custom button icon pada interactive messages
📦 Installation
Via package.json:
{
"dependencies": {
"@nozez-lab/baileys": "latest"
}
}Via terminal:
# Dari NPM
npm install @nozez-lab/baileys@latest
# Dari GitHub
npm install github:nozez-lab/baileys🔌 Import (ESM & CJS)
// ESM
import { makeWASocket } from '@nozez-lab/baileys'
// CJS (Node.js 24+)
const { makeWASocket } = require('@nozez-lab/baileys')🚀 Quick Start
import {
makeWASocket,
delay,
DisconnectReason,
useMultiFileAuthState
} from '@nozez-lab/baileys'
import { Boom } from '@hapi/boom'
import pino from 'pino'
const PHONE_NUMBER = '628xxxxxxxxxx'
const logger = pino({ level: 'silent' })
async function startBot() {
const { state, saveCreds } = await useMultiFileAuthState('session')
const sock = makeWASocket({ logger, auth: state })
sock.ev.on('creds.update', saveCreds)
sock.ev.on('connection.update', async (update) => {
const { connection, lastDisconnect } = update
if (connection === 'connecting' && !sock.authState.creds.registered) {
await delay(1500)
const code = await sock.requestPairingCode(PHONE_NUMBER)
console.log('🔗 Pairing Code:', code)
}
if (connection === 'close') {
const shouldReconnect =
new Boom(lastDisconnect?.error)?.output?.statusCode !== DisconnectReason.loggedOut
if (shouldReconnect) startBot()
}
if (connection === 'open') {
console.log('✅ Connected to WhatsApp')
}
})
sock.ev.on('messages.upsert', async ({ messages }) => {
for (const msg of messages) {
if (!msg.message) continue
console.log('📩 New message:', msg)
}
})
}
startBot()🔐 Auth State
[!NOTE] Kamu bisa menggunakan
useSingleFileAuthStateatauuseSqliteAuthStatesebagai alternatif dariuseMultiFileAuthState.useSingleFileAuthStatesudah memiliki mekanisme cache internal, sehingga tidak perlu membungkusstate.keysdenganmakeCacheableSignalKeyStore.
🗄️ Data Store
[!CAUTION] Sangat disarankan untuk membuat data store sendiri. Menyimpan seluruh riwayat chat di memori dapat menyebabkan penggunaan RAM yang berlebihan.
import {
makeWASocket,
makeInMemoryStore,
delay,
DisconnectReason,
useMultiFileAuthState
} from '@nozez-lab/baileys'
import pino from 'pino'
const logger = pino({ level: 'silent' })
const STORE_PATH = './store.json'
async function startBot() {
const { state, saveCreds } = await useMultiFileAuthState('session')
const sock = makeWASocket({ logger, auth: state })
const store = makeInMemoryStore({ logger, socket: sock })
store.bind(sock.ev)
sock.ev.on('creds.update', saveCreds)
sock.ev.on('chats.upsert', () => {
console.log('✉️ Chats:', store.chats.all())
})
store.readFromFile(STORE_PATH)
setInterval(() => store.writeToFile(STORE_PATH), 180_000)
}
startBot()🪪 WhatsApp IDs
| Tipe | Format |
|------|--------|
| Personal | [email protected] |
| LID | 12699999999@lid |
| Group | [email protected] |
| Meta AI | 11111111111@bot |
| Broadcast | [timestamp]@broadcast |
| Status | status@broadcast |
✉️ Sending Messages
[!NOTE] Dapatkan
jiddarimessage.key.remoteJid.
📝 Text
// Pesan teks biasa
sock.sendMessage(jid, { text: 'Halo! 👋' }, { quoted: message })
// Dengan link preview
sock.sendMessage(jid, {
text: 'Cek ini! https://github.com/nozez-lab/baileys',
linkPreview: {
'matched-text': 'https://github.com/nozez-lab/baileys',
title: '⚡ @nozez-lab/baileys',
description: 'WhatsApp bot library by Nozez',
previewType: 0
}
})🔔 Mention
// Mention user tertentu
sock.sendMessage(jid, {
text: 'Halo @628123456789!',
mentions: ['[email protected]']
}, { quoted: message })
// Mention semua anggota grup
sock.sendMessage(jid, {
text: 'Halo @all!',
mentionAll: true
}, { quoted: message })😄 Reaction
sock.sendMessage(jid, {
react: { key: message.key, text: '⚡' }
})📌 Pin Message
sock.sendMessage(jid, {
pin: message.key,
time: 86400, // 86400 (1h), 604800 (7d), 2592000 (30d)
type: 1 // 2 untuk unpin
})➡️ Forward Message
sock.sendMessage(jid, {
forward: message,
force: true
})👤 Contact
const vcard = [
'BEGIN:VCARD',
'VERSION:3.0',
'FN:Nozez',
'ORG:NozezLab;',
'TEL;type=CELL;type=VOICE;waid=628123456789:+62 812-3456-789',
'END:VCARD'
].join('\n')
sock.sendMessage(jid, {
contacts: {
displayName: 'Nozez',
contacts: [{ vcard }]
}
}, { quoted: message })📍 Location
sock.sendMessage(jid, {
location: {
degreesLatitude: -6.2,
degreesLongitude: 106.8,
name: 'Jakarta, Indonesia'
}
}, { quoted: message })📅 Event
sock.sendMessage(jid, {
event: {
name: '🎉 Community Meetup',
description: 'Kumpul bareng komunitas Nozez!',
startDate: new Date(Date.now() + 3600000),
endDate: new Date(Date.now() + 28800000),
location: {
name: 'Jakarta',
degreesLatitude: -6.2,
degreesLongitude: 106.8
}
}
}, { quoted: message })👥 Group Invite
const inviteCode = groupUrl.split('chat.whatsapp.com/')[1]?.split('?')[0]
sock.sendMessage(jid, {
groupInvite: {
inviteCode,
inviteExpiration: Date.now() + 86400000,
text: 'Gabung ke grup kita yuk!',
jid: '[email protected]',
subject: 'NozezLab Community'
}
}, { quoted: message })🛍️ Product
import { randomUUID } from 'crypto'
sock.sendMessage(jid, {
image: { url: './product.jpg' },
body: 'Cek produk ini!',
footer: '@nozez-lab/baileys',
product: {
currencyCode: 'IDR',
description: 'Produk pilihan terbaik',
priceAmount1000: 50_000_000,
productId: randomUUID(),
productImageCount: 1,
title: 'Premium Package',
url: 'https://github.com/nozez-lab/baileys'
},
businessOwnerJid: '[email protected]'
})📊 Poll
sock.sendMessage(jid, {
poll: {
name: '🔥 Vote sekarang!',
values: ['Ya', 'Tidak'],
selectableCount: 1,
endDate: new Date(Date.now() + 28800000)
}
}, { quoted: message })🖼️ Media Messages
🖼️ Image
sock.sendMessage(jid, {
image: { url: './gambar.jpg' },
caption: 'Gambar keren! ✨'
}, { quoted: message })🎥 Video
sock.sendMessage(jid, {
video: { url: './video.mp4' },
caption: 'Video keren!'
}, { quoted: message })📃 Sticker
sock.sendMessage(jid, {
sticker: { url: './sticker.webp' }
}, { quoted: message })💽 Audio
sock.sendMessage(jid, {
audio: { url: './audio.mp3' },
mimetype: 'audio/mp4',
ptt: true // true = pesan suara, false = file audio
}, { quoted: message })🗂️ Document
sock.sendMessage(jid, {
document: { url: './file.pdf' },
mimetype: 'application/pdf',
fileName: 'dokumen.pdf',
caption: 'Ini dokumennya'
}, { quoted: message })🖼️ Album
sock.sendMessage(jid, {
album: [
{ image: { url: './foto1.jpg' }, caption: 'Foto 1' },
{ image: { url: './foto2.jpg' }, caption: 'Foto 2' },
{ video: { url: './video.mp4' }, caption: 'Video' }
]
}, { quoted: message })👉 Interactive Messages
📘 Buttons
sock.sendMessage(jid, {
image: { url: './banner.jpg' },
body: 'Pilih menu di bawah ini:',
footer: '@nozez-lab/baileys',
buttons: [
{ id: '#menu', text: '📋 Menu Utama' },
{ id: '#info', text: 'ℹ️ Info' },
{ id: '#help', text: '🆘 Bantuan' }
]
}, { quoted: message })📋 List
sock.sendMessage(jid, {
body: 'Pilih salah satu opsi:',
footer: '@nozez-lab/baileys',
button: '📋 Lihat Menu',
list: [
{
title: '🔧 Tools',
rows: [
{ id: '#ping', title: 'Ping', description: 'Cek koneksi bot' },
{ id: '#info', title: 'Info', description: 'Info bot' }
]
},
{
title: '🎮 Fun',
rows: [
{ id: '#game', title: 'Game', description: 'Main game' }
]
}
]
}, { quoted: message })🗄️ Interactive
sock.sendMessage(jid, {
body: 'Selamat datang!',
footer: 'Powered by @nozez-lab/baileys',
nativeFlowButtons: [
{
name: 'quick_reply',
buttonParamsJson: JSON.stringify({ display_text: '⚡ Mulai', id: '#start' })
},
{
name: 'cta_url',
buttonParamsJson: JSON.stringify({
display_text: '🔗 GitHub',
url: 'https://github.com/nozez-lab/baileys'
})
}
]
}, { quoted: message })♻️ Modify Messages
🗑️ Delete
// Hapus untuk semua
sock.sendMessage(jid, { delete: message.key })✏️ Edit
sock.sendMessage(jid, {
edit: message.key,
text: 'Pesan yang sudah diedit ✏️'
})🧰 Utilities
🔑 Custom Pairing Code
const code = await sock.requestPairingCode('628xxxxxxxxxx', 'NOZEZBOT')
console.log('🔑 Pairing Code:', code)🖼️ Image Processing
import { getImageProcessingLibrary } from '@nozez-lab/baileys'
const lib = await getImageProcessingLibrary()
console.log('Library yang digunakan:', lib)📣 Newsletter (Channel)
// Buat newsletter
const newsletter = await sock.createNewsLetter({
name: 'Nozez Updates',
description: 'Update terbaru dari Nozez',
picture: fs.readFileSync('./logo.jpg')
})
// Kirim pesan ke newsletter
sock.sendMessage(newsletter.id, { text: '📢 Pengumuman baru!' })👥 Group Management
// Buat grup
const group = await sock.groupCreate('Nama Grup', ['[email protected]'])
// Tambah anggota
await sock.groupParticipantsUpdate(group.id, ['[email protected]'], 'add')
// Kick anggota
await sock.groupParticipantsUpdate(group.id, ['[email protected]'], 'remove')
// Promosi admin
await sock.groupParticipantsUpdate(group.id, ['[email protected]'], 'promote')👤 Profile Management
// Update nama
await sock.updateProfileName('Nozez Bot')
// Update status
await sock.updateProfileStatus('Ditenagai oleh @nozez-lab/baileys ⚡')
// Update foto profil
await sock.updateProfilePicture(sock.user.id, { url: './foto.jpg' })🔏 Privacy
// Atur last seen
await sock.updateLastSeenPrivacy('contacts')
// Atur online
await sock.updateOnlinePrivacy('match_last_seen')
// Atur foto profil
await sock.updateProfilePicturePrivacy('contacts')🔗 Fork Base
Proyek ini adalah fork dari:
Semua kredit untuk proyek asli tetap diberikan sepenuhnya. Fork ini menambahkan fitur-fitur tambahan yang dibutuhkan untuk pengembangan bot WhatsApp modern.
📣 Credits
| Kontribusi | Penulis | |-----------|---------| | Library Baileys Original | WhiskeySockets | | Fork & Kustomisasi | Nozez |
