Jeast Whatsapp API
A Simple whatsapp api that connects through the whatsapp web, that is used for all needs such as sending messages, and authenticating on whatsapp via qr code.
🚀 Installation
Type the npm command below to install the package
npm i jeast-whatsapp-api
or
yarn add jeast-whatsapp-api
Please note that Node v12+ is required.
⭕ Basic usage
const { Jeast } = require("jeast-whatsapp-api");
const client = new Jeast();
client.connect({
logger: true,
qr_terminal: true,
headless: true,
authState: {
isAuth: true,
authId: "example_account",
},
});
client.ev.qr(async (qr) => {
if (qr) {
console.log(qr);
}
});
client.ev.connection(async (connection) => {
if (connection.isConnected) {
console.log("connected!");
}
});
client.ev.message(async (message) => {
if (message.body == "Hello") {
await client.sendMessage(message.id.remote, "Hai");
}
});
Jeast Whatsapp API has various functions, there are several functions that are not tied to existing events, so we will provide documentation of these functions below
Events Listeners
This is a some event listener that return a callback
const { Jeast } = require("jeast-whatsapp-api");
const client = new Jeast();
client.ev.qr(callback);
client.ev.changeState(callback);
client.ev.connection(callback);
client.ev.message(callback);
client.ev.newMessage(callback);
client.ev.revokeMe(callback);
client.ev.revokeAll(callback);
client.ev.uploadMedia(callback);
client.ev.incomingCall(callback);
client.ev.group.join(callback);
client.ev.group.leave(callback);
client.ev.group.update(callback);
Sending Message
This is a function to send a message
const options = {
sendAudioAsVoice: Boolean,
sendVideoAsGif: Boolean,
sendAsSticker: Boolean,
sendAsDocument: Boolean,
};
sendMessage("receiver-number@.c.us", "message", options);
Get Chat List
This is a function to get all chat list
getChats();
Pin Chat By Id
This is a function to pin chat using specified id
pinChatById("receiver-number@c.us");
Unin Chat By Id
This is a function to unpin chat using specified id
unpinChatById("receiver-number@c.us");
Mute Chat
This is a function to mute chat
muteChat("receiver-number@c.us");
Mark Chat as Unread
This is a function to mark as unread chat
markChatAsUnread("receiver-number@c.us");
Logout
This is a function to logout from the whatsapp web
logout();
Search Messages
This is a function to search messages with query type string
const options = {
page: number;
limit: number;
chatId: string;
}
searchMessages(query = 'string', options);
Send Seen
This is a function to send message seen
sendMessageSeen("receiver-number@c.us");
Get Chat By Id
This is a function to get chat using chat id
getChatById("receiver-number@c.us");
Get Phone Country Code
This is a function to get chat using chat id
getPhoneCountry("phone-number");
Create New Group
This is a function to create new group and add some participants
createNewGroup("Test", ["List of participant number id"]);
Get Whatsapp Version
This is a function to get whatsapp version
getWAVersion();
Archive Message
This is a function for archive message by chat id
addToArchive("receiver-number@c.us");
Remove Message From Archive
This is a function for remove message from archive by chat id
removeFromArchive("receiver-number@c.us");
Get Contacts
This is a function to get all contacts
getContacts();
Get Labels
This is a function to get all labels
getLabels();
Get Chat By Label
This is a function to get chat by label id
getChatsByLabel("labelId");
Get All Blocked Contacts
This is a function to get all of blocked contacts
getBlocked()();
🖼 Send as Sticker
const { Jeast, MsgMedia } = require("jeast-whatsapp-api");
const client = new Jeast();
client.connect({
logger: true,
qr_terminal: true,
headless: true,
authState: {
isAuth: true,
authId: "example_account",
},
});
client.ev.qr(async (qr) => {
if (qr) {
console.log(qr);
}
});
client.ev.connection(async (connection) => {
if (connection.isConnected) {
const sticker = MsgMedia.fromFilePath(__dirname + "/path/to/file");
await client.sendMessage("receiver-number@c.us", sticker, {
sendAsSticker: true,
});
}
});
🖻 Send as Document
const { Jeast, MsgMedia } = require("jeast-whatsapp-api");
const client = new Jeast();
client.connect({
logger: true,
qr_terminal: true,
headless: true,
authState: {
isAuth: true,
authId: "example_account",
},
});
client.ev.qr(async (qr) => {
if (qr) {
console.log(qr);
}
});
client.ev.connection(async (connection) => {
if (connection.isConnected) {
const document = MsgMedia.fromFilePath(__dirname + "/path/to/file");
await client.sendMessage("receiver-number@c.us", document, {
sendAsDocument: true,
});
}
});
👾 Send Video as Gif
const { Jeast, MsgMedia } = require("jeast-whatsapp-api");
const client = new Jeast();
client.connect({
logger: true,
executablePath: "/path/to/chrome",
qr_terminal: true,
headless: true,
authState: {
isAuth: true,
authId: "example_account",
},
});
client.ev.qr(async (qr) => {
if (qr) {
console.log(qr);
}
});
client.ev.connection(async (connection) => {
if (connection.isConnected) {
const video = MsgMedia.fromFilePath(__dirname + "/path/to/file");
await client.sendMessage("receiver-number@c.us", video, {
sendVideoAsGif: true,
});
}
});
📑 License
MIT License
Copyright (c) 2022 Ferdian Satria Akbar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.