Getting Started
From zero to a connected bot in a few minutes.
Requirements
| Requirement | Details |
|---|---|
| Node.js | >= 20.0.0 (enforced by the package via engines) |
| A WhatsApp number | An active number to pair as the bot (multi-device) |
| Module system | The package is type: module โ use import (ESM) |
Install
npm i aunubaileysCore dependencies (ws, pino, libsignal, protobufjs, and more) install automatically. Optional peers: sharp, jimp, link-preview-js, audio-decode โ install only what your features need (e.g. image processing).
Your first bot
import makeWASocket, {
useMultiFileAuthState,
makeInMemoryStore,
DisconnectReason
} from 'aunubaileys'
import { Boom } from '@hapi/boom'
const store = makeInMemoryStore({})
async function start() {
const { state, saveCreds } = await useMultiFileAuthState('auth')
const sock = makeWASocket({
auth: state,
printQRInTerminal: true // or use a pairing code โ see Connection
})
store.bind(sock.ev)
sock.ev.on('creds.update', saveCreds)
sock.ev.on('connection.update', ({ connection, lastDisconnect }) => {
if (connection === 'close') {
const loggedOut = (lastDisconnect?.error instanceof Boom)
&& lastDisconnect.error.output.statusCode === DisconnectReason.loggedOut
if (!loggedOut) start() // reconnect
}
})
sock.ev.on('messages.upsert', async ({ messages }) => {
const m = messages[0]
if (m.key.fromMe) return
await sock.sendMessage(m.key.remoteJid, { text: 'Hello from AunuBaileys ๐ค' })
})
}
start()
The
auth/ folder is your session. Never delete or share it โ it holds the linked device's credentials. In AunuBaileys, session files are written atomically (since v1.0.2), so a crashed process can't leave a half-written credential file behind.