whats.js
v1.2.1
Published
a simple whatsapp package interface same as discord.js
Downloads
57
Maintainers
Readme
Whatsapp.js | whats.js
- Whatsapp.js | whats.js
- Installation
- Examples
- Docs
Please Consider Joining My Discord Support Server
Why You Should Use Whats.js
Whats.js is simple package that allow you to use whatsapp-web as nodejs client. Using @adiwajshing/baileys ( Modifed )
Change Log ( Latest Release 1.1.1 )
- Bug Fixed.
- Check Change Log v1.1.1
Installation
npm i whats.js@latest
Examples
Simple Source To Start Your Bot
const whatsapp = require("whats.js");
const client = new whatsapp();
Simple Ready Event Listener
const whatsapp = require("whats.js");
const client = new whatsapp();
client.once("ready",async client=>{
console.log(`Account Is Ready , Number : ${client.user.number} , Name : ${client.user.name}`);
})
Simple Message Event Listener
const whatsapp = require("whats.js");
const client = new whatsapp();
client.on("message",async message=>{
if(message.content =="Hi"){
await message.markAsRead(); // Mark The Message As Read
message.reply("Hello World"); // Reply In Same Channel "Group/UserDM"
message.reply("Don't Tell AnyOne But Im a bot ...",true); // Reply In DM.
}
})
Docs
Client
| PROPERTIES | METHODS | EVENTS | | ---------- | ---------------------- | --------------------------------------- | | | login | ready | | | | message | | | | messageUpdate | | | | messageDelete | | | | reactionCreate |
Events
Ready Event
Emitted when the client becomes ready to start working.
| PARAMETER | TYPE | DESCRIPTION |
| --------- | --------------------- | --------------- |
| client | User
| The Client Data |
Message Event
Emitted whenever a message is created.
| PARAMETER | TYPE | DESCRIPTION |
| --------- | --------------------------- | ------------------------ |
| message | Message
| The Created Message Data |
MessageUpdate Event
* Event Still Not Ready Yet.
MessageDelete Event
* Event Still Not Ready Yet.
ReactionCreate Event
* Event Still Not Ready Yet.
login method
Call This Function To Login The Client To WA-WEB Socket Server Required *
client.login();
Classes
User Class
An Object For User's Data. | PROPERTIES | METHODS | | ----------------------------------- | -------------------------------------- | | id | send | | Number | startActivity | | name | |
.id
Current Client's ID As String
.
.number
Current Client's Number As String
.
.name
Current Client's Name As String
.
.send(MessageTypes)
Send A Message To User With Parameter MessageTypes
or String
Required *, Return MessageClass
Of New Message Sent By Client (Cause Circular Class Error Deprecated).
await user.send(`Hi There Using Whats.js 💜.`); // Content OR MessageType Object.
.startActivity(activity)
Start Activity In Current User's DM Such As Typing,Recording,...etc String
.
await user.startActivity(`recording`); // Client Will Show Recording Status At The User's Dm
Message Class
An Object of Message instanse. | PROPERTIES | METHODS | | -------------------------------------- | -------------------------------------------- | | content | reply | | id | markAsRead | | Author | react | | channel | unReact | | media | forward | | | isMediaMessage | | | isButtonResponse | | | isListResponse |
.content
Returns Message Content As String
.
.id
Returns Message ID As String
.
.reply(MessageTypes,Dm)
Reply To Message With Parameters MessageTypes
or String
Required * And Reply In Dm Boolean
, Return MessageClass
Of New Message Sent By Client.
await message.reply(`Hi There Using Whats.js 💜.`,true); // First Content OR MessageType Object, Then Boolean True Or False (Default).
.markAsRead()
Mark A Message As Read (Two blue Ticks), No Parameters.
await message.markAsRead();
.react(Emoji)
React To A Message With An Emoji, Parameters String
Emoji Default : 👀.
await message.react("🍟"); // Fries Are The Best.
.unReact()
UnReact To Previous Reacted Message.
await message.unReact();
.forward(User)
Forward Message To Another User Parameter Must Be User
Required * .
await message.forward(myOtherAccount);
.isMediaMessage()
Returns True
When Its Media Message.
.isButtonResponse()
Returns True
When Its Button Response.
.isListResponse()
Returns True
When Its List Response.
Channel Class
| PROPERTIES | METHODS | | ---------------------------- | ---------------------------------------------- | | id | send | | | startActivity | | | awaitMessages |
.id
Returns Channel ID As String
.
.send(MessageTypes)
Send A Message In Channel With Parameter MessageTypes
or String
Required *, Return MessageClass
Of New Message Sent By Client (Cause Circular Class Error Deprecated).
await channel.send(`Hi There Using Whats.js 💜.`); // Content OR MessageType Object.
.startActivity(activity)
Start Activity In Current Channel Such As Typing,Recording,...etc String
.
await user.startActivity(`recording`); // Client Will Show Recording Status At The Channel
.awaitMessages(filter,maxResults,time)
Create A Message Collector With Filter And Max Results And Time. Parameters Function
Of Messages Filter, Number
Max Number Of Results Collected, Time To Stop Collecting Messages.
let filter = message=> !isNaN(message.content);
let collected = await channel.awaitMessages(filter,1,10000); // Collect Only One Number Content Message In 10,000ms = 10s;
console.log(collected);
Media Class
| PROPERTIES | METHODS | | ---------------------------------- | ---------------------------- | | name | isAudio | | format | isImage | | | isVideo | | | buffer | | | saveFile |
.name
Returns Media File Name As String
.
.format
Returns Media File Format As String
.
.isAudio()
Returns True
If Media File Is An Audio File.
.isImage()
Returns True
If Media File Is An Image File.
.isVideo()
Returns True
If Media File Is A Video File.
.buffer()
Async Function That Returns Buffer
Of The Media File.
await media.buffer(); // returns Buffer.
.saveFile(fileName,path)
Save File In Certain Path And Name Parameters FileName String
, Path String
Default : fileName = Media.name, path = Root Project Path.
await media.saveFile("Video.mp4","./videos");
Types
Activity Types
unavailable
, available
, composing
, recording
, paused
Message Types
MessageAttachment
This Class Can Be Used To Send A File With .send(MessageTypes)
/.send(MessageTypes)
/.reply(MessageTypes)
usage
const attachment = new client.MessageAttachment(path,fileName);
message.reply(Attachment);
MessageButtons
This Type Of Messages Doesn't Show Up For Other WA User Anymore So Its Deprecated *
Deprecated
MessageContact
This is A contact Card Message, Users Can Add Any Contact Quickly Using This Type Of Message.
usage
const contact = new client.MessageContact().setContactName("WA.js Developer").addContact("ASTA","967778117520","X Design Co."); // Parameters Can Be Used Within Class Constructor
message.reply(contact);
MessageLocation
This is A Location On Map Message, You Can Send A Location Using The Latitude,Longitude.
usage
const location = new client.MessageLocation(48.05,12.85); // Latitude,Longitude
channel.send(location);
// Markdowns Will Be More Detailed Soon I Want To Sleep Now LoL