This guide walks you through everything you need to go from zero to a running WhatsApp bot: installing the package, writing a minimal bot file with command handling, and connecting to WhatsApp for the first time. The whole process takes only a few minutes.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/jzszdznzzl/WABotJS/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
Make sure you have Node.js v24 or later installed. WABotJS requires it for the built-in Your project must also be an ESM module. If you are starting from scratch, initialise a new project and set the type:Then open
node:sqlite module used for session persistence.package.json and add "type": "module":package.json
Create your bot file
Create a file called
bot.ts (or bot.js if you are not using TypeScript) in your project root and paste the following example. It creates a Bot instance, registers event handlers, and starts the login flow.bot.ts
The
id string is used to namespace SQLite databases and auth files inside datadir. Use a stable, unique identifier — changing it will invalidate a stored session.Run the bot
If you are using TypeScript, the easiest way to run the file directly (without a compile step) is with Alternatively, compile first with For plain JavaScript (
tsx:tsc and then run the output:bot.js), run it directly:Scan the QR code and connect
When
bot.login() is called for the first time, WABotJS fetches the latest WhatsApp Web version, opens a WebSocket connection, and emits a QR string via your onQR handler. The QR is printed to your terminal.- Open WhatsApp on your phone.
- Go to Linked Devices → Link a Device.
- Scan the QR code shown in your terminal.
onOpen handler fires with your account’s contact info, and the bot is live. Your session is automatically saved to the SQLite database in datadir — on the next run the bot reconnects without showing a QR again.Phone-number OTP pairing — if you prefer not to scan a QR code, pass your phone number (in E.164 format) to
login(). WABotJS will request an 8-digit pairing code from WhatsApp and deliver it to your onOTP handler.Next Steps
Authentication
Deep-dive into QR and OTP pairing modes, session management, and logout.
Command Routing
Learn how to organise commands, change the prefix, and handle arguments.
Handling Messages
Reply, react, read, delete, edit, and download media from incoming messages.
Bot API Reference
Complete reference for every method and event on the
Bot class.