npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@deathabyss/wwebjs-sender

v1.93.2

Published

A package to send messages/buttons using constructors with the whatsapp-web.js package

Downloads

171

Readme

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 i @deathabyss/wwebjs-sender
yarn add @deathabyss/wwebjs-sender

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

npm i whatsapp-web.js
yarn add whatsapp-web.js

Update 🔁

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

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

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

npm r whatsapp-web.js && npm i whatsapp-web.js
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


📖 License

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