Zaileys - Simplify Typescript/Javascript WhatsApp NodeJS API
[!WARNING]
This is beta version, not recomended to use in production. Join whatsapp community for latest info WhatsApp Channel
Zaileys is a powerful and flexible WhatsApp API library for Node.js, built on top of Baileys. It simplifies the process of integrating WhatsApp functionalities into your applications, providing a comprehensive set of features for building robust and scalable WhatsApp-based solutions.
# Features
- Multi-Device Support: Leverage the latest WhatsApp multi-device features for enhanced reliability and performance.
- Customizable: Adapt the library to your specific needs with flexible configuration options and modular design.
# Installation
npm add zaileys
pnpm add zaileys
yarn add zaileys
bun add zaileys
deno add npm:zaileys
# Example Code
[!TIP]
If you don't want to take time for setup and configuration, use the example.ts file that I have provided.
# Usage & Configuration
📦 Import Library
import { Client } from "zaileys";
const { Client } = require("zaileys");
⚙️ Configuration
[!WARNING]
Warning! in beta version this library uses built-in Baileys makeInMemoryStore
function which will most likely use quite a lot of RAM.
If you experience this, you can delete the .zaileys/memory.json
file then restart the server.
const wa = new Client({
prefix: "/",
ignoreMe: true,
phoneNumber: 628xxx,
authPath: ".zaileys",
authType: "pairing",
showLogs: true,
autoMentions: true,
autoOnline: true,
autoRead: true,
autoRejectCall: true,
citation: {
authors: () => ["628xxxx"],
myGroups: () => ["1203633xxxxx"],
...otherKey
},
});
[!NOTE]
The functions and parameters below may change at any time considering that this library is a beta version. So when you update a library to the latest version but an error occurs, there may be changes to certain functions and parameters.
🛎️ Event Handler
You can find out the output type of each object in the listener below:
wa.on("connection", (ctx) => {});
wa.on("message", (ctx) => {});
wa.on("command", (ctx) => {});
wa.on("call", (ctx) => {});
🔹 Connection Handler
wa.on("connection", (ctx) => {
if (ctx.status == "open") {
}
});
🔹 Send Text Message
Here you can find out the complete parameters for the .sendText()
function
wa.on("message", (ctx) => {
if (ctx.text == "ping") {
wa.sendText("Hello! " + ctx.senderName);
}
if (ctx.reply?.text == "ping") {
wa.sendText("Pong from reply!");
}
if (ctx.reply?.reply?.reply?.text == "ping") {
wa.sendText("Pong from nested reply!");
}
if (ctx.text == "pong") {
wa.sendText("Ping!", { footer: "Footer message" });
}
});
🔹 Send Reply Message
Here you can find out the complete parameters for the .sendReply()
function
wa.on("message", (ctx) => {
if (ctx.text == "ping") {
wa.sendReply("Pong!");
}
if (ctx.text == "pong") {
wa.sendReply("Ping!", { footer: "Footer message" });
}
if (ctx.text == "fake") {
wa.sendReply("Fake Verified!", { fakeVerified: "whatsapp" });
}
});
Here you can find out all the verified platforms provided
🔹 Send Sticker Message
Here you can find out the complete parameters for the .sendSticker()
function
wa.on("message", async (ctx) => {
if (ctx.chatType == "sticker") {
const sticker = await ctx.media?.buffer!();
wa.sendSticker(sticker);
}
if (ctx.text == "sticker") {
wa.sendSticker("https://gtihub.com/zeative.png");
}
});
🔹 Send Image Message
Here you can find out the complete parameters for the .sendImage()
function
wa.on("message", async (ctx) => {
if (ctx.chatType == "image") {
const image = await ctx.media?.buffer!();
wa.sendImage(image);
}
if (ctx.text == "image") {
wa.sendImage("https://gtihub.com/zeative.png");
}
if (ctx.text == "mypp") {
const picture = await ctx.senderImage();
wa.sendImage(picture);
}
});
🔹 Send Video Message
Here you can find out the complete parameters for the .sendVideo()
function
wa.on("message", async (ctx) => {
if (ctx.chatType == "video") {
const video = await ctx.media?.buffer!();
wa.sendVideo(video);
}
if (ctx.text == "video") {
wa.sendVideo("https://gtihub.com/zeative.png");
}
});
🔹 Send Audio Message
Here you can find out the complete parameters for the .sendAudio()
function
wa.on("message", async (ctx) => {
if (ctx.chatType == "audio") {
const audio = await ctx.media?.buffer!();
wa.sendAudio(audio);
}
if (ctx.text == "audio") {
wa.sendAudio("https://gtihub.com/zeative.png");
}
});
🔹 With Prefix Message
[!NOTE]
You must set prefix
option to anything character
wa.on("message", async (ctx) => {
if (ctx.command == "test") {
wa.sendText("From command message!");
}
});
🔹 Mentioned User
[!NOTE]
You must set autoMentions
option to true
and bot will send text as mentions
wa.on("message", async (ctx) => {
if (ctx.text == "mentions") {
wa.sendText("Here user mentioned: @0 @18002428478");
}
});
🔹 Citation Handler
[!NOTE]
You must set citation
like example above before
const wa = new Client({
...,
citation: {
authors: () => ["628xxxx"],
myPrivateGroups: () => ["1203633xxxxx"],
bannedUsers: async () => {
const res = await fetch("/get/user/banned")
const users = await res.json()
return users
}
}
})
wa.on("message", async (ctx) => {
const isAuthors = ctx.citation?.isAuthors;
const isMyPrivateGroups = ctx.citation?.isMyPrivateGroups;
const isBannedUsers = ctx.citation?.isBannedUsers;
if (isAuthors && ctx.text == "test1") {
wa.sendText("Message for my author: kejaa");
}
if (isMyPrivateGroups && ctx.text == "test2") {
wa.sendText("Message for my private group!");
}
if (isBannedUsers && ctx.text) {
wa.sendText("Your number is banned!");
}
});
# Contributing
Contributions are welcome! Please follow these steps to contribute:
- Fork the repository.
- Create a new branch for your feature or bug fix (
git checkout -b feature/your-feature-name
or git checkout -b fix/bug-description
). - Make your changes and commit them (
git commit -m 'Add some AmazingFeature'
). - Push your changes to your forked repository (
git push origin feature/your-feature-name
). - Submit a pull request to the main repository.
Please ensure your code follows the project's coding standards and includes appropriate tests.
# License
This project is licensed under the MIT License - see the LICENSE file for details.
# Acknowledgements
- Baileys - The WhatsApp Web API library this project is based on.