New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

zaileys

Package Overview
Dependencies
Maintainers
0
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zaileys

Zaileys - Simplify Typescript/Javascript WhatsApp NodeJS API

  • 0.29.4-beta
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
93
decreased by-89.52%
Maintainers
0
Weekly downloads
 
Created
Source
Zaileys - Simplify Typescript/Javascript WhatsApp NodeJS API

Zaileys - Simplify Typescript/Javascript WhatsApp NodeJS API

NPM Version NPM Downloads GitHub code size in bytes GitHub License GitHub Repo stars GitHub forks

[!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

// ESM
import { Client } from "zaileys";

// CJS
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: "/", // for command message, example '/'
  ignoreMe: true, // ignore messages from bot (bot phone number)
  phoneNumber: 628xxx, // fill bot phone number if auth type is 'pairing'
  authPath: ".zaileys", // auth directory path for session and chat store
  authType: "pairing", // auth type 'pairing' or 'qr'
  showLogs: true, // show logs of any chats
  autoMentions: true, // bot will be auto mentioned if text contains sender number with '@' prefix
  autoOnline: true, // bot status will be mark online
  autoRead: true, // auto read message from any chats
  autoRejectCall: true,  // auto reject call if someone call you
  citation: {
    // your citation will be boolean object based on validate with your value
    // system will be validate your value with 'senderId' and 'roomId'
    // if one is valid then the key will return 'boolean'
    // sample output: { isAuthors: boolean }

    // just sample, you can rename with any key
    authors: () => ["628xxxx"], // key 'authors' will be 'isAuthors'
    myGroups: () => ["1203633xxxxx"], // key 'myGroups' will be 'isMyGroups'
    ...otherKey // key 'otherKey' will be 'isOtherKey'
  },
});

[!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) => {}); // listener for current connection
wa.on("message", (ctx) => {}); // listener for message from any chats
wa.on("command", (ctx) => {}); // listener for message that starts with prefix at beginning of word
wa.on("call", (ctx) => {}); // listener for someone call to bot

🔹 Connection Handler

wa.on("connection", (ctx) => {
  if (ctx.status == "open") {
    // do something
  }
});

🔹 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);
  }

  // text from reply message
  if (ctx.reply?.text == "ping") {
    wa.sendText("Pong from reply!");
  }

  // text from nested reply message
  // you can retrieve reply messages of any depth
  if (ctx.reply?.reply?.reply?.text == "ping") {
    wa.sendText("Pong from nested reply!");
  }

  // text with footer message (doesn't work on whatsapp desktop)
  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!");
  }

  // reply with footer message (doesn't work on whatsapp desktop)
  if (ctx.text == "pong") {
    wa.sendReply("Ping!", { footer: "Footer message" });
  }

  // reply with fake verified badge
  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) => {
  // for example set prefix to "/"
  // and user text "/test"
  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");
    // example output: "Here user mentioned: @WhatsApp @ChatGPT"

    // if `autoMentions` is inactive or `false`
    // output can be plain text: "Here user mentioned: @0 @18002428478"
  }
});

🔹 Citation Handler

[!NOTE] You must set citation like example above before

const wa = new Client({
  ...,

  // just example you can edit with your own
  citation: {
    authors: () => ["628xxxx"],
    myPrivateGroups: () => ["1203633xxxxx"],
    bannedUsers: async () => {
      const res = await fetch("/get/user/banned")
      const users = await res.json()

      return users // ["628xx", "628xx", "628xx"]
    }
  }
})

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:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix (git checkout -b feature/your-feature-name or git checkout -b fix/bug-description).
  3. Make your changes and commit them (git commit -m 'Add some AmazingFeature').
  4. Push your changes to your forked repository (git push origin feature/your-feature-name).
  5. 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.

Keywords

FAQs

Package last updated on 08 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc