Zaileys is a powerful, type-safe wrapper around Baileys, designed to simplify the development of WhatsApp bots. It provides a robust architecture with built-in state management, middleware support, and easy-to-use event handlers, making it perfect for building scalable and maintainable WhatsApp applications.
Zaileys solves the complexity of managing raw WhatsApp socket connections by providing a high-level, opinionated API. It is built for developers who need to create bots, customer support agents, or automated notification systems without getting bogged down in protocol details.
Targeting Node.js and TypeScript developers, Zaileys integrates essential features like rate limiting, session management, and input validation out of the box.
- ✅ Type-Safe - Full TypeScript + Zod validation with autocomplete
- ✅ Middleware - Intercept and process events globally
- ✅ Plugin System - Drop-in file-based plugins with on/off controls
- ✅ State Management - Built-in JetDB for data persistence with auto chunking
- ✅ Rate Limiting - Anti-spam protection out of the box
- ✅ Multi-Device - QR code or Pairing Code authentication
- ✅ Built-in FFmpeg - No external dependencies for media processing
- ✅ Interactive Buttons - Simple buttons, URL, copy code, call buttons, and lists
- ✅ Context Injection - Universal data injection accessible anywhere in ctx
- ✅ Fire and Forget - Background task processing for lightning-fast responses
- ✅ Auto-Healing - Intelligent connection monitoring and session repair
- ✅ Auto Clean Up - Periodic database maintenance to save space
Client - Your bot's brain. Manages connections, events, and the entire lifecycle.
Context - Rich event objects with all the data and helpers you need.
Middleware - Pre-process events for logging, auth, spam filtering, or custom logic.
Plugins - Drop files in plugins/ directory. Auto-loaded, zero config.
Store - JSON database (JetDB) that auto-syncs chats, contacts, and messages.
Install zaileys using your preferred package manager:
npm install zaileys
# or
pnpm add zaileys
# or
yarn add zaileysNote: Requires Node.js v20+ and TypeScript for best experience.
FFmpeg: No need to install FFmpeg separately! It's already bundled with Zaileys for seamless media processing (audio, video, stickers). You can disabled it if you want at
Client Configuration.
Prefer a ready-to-run setup? We provide an official Starter Kit that includes a fully configured environment, example commands, and best practices.
Here is a minimal example to get your bot running with QR code authentication:
import { Client } from 'zaileys';
// or
const { Client } = require('zaileys');
const wa = new Client({
// dynamic session you can change
session: 'zaileys', // default
// qr code
authType: 'qr',
// pairing code
authType: 'pairing',
phoneNumber: 6280000000,
// for detailed logs
// fancyLogs: true,
// if you want to disable built-in ffmpeg
// disableFFmpeg: true,
// plugin configuration
pluginsDir: 'plugins', // default
pluginsHmr: true, // default: true (auto reload plugins on change)
sticker: {
authorName: 'your name',
packageName: 'package name',
quality: 80,
shape: 'circle', // output sticker must be circle
},
});
wa.on('messages', async (ctx) => {
if (ctx.text == 'ping') {
await wa.send(ctx.roomId, 'Pong! 🏓');
}
});✨ Structure of ctx on event listener messages
The Client constructor accepts a configuration object. Below are the valid options based on the library's type definitions.
These options apply to both authentication methods:
| Option | Type | Default | Description |
|---|---|---|---|
session |
string |
'zaileys' |
Name of the session folder. |
prefix |
string |
undefined |
Command prefix (e.g., '/'). |
showLogs |
boolean |
true |
Enable internal logging. |
fancyLogs |
boolean |
false |
Enable detailed, fancy log output. |
ignoreMe |
boolean |
true |
Ignore messages sent by the bot itself. |
syncFullHistory |
boolean |
true |
Sync full chat history on startup. |
pluginsDir |
string |
'plugins' |
Directory where plugins are located. |
pluginsHmr |
boolean |
true |
Enable Hot Module Replacement for plugins. |
cleanupDays |
number |
7 |
Days to keep messages before auto-deletion. |
autoCleanUp |
object |
undefined |
Configuration for periodic database cleanup. |
disableFFmpeg |
boolean |
false |
Disable built-in FFmpeg installers. |
| Option | Type | Default | Description |
|---|---|---|---|
autoRead |
boolean |
true |
Automatically mark messages as read. |
autoOnline |
boolean |
true |
Automatically set presence to online. |
autoPresence |
boolean |
true |
Automatically send presence updates (composing/recording). |
autoMentions |
boolean |
true |
Automatically handle mentions. |
autoRejectCall |
boolean |
true |
Automatically reject incoming calls. |
| Option | Type | Description |
|---|---|---|
limiter |
object |
Rate limiting configuration. Default: maxMessages: 20, durationMs: 10_000. |
fakeReply |
object |
Configuration for fake reply provider. |
sticker |
object |
Default metadata for sticker creation (packageName, authorName, quality, shape). |
citation |
object |
Custom citation sources. |
You can use middleware to filter messages or add custom logic before your handlers run.
wa.use(async (ctx, next) => {
if (ctx.messages.isSpam) {
console.warn(`Spam detected from ${ctx.messages.senderName}`);
return;
}
await next();
});Zaileys features a built-in file-based plugin system with Hot Module Replacement (HMR) support. By default, it looks for plugins in the plugins directory of your project root and automatically reloads them when you make changes.
0. Configuration:
You can customize the plugin directory and HMR behavior in the Client constructor:
const wa = new Client({
pluginsDir: 'my-plugins', // Custom plugins directory
pluginsHmr: true, // Enable/disable HMR (default: true)
});1. Create a plugin file (e.g., plugins/hello.ts):
also nested file plugins/nested1/nested2/hello.ts
import { definePlugins } from 'zaileys';
export default definePlugins(
async (wa, ctx) => {
await wa.send(ctx.messages.roomId, 'Hello from plugin!');
},
{
matcher: ['/hello', '!hello'], // Trigger commands
metadata: {
description: 'A simple hello world plugin',
},
},
);2. Extract plugin information (optional):
const pluginsInfo = wa.plugins.getPluginsInfo();
/* Example output
[
{
matcher: ['/hello', '!hello'],
metadata: {
description: 'A simple hello world plugin',
},
}
]
*/This returns an array of all loaded plugins with their matcher and metadata, useful for generating help menus or listing available commands.
3. Plugin Controls:
// Disable all plugins
wa.plugins.disableAll();
// Enable all plugins
wa.plugins.enableAll();
// Disable specific plugin by matcher
wa.plugins.disable('/hello');
// Enable specific plugin
wa.plugins.enable('/hello');
// Disable all plugins in a folder (e.g., plugins/admin/)
wa.plugins.disableByParent('admin');
// Enable all plugins in a folder
wa.plugins.enableByParent('admin');
// Check if plugins are globally enabled
wa.plugins.isEnabled(); // true/falseCitation allows you to define custom authorization logic by creating named checkers that verify if a user is in a specific list (e.g., premium users, banned users).
1. Configure citation sources in the client options:
const wa = new Client({
authType: 'qr',
citation: {
premium: async () => {
// const numbers = await fetch...
return [6280000000, 12388888888];
},
banned: async () => {
return [6285555555555];
},
},
});2. Use citation in your message handlers:
wa.on('messages', async (ctx) => {
const isBanned = await ctx.citation.banned();
const isPremium = await ctx.citation.premium();
if (isBanned) return;
if (isPremium) {
await wa.send(ctx.roomId, 'Premium feature unlocked!');
}
});Each citation function returns true if the sender matches any ID in the returned list, false otherwise.
How it works:
Citation functions return an array of phone numbers, group id and lid Internally, Zaileys compares the sender's ID against this list by checking:
roomId- The chat/group IDsenderId- The sender's WhatsApp IDsenderLid- The sender's LID
If any of these match a number in your returned array, the citation check returns true. This makes it flexible for both individual chats and group scenarios.
Context Injection allows you to inject custom data that is accessible in every message context.
1. Inject data:
// Inject data anywhere in your app
wa.inject('user', { name: 'Kejaa', role: 'admin' });
wa.inject('config', { debug: true, version: '1.0.0' });2. Access injected data in handlers:
wa.on('messages', async (ctx) => {
console.log(ctx.injection.user); // { name: 'John', role: 'admin' }
console.log(ctx.injection.config); // { debug: true, version: '1.0.0' }
});3. Manage injections:
// Get injection value
const user = wa.getInjection('user');
// Remove specific injection
wa.removeInjection('user');
// Clear all injections
wa.clearInjections();This is perfect for sharing database connections, user sessions, or configuration across all handlers.
Zaileys includes an intelligent HealthManager that monitors your connection and automatically repairs corrupted sessions.
- Bad MAC Repair: Automatically detects "Bad MAC" errors and repairs the affected session keys without requiring a full logout.
- Log Suppression: Silences noisy stack traces and internal error messages from
libsignal-nodeto keep your terminal clean. - Zero Config: Enabled by default and works silently in the background.
Keep your database lean and performant by enabling automatic cleanup of old messages.
const wa = new Client({
autoCleanUp: {
enabled: true,
intervalMs: 60 * 60 * 1000, // Run every 1 hour
maxAgeMs: 24 * 60 * 60 * 1000, // Delete messages older than 24 hours
scopes: ['messages'], // Database scopes to clean
},
});The CleanUpManager runs in the background and ensures your storage usage stays within limits.
Quick Jump: Text · Reply · Forward · Media · Banner · Location · Contact · Poll · Reaction · Presence · Mentions · Edit & Delete · Buttons · Member Label
Send a simple text message to any chat.
await wa.send(ctx.roomId, 'Hello World!');
await wa.send(ctx.roomId, {
text: 'Hello with options!',
});Reply to a specific message using the replied option.
await wa.send(ctx.roomId, {
text: 'This is a reply!',
replied: ctx.message(),
});Forward message to any chat.
await wa.forward(ctx.roomId, {
text: 'Forwarded message',
isForwardedMany: true,
});Send images, videos, audio, stickers, or documents. Media can be a URL, Buffer, or base64 string.
Image:
await wa.send(ctx.roomId, {
image: 'https://example.com/image.jpg',
caption: 'Check this out!',
});
await wa.send(ctx.roomId, {
image: fs.readFileSync('./image.jpg'),
caption: 'Image from buffer',
isViewOnce: true,
});Video:
await wa.send(ctx.roomId, {
video: 'https://example.com/video.mp4',
caption: 'Cool video!',
ptv: true,
});Audio:
await wa.send(ctx.roomId, {
audio: 'https://example.com/audio.mp3',
ptt: true,
});Sticker:
// support gif and video
await wa.send(ctx.roomId, {
sticker: 'https://example.com/sticker.mp4',
shape: 'circle', // default: 'default' | 'circle' | 'rounded' | 'oval'
});Document:
await wa.send(ctx.roomId, {
document: 'https://example.com/file.pdf',
fileName: 'document.pdf',
caption: 'Here is the file',
});Send messages with an external ad reply banner (link preview).
await wa.send(ctx.roomId, {
text: 'Banner message!',
banner: {
thumbnailUrl: 'https://github.com/zeative.png',
sourceUrl: 'https://jaa.web.id',
title: 'Test Banner',
body: 'Hello World!',
},
});Send location with coordinates.
await wa.send(ctx.roomId, {
location: {
latitude: -6.2,
longitude: 106.816666,
title: 'Jakarta',
footer: 'Capital of Indonesia',
url: 'https://maps.google.com/?q=-6.200000,106.816666',
},
});Send one or multiple contacts.
await wa.send(ctx.roomId, {
contacts: {
title: 'My Contacts',
contacts: [
{
fullname: 'John Doe',
phoneNumber: 6281234567890,
organization: 'Company Inc.',
},
{
fullname: 'Jane Smith',
phoneNumber: 6289876543210,
},
],
},
});Create a poll with multiple options.
await wa.send(ctx.roomId, {
poll: {
name: 'What is your favorite color?',
answers: ['Red', 'Blue', 'Green', 'Yellow'],
isMultiple: false,
},
});React to a message with an emoji.
await wa.reaction(ctx.message(), '👍');
await wa.reaction(ctx.message(), '❤️');Update your presence status in a chat.
await wa.presence(ctx.roomId, 'typing');
await wa.presence(ctx.roomId, 'recording');Mentions are automatically detected when autoMentions is enabled (default: true).
// support lid
await wa.send(ctx.roomId, 'Hello @6281234567890!');Edit message:
const sent = await wa.send(ctx.roomId, 'Original text');
setTimeout(async () => {
await wa.edit(sent, 'Edited text');
}, 2000);Delete message:
const sent = await wa.send(ctx.roomId, 'This will be deleted');
setTimeout(async () => {
await wa.delete(sent);
}, 2000);
// or multiple messages
await wa.delete([sent1, sent2]);Send messages with interactive buttons.
Simple Buttons:
✅ Simple button has support Android/iPhone/Desktop
await wa.button(ctx.roomId, {
text: 'Choose an option:',
buttons: {
type: 'simple',
footer: 'Footer text',
data: [
{ id: 'btn1', text: 'Option 1' },
{ id: 'btn2', text: 'Option 2' },
{ id: 'btn3', text: 'Option 3' },
],
},
});Interactive Buttons:
⚠️ Experimental, only support Android/iPhone
await wa.button(ctx.roomId, {
text: 'Interactive menu:',
buttons: {
type: 'interactive',
footer: 'Footer text',
data: [
{ type: 'quick_reply', id: 'reply1', text: 'Quick Reply' },
{ type: 'cta_url', text: 'Visit Website', url: 'https://example.com' },
{ type: 'cta_copy', id: 'copy1', text: 'Copy Code', copy: 'PROMO123' },
{ type: 'cta_call', text: 'Call Us', phoneNumber: '+6281234567890' },
],
},
});Lists Buttons:
⚠️ Experimental, not supported on some devices. Don't use in production!
await wa.button(ctx.roomId, {
text: 'Choose an option:',
buttons: {
type: 'interactive',
footer: 'Footer text',
data: [
{
type: 'single_select',
text: 'Choose an option:',
section: [
{
title: 'Section 1',
rows: [
{ id: 'btn1', title: 'Option 1' },
{ id: 'btn2', title: 'Option 2' },
{ id: 'btn3', title: 'Option 3' },
],
},
],
},
],
},
});Labeling user member on group chat.
await wa.memberLabel(ctx.roomId, 'Fullstack Developer');Quick Jump: Create · Participants · Profile · Settings · Invite Code · Metadata · Join Requests · Fetch All · Ephemeral · Leave
Manage groups, participants, and settings easily.
Create a new group with initial participants.
// Create group with name and participants
const group = await wa.group.create('My Group', ['senderId']);
console.log('Group created:', group);Add, remove, promote, or demote participants.
const groupId = '1234567890@g.us';
// Add participants
await wa.group.participant(groupId, ['senderId'], 'add');
// Remove participants
await wa.group.participant(groupId, [...], 'remove');
// Promote to admin
await wa.group.participant(groupId, [...], 'promote');
// Demote to member
await wa.group.participant(groupId, [...], 'demote');Update group subject, description, or icon.
// Update subject
await wa.group.profile(groupId, 'New Group Name', 'subject');
// Update description
await wa.group.profile(groupId, 'This is the new description', 'description');
// Update group avatar (from URL or Buffer)
await wa.group.profile(groupId, 'https://example.com/icon.jpg', 'avatar');Configure group permissions.
// All members can send messages
await wa.group.setting(groupId, 'open');
// Only admins can send messages
await wa.group.setting(groupId, 'close');
// Only admins can edit group info
await wa.group.setting(groupId, 'locked');
// All members can edit group info
await wa.group.setting(groupId, 'unlocked');
// Only admins can add members
await wa.group.setting(groupId, 'admin_add');
// All members can add members
await wa.group.setting(groupId, 'all_member_add');Manage group invite links.
// Get current invite code
const code = await wa.group.inviteCode(groupId, 'code');
console.log('Invite link:', `https://chat.whatsapp.com/${code}`);
// Revoke invite code
await wa.group.inviteCode(groupId, 'revoke');
// Get invite info
const info = await wa.group.inviteCode('INVITE_CODE', 'info');
// Join group via invite code
await wa.group.inviteCode('INVITE_CODE', 'accept');Get full group metadata.
const metadata = await wa.group.metadata(groupId);
console.log(metadata);Manage pending join requests.
// Get list of pending requests
const requests = await wa.group.requestJoinList(groupId);
// Approve requests
await wa.group.requestJoin(groupId, ['senderId'], 'approve');
// Reject requests
await wa.group.requestJoin(groupId, [...], 'reject');Get all groups the bot is part of.
const groups = await wa.group.fetchAllGroups();
console.log('Joined groups:', Object.keys(groups).length);Set disappearing messages in groups.
// Turn off disappearing messages
await wa.group.ephemeral(groupId, 'off');
// Set to 24 hours
await wa.group.ephemeral(groupId, '24h');
// Set to 7 days
await wa.group.ephemeral(groupId, '7d');
// Set to 90 days
await wa.group.ephemeral(groupId, '90d');Leave group.
await wa.group.leave(groupId);Create and manage WhatsApp Channels (Newsletters).
Quick Jump: Create · Actions · Update · Info · Messages · Admin
const channel = await wa.newsletter.create('My Channel', 'Description here');
console.log('Channel created:', channel);Follow, unfollow, mute, or unmute a channel.
const channelId = '1234567890@newsletter';
// Follow
await wa.newsletter.action(channelId, 'follow');
// Unfollow
await wa.newsletter.action(channelId, 'unfollow');
// Mute
await wa.newsletter.action(channelId, 'mute');
// Unmute
await wa.newsletter.action(channelId, 'unmute');Update channel info.
// Update name
await wa.newsletter.update(channelId, 'New Name', 'name');
// Update description
await wa.newsletter.update(channelId, 'New Description', 'description');
// Update picture (URL/Buffer)
await wa.newsletter.update(channelId, 'https://example.com/image.jpg', 'picture');
// Remove picture
await wa.newsletter.removePicture(channelId);Get channel details.
// Get metadata by ChannelId
const meta = await wa.newsletter.metadata(channelId, 'jid');
// Get metadata by Invite Code
const metaInvite = await wa.newsletter.metadata('INVITE_CODE', 'invite');
// Get subscribers
const subs = await wa.newsletter.subscribers(channelId);
// Get admin count
const adminCount = await wa.newsletter.adminCount(channelId);Fetch messages or react to them.
// Fetch messages
const since = new Date() - 1000 * 60 * 60 * 24; // 1 day
const after = new Date();
const count = 10;
const messages = await wa.newsletter.fetchMessages(channelId, count, since, after);
// React to message
await wa.newsletter.reaction(channelId, 'chatId', '👍');Manage channel ownership and admins.
// Change owner
await wa.newsletter.changeOwner(channelId, 'senderId');
// Demote admin
await wa.newsletter.demote(channelId, 'senderId');
// Delete channel
await wa.newsletter.delete(channelId);Create and manage WhatsApp Communities.
Quick Jump: Create · Create Group · Groups · Info · Participants · Invite · Settings · Leave
const community = await wa.community.create('My Community', 'Description here');
console.log('Community created:', community);Create a new group linked to a community.
const communityId = '1234567890@g.us';
const group = await wa.community.createGroup('New Group', ['senderId'], communityId);Link or unlink groups from a community.
const groupId = '0987654321@g.us';
// Link group
await wa.community.group(communityId, 'link', groupId);
// Unlink group
await wa.community.group(communityId, 'unlink', groupId);
// Get linked groups
const linkedGroups = await wa.community.group(communityId, 'linked');Get metadata or update info.
// Get metadata
const meta = await wa.community.metadata(communityId);
// Update subject
await wa.community.update(communityId, 'subject', 'New Name');
// Update description
await wa.community.update(communityId, 'description', 'New Description');Manage community participants.
// List participants
const participants = await wa.community.participants(communityId, 'list');
// Add participant
await wa.community.participants(communityId, 'update', 'add', ['senderId']);
// Remove participant
await wa.community.participants(communityId, 'update', 'remove', ['senderId']);
// Promote to admin
await wa.community.participants(communityId, 'update', 'promote', ['senderId']);
// Demote to member
await wa.community.participants(communityId, 'update', 'demote', ['senderId']);Manage community invite links.
// Get invite code
const code = await wa.community.invite(communityId, 'code');
// Revoke invite code
await wa.community.invite(communityId, 'revoke');
// Get invite info
const info = await wa.community.invite('INVITE_CODE', 'info');
// Join via invite code
await wa.community.invite('INVITE_CODE', 'accept');Configure community settings.
// Toggle ephemeral messages
await wa.community.settings(communityId, 'ephemeral', 86400); // 24 hours
// Who can add members? 'all_member_add' or 'admin_add'
await wa.community.settings(communityId, 'memberAdd', 'admin_add');
// Join approval mode? 'on' or 'off'
await wa.community.settings(communityId, 'approval', 'on');Leave a community.
await wa.community.leave(communityId);Manage your privacy settings and block list.
Quick Jump: Block/Unblock · Configuration · Get Settings
// Block user
await wa.privacy.block('senderId');
// Unblock user
await wa.privacy.unblock('senderId');
// Get blocklist
const blocklist = await wa.privacy.blocklist();Update privacy settings.
// Last Seen: 'all', 'contacts', 'contact_blacklist', 'none'
await wa.privacy.lastSeen('contacts');
// Online: 'all', 'match_last_seen'
await wa.privacy.online('match_last_seen');
// Profile Picture: 'all', 'contacts', 'contact_blacklist', 'none'
await wa.privacy.picture('all');
// Status: 'all', 'contacts', 'contact_blacklist', 'none'
await wa.privacy.status('contacts');
// Read Receipts: 'all', 'none'
await wa.privacy.readReceipt('all');
// Group Add: 'all', 'contacts', 'contact_blacklist', 'none'
await wa.privacy.groupsAdd('contacts');
// Default Disappearing Mode: 'off', '24h', '7d', '90d'
await wa.privacy.ephemeral('90d');Fetch current privacy settings.
const settings = await wa.privacy.getSettings();
console.log(settings);Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create new branch:
git checkout -b feature/my-feature. - Commit your changes:
git commit -m 'Add some feature'. - Push to the branch:
git push origin feature/my-feature. - Open Pull Request.
If you encounter any problems or have feature requests, please open an issue
- Buy me coffee ☕
- Ko-Fi
- Trakteer
- ⭐ Star the repo on GitHub
Distributed under the MIT License. See LICENSE for details.

{ "uniqueId": "Z4D3FCXXXXXXXXXXXXX", "channelId": "Z4D3FCXXXXXXXXXXXXX", "chatId": "ACAE07XXXXXXXXXXXXX", "chatType": "text", "receiverId": "628xxxxxxxx@s.whatsapp.net", "receiverName": "Zaileys", "roomId": "120xxxxxxxx@g.us", "roomName": "Group Test", "senderLid": "272xxxxxxxx@lid", "senderId": "628xxxxxxxx@s.whatsapp.net", "senderName": "kejaa", "senderDevice": "android", "timestamp": 1766045633000, "text": "World Hello! https://github.com/zeative/zaileys", "mentions": ["@628xxxxxxxx", "@123xxxxxxxx"], "links": ["https://github.com/zeative/zaileys"], "isBot": false, "isFromMe": false, "isPrefix": false, "isTagMe": false, "isStatusMention": false, "isGroupStatusMention": false, "isHideTags": true, "isSpam": false, "isGroup": true, "isNewsletter": false, "isQuestion": false, "isStory": false, "isViewOnce": false, "isEdited": false, "isDeleted": false, "isPinned": false, "isUnPinned": false, "isBroadcast": false, "isEphemeral": false, "isForwarded": false, "citation": { "authors": [AsyncFunction (anonymous)], "banned": [AsyncFunction (anonymous)] }, "media": { // ... // buffer promise // stream promise }, "message": [Function (anonymous)], "replied": {} // MessagesContext }