@nuisockets/baileys
v7.1.8
Published
A WebSockets library for interacting with WhatsApp Web (© NuiiS4TORU)
Downloads
2,768
Readme
📚 Navigasi
Koneksi QR Code · Pairing Code · Browser Identity · Opsi Koneksi
Handle Pesan Terima Pesan · Handle Grup
Kirim Pesan Teks · Gambar · Video · Audio & Voice Note · Dokumen · Sticker · Lokasi · Kontak
Interaksi Reaksi · Poll · Poll Result · Poll Update · Forward · Hapus · Edit · Pin
Tambahan Album · Event · Group Status · Flow Reply · Button Reply · Keep In Chat · Scheduled Call · Group Invite · Product
Wrapper View Once · View Once V2 · Ephemeral · Spoiler · Group Status Wrap · Lottie Sticker
Instalasi
const { default: makeWASocket } = require('@nuisockets/baileys')
// atau ESM
import makeWASocket from '@nuisockets/baileys'🔌 Koneksi QR Code
const {
default: makeWASocket,
useMultiFileAuthState,
DisconnectReason,
fetchLatestBaileysVersion
} = require('@nuisockets/baileys')
async function start() {
const { state, saveCreds } = await useMultiFileAuthState('auth_info')
const { version } = await fetchLatestBaileysVersion()
const sock = makeWASocket({
version,
auth: state,
printQRInTerminal: true
})
sock.ev.on('creds.update', saveCreds)
sock.ev.on('connection.update', ({ connection, lastDisconnect }) => {
if (connection === 'close') {
const code = lastDisconnect?.error?.output?.statusCode
if (code !== DisconnectReason.loggedOut) start()
} else if (connection === 'open') {
console.log('✅ Terhubung!')
}
})
}
start()🔑 Koneksi Pairing Code
Untuk server/VPS tanpa tampilan terminal.
const sock = makeWASocket({
version,
auth: state,
printQRInTerminal: false
})
sock.ev.on('creds.update', saveCreds)
sock.ev.on('connection.update', ({ connection, lastDisconnect }) => {
if (connection === 'close') {
if (lastDisconnect?.error?.output?.statusCode !== DisconnectReason.loggedOut) start()
}
})
// Nomor HP format internasional tanpa +
if (!sock.authState.creds.registered) {
const code = await sock.requestPairingCode('628123456789')
console.log('Pairing code:', code)
// Masukkan di WA → Perangkat Tertaut → Tautkan Perangkat
}Pairing code kadaluarsa dalam beberapa menit. Jalankan ulang jika gagal.
Custom pairing code (8 karakter):
const code = await sock.requestPairingCode('628123456789', 'ABCD1234')🖥️ Browser Identity
const { Browsers } = require('@nuisockets/baileys')
makeWASocket({
browser: Browsers.macOS('Chrome'), // Mac OS — Chrome
browser: Browsers.macOS('Firefox'), // Mac OS — Firefox
browser: Browsers.windows('Chrome'), // Windows — Chrome
browser: Browsers.ubuntu('Chrome'), // Ubuntu — Chrome
browser: Browsers.baileys('Chrome'), // Baileys — Chrome
browser: ['MyBot', 'Chrome', '1.0.0'] // custom
})⚙️ Opsi Koneksi
makeWASocket({
version,
auth: state,
printQRInTerminal: true,
browser: Browsers.macOS('Chrome'),
connectTimeoutMs: 20000,
keepAliveIntervalMs: 30000,
markOnlineOnConnect: true,
syncFullHistory: false,
generateHighQualityLinkPreview: false,
emitOwnEvents: true,
getMessage: async key => store?.messages?.[key.remoteJid]?.get(key.id)?.message
})📥 Terima Pesan
sock.ev.on('messages.upsert', async ({ messages, type }) => {
if (type !== 'notify') return
for (const m of messages) {
if (!m.message) continue
if (m.key.fromMe) continue
const jid = m.key.remoteJid
const isGroup = jid.endsWith('@g.us')
const sender = isGroup ? m.key.participant : jid
// Ambil teks
const text =
m.message.conversation ||
m.message.extendedTextMessage?.text ||
m.message.imageMessage?.caption ||
m.message.videoMessage?.caption || ''
// Tandai dibaca
await sock.readMessages([m.key])
// Typing indicator
await sock.sendPresenceUpdate('composing', jid)
}
})👥 Handle Grup
// Anggota masuk/keluar
sock.ev.on('group-participants.update', ({ id, participants, action }) => {
// action: 'add' | 'remove' | 'promote' | 'demote'
})
// Info grup diupdate
sock.ev.on('groups.update', updates => {})
// Metadata grup
const meta = await sock.groupMetadata(groupJid)
console.log(meta.subject, meta.participants)
// Semua grup
const groups = await sock.groupFetchAllParticipating()
// Tambah / keluarkan / promote / demote
await sock.groupParticipantsUpdate(groupJid, ['[email protected]'], 'add')
await sock.groupParticipantsUpdate(groupJid, ['[email protected]'], 'remove')
await sock.groupParticipantsUpdate(groupJid, ['[email protected]'], 'promote')
await sock.groupParticipantsUpdate(groupJid, ['[email protected]'], 'demote')
// Ubah nama / deskripsi
await sock.groupUpdateSubject(groupJid, 'Nama Baru')
await sock.groupUpdateDescription(groupJid, 'Deskripsi baru')
// Kunci / buka grup
await sock.groupSettingUpdate(groupJid, 'announcement')
await sock.groupSettingUpdate(groupJid, 'not_announcement')
// Mention semua anggota
const meta2 = await sock.groupMetadata(groupJid)
const members = meta2.participants.map(p => p.id)
await sock.sendMessage(groupJid, {
text: members.map(m => `@${m.split('@')[0]}`).join(' '),
mentions: members
})💬 Teks
await sock.sendMessage(jid, { text: 'Halo!' })
// Dengan mention
await sock.sendMessage(jid, {
text: '@628xxx halo!',
mentions: ['[email protected]']
}, { quoted: m })🖼️ Gambar
// URL
await sock.sendMessage(jid, {
image: { url: 'https://example.com/image.jpg' },
caption: 'Keterangan'
})
// Buffer / file
await sock.sendMessage(jid, {
image: fs.readFileSync('image.jpg'),
caption: 'Keterangan'
})🎥 Video
await sock.sendMessage(jid, {
video: { url: 'https://example.com/video.mp4' },
caption: 'Keterangan',
gifPlayback: false // true = GIF looping
})
// Video note (bubble)
await sock.sendMessage(jid, {
video: fs.readFileSync('video.mp4'),
ptv: true
})🎵 Audio & Voice Note
// Audio biasa
await sock.sendMessage(jid, {
audio: { url: 'https://example.com/audio.mp3' },
mimetype: 'audio/mpeg'
})
// Voice note (PTT)
await sock.sendMessage(jid, {
audio: fs.readFileSync('voice.ogg'),
mimetype: 'audio/ogg; codecs=opus',
ptt: true
})📄 Dokumen
await sock.sendMessage(jid, {
document: fs.readFileSync('file.pdf'),
mimetype: 'application/pdf',
fileName: 'dokumen.pdf',
caption: 'File ini'
})🎭 Sticker
await sock.sendMessage(jid, {
sticker: fs.readFileSync('sticker.webp')
})📍 Lokasi
await sock.sendMessage(jid, {
location: {
degreesLatitude: -6.2088,
degreesLongitude: 106.8456,
name: 'Monas',
address: 'Jakarta Pusat'
}
})👤 Kontak
await sock.sendMessage(jid, {
contacts: {
displayName: 'Nama',
contacts: [{
vcard: 'BEGIN:VCARD\nVERSION:3.0\nFN:Nama\nTEL:+62812345678\nEND:VCARD'
}]
}
})😀 Reaksi
await sock.sendMessage(jid, { react: { text: '👍', key: m.key } })
// Hapus reaksi
await sock.sendMessage(jid, { react: { text: '', key: m.key } })🗳️ Poll
await sock.sendMessage(jid, {
poll: {
name: 'Pilih salah satu?',
values: ['Opsi A', 'Opsi B', 'Opsi C'],
selectableCount: 1 // 0 = boleh pilih banyak
}
})📊 Poll Result
await sock.sendMessage(jid, {
pollResult: {
name: 'Nama Poll',
votes: [
{ name: 'Opsi A', voteCount: 10 },
{ name: 'Opsi B', voteCount: 5 }
],
pollType: 0 // 0 = POLL, 1 = QUIZ
}
})🗳️ Poll Update
await sock.sendMessage(jid, {
pollUpdate: {
key: pollMessage.key, // key dari pesan poll yang mau di-vote
vote: encryptedVotePayload,
metadata: optionalMetadata
}
})↩️ Forward
await sock.sendMessage(jid, {
forward: targetMessage,
force: true // paksa tampil sebagai forwarded
})🗑️ Hapus Pesan
await sock.sendMessage(jid, { delete: m.key })✏️ Edit Pesan
await sock.sendMessage(jid, {
text: 'Teks yang sudah diedit',
edit: m.key
})📌 Pin Pesan
// Pin
await sock.sendMessage(jid, {
pin: m.key,
type: 1,
time: 86400 // 86400=1hr | 604800=7hr | 2592000=30hr
})
// Unpin
await sock.sendMessage(jid, { pin: m.key, type: 2 })🖼️ Album
await sock.sendMessage(jid, {
album: [
{ image: { url: 'https://example.com/1.jpg' }, caption: 'Foto 1' },
{ image: { url: 'https://example.com/2.jpg' }, caption: 'Foto 2' },
{ video: { url: 'https://example.com/vid.mp4' }, caption: 'Video' }
]
})
// minimal 2 media📅 Event
await sock.sendMessage(jid, {
event: {
name: 'Nama Acara',
description: 'Deskripsi',
startDate: new Date('2025-12-01T10:00:00'),
endDate: new Date('2025-12-01T12:00:00'),
location: {
degreesLatitude: -6.2088,
degreesLongitude: 106.8456,
name: 'Monas, Jakarta'
},
extraGuestsAllowed: true
}
})📸 Group Status / Group Story
// Teks
await sock.sendMessage(groupJid, {
groupStatusMessage: { text: 'Status teks!' }
})
// Gambar
await sock.sendMessage(groupJid, {
groupStatusMessage: {
image: { url: 'https://example.com/image.jpg' },
caption: 'Keterangan'
}
})
// Video
await sock.sendMessage(groupJid, {
groupStatusMessage: {
video: { url: 'https://example.com/video.mp4' },
caption: 'Keterangan'
}
})⚡ Flow Reply
Balas pesan interaktif native flow:
await sock.sendMessage(jid, {
flowReply: {
name: 'quick_reply', // nama button yang ditekan
paramsJson: '{"id":"btn1"}',
text: 'Teks balasan',
format: 1,
version: 1
}
})🔘 Button Reply
// Template button
await sock.sendMessage(jid, {
buttonReply: {
displayText: 'Opsi yang dipilih',
id: 'btn_id',
index: 0
},
type: 'template'
})
// Plain button
await sock.sendMessage(jid, {
buttonReply: {
displayText: 'Opsi yang dipilih',
id: 'btn_id'
},
type: 'plain'
})📌 Keep In Chat
// Simpan
await sock.sendMessage(jid, {
keep: m.key,
keepType: 1 // 1 = keep, 2 = unkeep
})📞 Scheduled Call
await sock.sendMessage(jid, {
call: {
time: Date.now() + 3600000,
type: 1, // 1 = voice, 2 = video
title: 'Meeting'
}
})🔗 Group Invite
await sock.sendMessage(jid, {
groupInvite: {
jid: '[email protected]',
inviteCode: 'kode',
inviteExpiration: Date.now() + 86400000,
subject: 'Nama Grup',
text: 'Bergabunglah!'
}
})🛍️ Product
await sock.sendMessage(jid, {
product: {
productImage: fs.readFileSync('produk.jpg'),
productId: 'prod_123',
title: 'Nama Produk',
description: 'Deskripsi',
currencyCode: 'IDR',
priceAmount1000: 50000000,
retailerId: 'sku_001',
url: 'https://toko.example.com/produk'
}
})👁️ View Once
await sock.sendMessage(jid, {
image: { url: 'https://example.com/image.jpg' },
viewOnce: true
})👁️ View Once V2
await sock.sendMessage(jid, {
image: { url: 'https://example.com/image.jpg' },
viewOnceV2: true // wrap ke viewOnceMessageV2
})
// viewOnceV2Extension
await sock.sendMessage(jid, {
image: { url: 'https://example.com/image.jpg' },
viewOnceV2Extension: true
})⏱️ Ephemeral
Wrap pesan ke dalam ephemeralMessage:
await sock.sendMessage(jid, {
text: 'Pesan ini ephemeral',
ephemeral: true
})🫣 Spoiler
Wrap pesan ke dalam spoilerMessage:
await sock.sendMessage(jid, {
image: { url: 'https://example.com/image.jpg' },
caption: 'Spoiler!',
spoiler: true
})📢 Group Status Wrap
Wrap pesan biasa menjadi groupStatusMessageV2:
await sock.sendMessage(jid, {
text: 'Status di grup ini',
groupStatus: true
})🌀 Lottie Sticker
Wrap sticker ke dalam lottieStickerMessage:
await sock.sendMessage(jid, {
sticker: fs.readFileSync('sticker.webp'),
isLottie: true
})Opsi Umum
Semua sendMessage mendukung opsi ke-3:
await sock.sendMessage(jid, content, {
quoted: m, // reply/quote pesan
ephemeralExpiration: 86400, // pesan hilang (detik)
statusJidList: ['[email protected]'], // kirim status ke JID
mediaUploadTimeoutMs: 30000,
backgroundColor: '#FF0000',
font: 1
})File yang Dimodifikasi
| File | Keterangan |
|---|---|
| lib/Socket/dugong.js | Handler GROUP_STORY, ALBUM, EVENT, POLL_RESULT |
| lib/Socket/messages-send.js | Route pesan + getBizBinaryNode dinamis |
| lib/Utils/messages.js | Semua handler tipe pesan lengkap |
| lib/Utils/rich-message-utils.js | Helper Rich Message / AI Response |
| lib/WABinary/generic-utils.js | getBizBinaryNode dengan FLOWS_MAP |
| lib/Types/Message.js | Export ButtonType, ListType, dll |
| lib/WABinary/constants.js | LANGUAGE_KEYWORDS untuk syntax highlight |
| lib/Defaults/index.js | LEXER_REGEX, DONATE_URL, LIBRARY_NAME |
Project ini tidak berafiliasi dengan WhatsApp atau Meta. "WhatsApp" adalah merek dagang terdaftar dari pemiliknya masing-masing.
