@deathabyss/wwebjs-sender

1.93.2 • Public • Published

Npm package version Npm package weekly downloads GitHub stars CC BY-NC-SA 4.0

This package creates embeds and buttons in a very simple way using the whatsapp-web.js module for whatsapp.

NOTE : Internally whatsapp-web.js is being used to send and receive messages. Though it has been safe as per my testing, I cannot promise that your number will not be blocked by Whatsapp. Also, this project is not affiliated, associated, authorized or endorsed with Whatsapp or any of its subsidiaries or affiliates in any way.


🔗 Links


🚀 Installation:

Install the package @deathabyss/wwebjs-sender with npm or yarn

npm

npm i @deathabyss/wwebjs-sender
yarn

yarn add @deathabyss/wwebjs-sender

Install the package whatsapp-web.js with npm or yarn

npm

npm i whatsapp-web.js
yarn

yarn add whatsapp-web.js

Update 🔁

Update the package @deathabyss/wwebjs-sender with npm or yarn

npm

npm r @deathabyss/wwebjs-sender && npm i @deathabyss/wwebjs-sender
yarn

yarn remove @deathabyss/wwebjs-sender && yarn add @deathabyss/wwebjs-sender

Update the package whatsapp-web.js with npm or yarn

npm

npm r whatsapp-web.js && npm i whatsapp-web.js
yarn

yarn remove whatsapp-web.js && yarn add whatsapp-web.js

✨ Features:

  • Create embeds in an easy way
  • Create buttons in an easy way
  • Reply to messages with embed
  • Send messages to a number with embeds and buttons at the same time in an easy way
  • Collect messages by event handler, collect answers of message and embed collectors

👀 Example of embed and button usage:

const WwebjsSender = require("@deathabyss/wwebjs-sender");
const { Client } = require("whatsapp-web.js");

const client = new Client();

client.on("qr", (qr) => {
  console.log("QR RECEIVED", qr);
});

client.on("ready", () => {
  console.log("Client is ready!");
});

client.on("message", (msg) => {
  if (msg.body == "!command") {
    const { from } = msg;
    let embed = new WwebjsSender.MessageEmbed()
      .sizeEmbed(28)
      .setTitle("✅ | Successful process!")
      .setDescription("The process has been successful!")
      .addField("✔", "To confirm")
      .addField("❌", "To cancel")
      .addFields({
        name: "Now you have 2 buttons to choose!",
        value: "✔ or ❌",
      })
      .setFooter("WwebjsSender")
      .setTimestamp();

    let button1 = new WwebjsSender.MessageButton()
      .setCustomId("confirm")
      .setLabel("✔");

    let button2 = new WwebjsSender.MessageButton()
      .setCustomId("cancel")
      .setLabel("❌");

    WwebjsSender.send({
      client: client,
      number: from,
      embed: embed,
      button: [button1, button2],
    });
  }
});

client.initialize();

👀 Example of embed and button usage result:

👀 Example of collector usage:

const WwebjsSender = require("@deathabyss/wwebjs-sender");
const { Client } = require("whatsapp-web.js");

const client = new Client();

client.on("qr", (qr) => {
  console.log("QR RECEIVED", qr);
});

client.on("ready", () => {
  console.log("Client is ready!");
});

client.on("message", async (msg) => {
  if (msg.body == "!command") {
    const { from } = msg;
    const chat = await msg.getChat();

    let someEmbed = new WwebjsSender.MessageEmbed()
      .sizeEmbed(24)
      .setTitle(`1️⃣ | What is your name?`)
      .setDescription(`Please, type your name.`)
      .setFooter(`Question!`)
      .setTimestamp();

    let anotherEmbed = new WwebjsSender.MessageEmbed()
      .sizeEmbed(24)
      .setTitle(`2️⃣ | What is your age?`)
      .setDescription(`Please, type your age.`)
      .setFooter(`Question!`)
      .setTimestamp();

    let collect = new WwebjsSender.Collector({
      client: client,
      chat: chat,
      time: 10000,
      number: from,
      max: [20, 3],
      question: ["What is your name?", "What is your age?"],
      embed: [someEmbed, anotherEmbed],
    });

    collect.on("message", async (msg) => {
      let body = msg.body;
      console.log(body);
    });

    collect.initialize();

    let resultMessageQuestion = await collect.messageQuestionCollcetor();

    let resultEmbedQuestion = await collect.embedQuestionCollector();

    console.log(resultMessageQuestion, resultEmbedQuestion);
  }
});

client.initialize();

📚 Usage:

MessageEmbed

let embed = new MessageEmbed() //Call the constructor MessageEmbed
  .sizeEmbed(28) //Set horizontal size of the embed in pixel [optional] [default 28 pixels]
  .setTitle("Title") //Set a title for the embed [optional]
  .setDescription("Description") //Set a description for the embed [required]
  .setFooter("Footer") //Set a footer for the embed [optional]
  .addField("Name", "Value") //Set a field name for the embed [optional]
  .addFields({ name: "Name", value: "Value" }) //set fields for the embed [optional]
  .setTimestamp(); //Set a timestamp for the embed [optional]

MessageButton

let button = new MessageButton() //Call the constructor MessageButton
  .setCustomId("Id") //Set a custom id for the button [optional]
  .setLabel("Label"); //Set a label for the button [required]

Reply

reply({
  message: msg, //The message that was received [required]
  embed: embed, //The embed [required]
});

Send

send({
  client: client, //The client of the bot [required]
  number: number, //The number to send the message [required]
  embed: embed, //The embed [required]
  button: [button], //The button/s [optional]
});

Collector

let collect = new Collector({
  client: client, //The client of the bot [required]
  chat: chat, //The chat to send the message [required]
  time: time, //The time to wait for the answer [required]
  number: number, //The number to send the message [required]
  max: [number, number2], //The max characters per question [optional]
  question: [string, string2], //The question/s to ask [optional]
  embed: [embed, embed2], //The embed/s to send [optional]
});

Collect Message Event

collect.on("message", async (msg) => {
  let body = msg.body; //The body of the message received
});

await collect.initialize(); //Initialize the collector [required]

Collect Message Question/s

let resultMessageQuestion = await collect.messageQuestionCollcetor(); //Get the message answer/s [required]

Collect Embed Question/s

let resultEmbedQuestion = await collect.embedQuestionCollector(); //Get the embed answer/s [required]

📁 Contributing

1 - Fork it (https://github.com/yourname/yourproject/fork)

2 - Create your feature branch (git checkout -b features/thing)

3 - Commit your changes (git commit -am 'feat(image): Add some thing')

4 - Push to the branch (git push origin feature/thing)

5 - Create a new Pull Request


👥 Contributors


DeathAbyss

💻 🎨 🧪 🤔

Leonardo Bagi

💻 🧪 🧾

📖 License

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License CC BY-NC-SA 4.0


Package Sidebar

Install

npm i @deathabyss/wwebjs-sender

Weekly Downloads

16

Version

1.93.2

License

ISC

Unpacked Size

134 kB

Total Files

12

Last publish

Collaborators

  • leonardobagi
  • deathabyss