NOTE: I can't guarantee you will not be blocked by using this method, although it has worked for me. WhatsApp does not allow bots or unofficial clients on their platform, so this shouldn't be considered totally safe.
Installation
The module is now available on npm! npm i whatsapp-web.js
Please note that Node v8+ is required due to Puppeteer.
+Please note that Node v10.18.1+ is required due to Puppeteer.
Example usage
const { Client } = require('whatsapp-web.js');
const client = new Client();
@@ -138,6 +138,10 @@ client.initialize();
Mention users
✅
+
+ Mute/unmute chats
+ ✅
+
Get contact info
✅
@@ -520,15 +524,15 @@ client.initialize();
-
-
-
-
+
+
-
Client#
event:message
@@ -584,20 +588,25 @@ client.initialize();
-
+ -
+ Client#
getInviteInfo(inviteCode)
+
+ -
+
-
Client#
getProfilePicUrl(contactId)
-
+ -
+ Client#
getState()
+
+ -
+
- -
- Client#
getState()
-
- -
-
-
Client#
getWWebVersion()
@@ -613,6 +622,11 @@ client.initialize();
-
+ -
+ Client#
logout()
+
+ -
+
-
Client#
muteChat(chatId, unmuteDate)
@@ -670,7 +684,7 @@ client.initialize();
-
-
- ClientInfo#
me
+ ClientInfo#getBatteryStatus()
-
@@ -678,20 +692,25 @@ client.initialize();
+ -
+ ClientInfo#
me
+
+ -
+
-
ClientInfo#
phone
-
+
+
+
+
-
-
-
-
ClientInfo#
pushname
@@ -901,16 +920,6 @@ client.initialize();
-
- -
- GroupChat.
getInviteInfo(inviteCode)
-
- -
-
- -
- GroupChat.
join(inviteCode)
-
- -
-
-
GroupChat#
addParticipants(participantIds)
@@ -956,15 +965,15 @@ client.initialize();
-
-
-
-
+
+
-
GroupChat#
getInviteCode()
@@ -1227,6 +1236,50 @@ client.initialize();
+
+
+ InterfaceController
+
+
+
+ -
+ InterfaceController()
+
+ -
+
+ -
+ InterfaceController#
closeRightDrawer()
+
+ -
+
+
+
+
+
+ -
+ InterfaceController#
openChatDrawer(chatId)
+
+ -
+
+ -
+ InterfaceController#
openChatWindow(chatId)
+
+ -
+
+
+
+
+
+ -
+ InterfaceController#
openMessageDrawer(msgId)
+
+ -
+
+
+
+
+
+
Location
@@ -1931,7 +1984,7 @@ client.initialize();
diff --git a/docs/scripts/jsdoc-toc.js b/docs/scripts/jsdoc-toc.js
index 02c2838..a472d9b 100644
--- a/docs/scripts/jsdoc-toc.js
+++ b/docs/scripts/jsdoc-toc.js
@@ -6,7 +6,7 @@
treeNode.tree({
autoEscape: false,
closedIcon: '⇢',
- data: [{"label":"Globals","id":"global","children":[]},{"label":"Base","id":"Base","children":[]},{"label":"BusinessContact","id":"BusinessContact","children":[]},{"label":"Chat","id":"Chat","children":[]},{"label":"Client","id":"Client","children":[]},{"label":"ClientInfo","id":"ClientInfo","children":[]},{"label":"Contact","id":"Contact","children":[]},{"label":"GroupChat","id":"GroupChat","children":[]},{"label":"GroupNotification","id":"GroupNotification","children":[]},{"label":"Location","id":"Location","children":[]},{"label":"Message","id":"Message","children":[]},{"label":"MessageMedia","id":"MessageMedia","children":[]},{"label":"PrivateChat","id":"PrivateChat","children":[]},{"label":"PrivateContact","id":"PrivateContact","children":[]},{"label":"Util","id":"Util","children":[]}],
+ data: [{"label":"Globals","id":"global","children":[]},{"label":"Base","id":"Base","children":[]},{"label":"BusinessContact","id":"BusinessContact","children":[]},{"label":"Chat","id":"Chat","children":[]},{"label":"Client","id":"Client","children":[]},{"label":"ClientInfo","id":"ClientInfo","children":[]},{"label":"Contact","id":"Contact","children":[]},{"label":"GroupChat","id":"GroupChat","children":[]},{"label":"GroupNotification","id":"GroupNotification","children":[]},{"label":"InterfaceController","id":"InterfaceController","children":[]},{"label":"Location","id":"Location","children":[]},{"label":"Message","id":"Message","children":[]},{"label":"MessageMedia","id":"MessageMedia","children":[]},{"label":"PrivateChat","id":"PrivateChat","children":[]},{"label":"PrivateContact","id":"PrivateContact","children":[]},{"label":"Util","id":"Util","children":[]}],
openedIcon: ' ⇣',
saveState: false,
useContextMenu: false
diff --git a/docs/structures_Base.js.html b/docs/structures_Base.js.html
index a74e80b..28d9be6 100644
--- a/docs/structures_Base.js.html
+++ b/docs/structures_Base.js.html
@@ -4,7 +4,7 @@
- whatsapp-web.js 1.6.1 » Source: structures/Base.js
+ whatsapp-web.js 1.7.0 » Source: structures/Base.js
@@ -15,7 +15,7 @@
@@ -60,7 +60,7 @@ module.exports = Base;
diff --git a/docs/structures_BusinessContact.js.html b/docs/structures_BusinessContact.js.html
index eb8edb5..a49983b 100644
--- a/docs/structures_BusinessContact.js.html
+++ b/docs/structures_BusinessContact.js.html
@@ -4,7 +4,7 @@
- whatsapp-web.js 1.6.1 » Source: structures/BusinessContact.js
+ whatsapp-web.js 1.7.0 » Source: structures/BusinessContact.js
@@ -15,7 +15,7 @@
@@ -59,7 +59,7 @@ module.exports = BusinessContact;
diff --git a/docs/structures_Chat.js.html b/docs/structures_Chat.js.html
index 93a5e89..c4cb72a 100644
--- a/docs/structures_Chat.js.html
+++ b/docs/structures_Chat.js.html
@@ -4,7 +4,7 @@
- whatsapp-web.js 1.6.1 » Source: structures/Chat.js
+ whatsapp-web.js 1.7.0 » Source: structures/Chat.js
@@ -15,7 +15,7 @@
@@ -207,7 +207,7 @@ class Chat extends Base {
return true;
}, this.id._serialized);
}
-
+
/**
* Stops typing or recording in chat immediately.
*/
@@ -230,7 +230,7 @@ module.exports = Chat;
diff --git a/docs/structures_ClientInfo.js.html b/docs/structures_ClientInfo.js.html
index 8502f93..2da9977 100644
--- a/docs/structures_ClientInfo.js.html
+++ b/docs/structures_ClientInfo.js.html
@@ -4,7 +4,7 @@
- whatsapp-web.js 1.6.1 » Source: structures/ClientInfo.js
+ whatsapp-web.js 1.7.0 » Source: structures/ClientInfo.js
@@ -15,7 +15,7 @@
@@ -77,6 +77,19 @@ class ClientInfo extends Base {
return super._patch(data);
}
+ /**
+ * Get current battery percentage and charging status for the attached device
+ * @returns {object} batteryStatus
+ * @returns {number} batteryStatus.battery - The current battery percentage
+ * @returns {boolean} batteryStatus.plugged - Indicates if the phone is plugged in (true) or not (false)
+ */
+ async getBatteryStatus() {
+ return await this.client.pupPage.evaluate(() => {
+ const { battery, plugged } = window.Store.Conn;
+ return { battery, plugged };
+ });
+ }
+
}
module.exports = ClientInfo;
@@ -89,7 +102,7 @@ module.exports = ClientInfo;
diff --git a/docs/structures_Contact.js.html b/docs/structures_Contact.js.html
index 7528d06..b9f238e 100644
--- a/docs/structures_Contact.js.html
+++ b/docs/structures_Contact.js.html
@@ -4,7 +4,7 @@
- whatsapp-web.js 1.6.1 » Source: structures/Contact.js
+ whatsapp-web.js 1.7.0 » Source: structures/Contact.js
@@ -15,7 +15,7 @@
@@ -149,7 +149,7 @@ module.exports = Contact;
diff --git a/docs/structures_GroupChat.js.html b/docs/structures_GroupChat.js.html
index 26b791d..e8fafb0 100644
--- a/docs/structures_GroupChat.js.html
+++ b/docs/structures_GroupChat.js.html
@@ -4,7 +4,7 @@
- whatsapp-web.js 1.6.1 » Source: structures/GroupChat.js
+ whatsapp-web.js 1.7.0 » Source: structures/GroupChat.js
@@ -15,7 +15,7 @@
@@ -167,27 +167,6 @@ class GroupChat extends Chat {
}, this.id._serialized);
}
- /**
- * Returns an object with information about the invite code's group
- * @param {string} inviteCode
- * @returns {Promise<object>} Invite information
- */
- static async getInviteInfo(inviteCode) {
- return await this.client.pupPage.evaluate(inviteCode => {
- return window.Store.Wap.groupInviteInfo(inviteCode);
- }, inviteCode);
- }
-
- /**
- * Joins a group with an invite code
- * @param {string} inviteCode
- */
- static async join(inviteCode) {
- return await this.client.pupPage.evaluate(inviteCode => {
- return window.Store.Wap.acceptGroupInvite(inviteCode);
- }, inviteCode);
- }
-
/**
* Makes the bot leave the group
*/
@@ -209,7 +188,7 @@ module.exports = GroupChat;
diff --git a/docs/structures_GroupNotification.js.html b/docs/structures_GroupNotification.js.html
index 28506b3..a2c6a77 100644
--- a/docs/structures_GroupNotification.js.html
+++ b/docs/structures_GroupNotification.js.html
@@ -4,7 +4,7 @@
- whatsapp-web.js 1.6.1 » Source: structures/GroupNotification.js
+ whatsapp-web.js 1.7.0 » Source: structures/GroupNotification.js
@@ -15,7 +15,7 @@
@@ -143,7 +143,7 @@ module.exports = GroupNotification;
diff --git a/docs/structures_Location.js.html b/docs/structures_Location.js.html
index 2961ef4..1edbebf 100644
--- a/docs/structures_Location.js.html
+++ b/docs/structures_Location.js.html
@@ -4,7 +4,7 @@
- whatsapp-web.js 1.6.1 » Source: structures/Location.js
+ whatsapp-web.js 1.7.0 » Source: structures/Location.js
@@ -15,7 +15,7 @@
@@ -71,7 +71,7 @@ module.exports = Location;
diff --git a/docs/structures_Message.js.html b/docs/structures_Message.js.html
index a07f902..e6f2dcf 100644
--- a/docs/structures_Message.js.html
+++ b/docs/structures_Message.js.html
@@ -4,7 +4,7 @@
- whatsapp-web.js 1.6.1 » Source: structures/Message.js
+ whatsapp-web.js 1.7.0 » Source: structures/Message.js
@@ -15,7 +15,7 @@
@@ -95,7 +95,7 @@ class Message extends Base {
* ID for the Chat that this message was sent to, except if the message was sent by the current user.
* @type {string}
*/
- this.from = typeof (data.from) === 'object' ? data.from._serialized : data.from;
+ this.from = (typeof (data.from) === 'object' && data.from !== null) ? data.from._serialized : data.from;
/**
* ID for who this message is for.
@@ -104,13 +104,13 @@ class Message extends Base {
* If the message is sent by another user, it will be the ID for the current user.
* @type {string}
*/
- this.to = typeof (data.to) === 'object' ? data.to._serialized : data.to;
+ this.to = (typeof (data.to) === 'object' && data.to !== null) ? data.to._serialized : data.to;
/**
* If the message was sent to a group, this field will contain the user that sent the message.
* @type {string}
*/
- this.author = typeof (data.author) === 'object' ? data.author._serialized : data.author;
+ this.author = (typeof (data.author) === 'object' && data.author !== null) ? data.author._serialized : data.author;
/**
* Indicates if the message was forwarded
@@ -287,7 +287,7 @@ module.exports = Message;
diff --git a/docs/structures_MessageMedia.js.html b/docs/structures_MessageMedia.js.html
index 0bce416..0e3d474 100644
--- a/docs/structures_MessageMedia.js.html
+++ b/docs/structures_MessageMedia.js.html
@@ -4,7 +4,7 @@
- whatsapp-web.js 1.6.1 » Source: structures/MessageMedia.js
+ whatsapp-web.js 1.7.0 » Source: structures/MessageMedia.js
@@ -15,7 +15,7 @@
@@ -86,7 +86,7 @@ module.exports = MessageMedia;
diff --git a/docs/structures_PrivateChat.js.html b/docs/structures_PrivateChat.js.html
index 643df2e..4b0236e 100644
--- a/docs/structures_PrivateChat.js.html
+++ b/docs/structures_PrivateChat.js.html
@@ -4,7 +4,7 @@
- whatsapp-web.js 1.6.1 » Source: structures/PrivateChat.js
+ whatsapp-web.js 1.7.0 » Source: structures/PrivateChat.js
@@ -15,7 +15,7 @@
@@ -51,7 +51,7 @@ module.exports = PrivateChat;
diff --git a/docs/structures_PrivateContact.js.html b/docs/structures_PrivateContact.js.html
index 35cf729..f2a62ec 100644
--- a/docs/structures_PrivateContact.js.html
+++ b/docs/structures_PrivateContact.js.html
@@ -4,7 +4,7 @@
- whatsapp-web.js 1.6.1 » Source: structures/PrivateContact.js
+ whatsapp-web.js 1.7.0 » Source: structures/PrivateContact.js
@@ -15,7 +15,7 @@
@@ -51,7 +51,7 @@ module.exports = PrivateContact;
diff --git a/docs/util_Constants.js.html b/docs/util_Constants.js.html
index 3c4026a..0890487 100644
--- a/docs/util_Constants.js.html
+++ b/docs/util_Constants.js.html
@@ -4,7 +4,7 @@
- whatsapp-web.js 1.6.1 » Source: util/Constants.js
+ whatsapp-web.js 1.7.0 » Source: util/Constants.js
@@ -15,7 +15,7 @@
@@ -174,7 +174,7 @@ exports.MessageAck = {
diff --git a/docs/util_InterfaceController.js.html b/docs/util_InterfaceController.js.html
new file mode 100644
index 0000000..43c9006
--- /dev/null
+++ b/docs/util_InterfaceController.js.html
@@ -0,0 +1,109 @@
+
+
+
+
+
+
+ whatsapp-web.js 1.7.0 » Source: util/InterfaceController.js
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source: util/InterfaceController.js
+
+
+ 'use strict';
+
+/**
+ * Interface Controller
+ */
+class InterfaceController {
+
+ constructor(props) {
+ this.pupPage = props.pupPage;
+ }
+
+ /**
+ * Opens the Chat Window
+ * @param {string} chatId ID of the chat window that will be opened
+ */
+ async openChatWindow(chatId) {
+ await this.pupPage.evaluate(async chatId => {
+ let chat = await window.Store.Chat.get(chatId);
+ await window.Store.Cmd.openChatAt(chat);
+ }, chatId);
+ }
+
+ /**
+ * Opens the Chat Drawer
+ * @param {string} chatId ID of the chat drawer that will be opened
+ */
+ async openChatDrawer(chatId) {
+ await this.pupPage.evaluate(async chatId => {
+ let chat = await window.Store.Chat.get(chatId);
+ await window.Store.Cmd.chatInfoDrawer(chat);
+ }, chatId);
+ }
+
+ /**
+ * Opens the Message Drawer
+ * @param {string} msgId ID of the message drawer that will be opened
+ */
+ async openMessageDrawer(msgId) {
+ await this.pupPage.evaluate(async msgId => {
+ let msg = await window.Store.Msg.get(msgId);
+ await window.Store.Cmd.msgInfoDrawer(msg);
+ }, msgId);
+ }
+
+ /**
+ * Closes the Right Drawer
+ */
+ async closeRightDrawer() {
+ await this.pupPage.evaluate(async () => {
+ await window.Store.Cmd.closeDrawerRight();
+ });
+ }
+
+}
+
+module.exports = InterfaceController;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/docs/util_Util.js.html b/docs/util_Util.js.html
index a31697c..642044b 100644
--- a/docs/util_Util.js.html
+++ b/docs/util_Util.js.html
@@ -4,7 +4,7 @@
- whatsapp-web.js 1.6.1 » Source: util/Util.js
+ whatsapp-web.js 1.7.0 » Source: util/Util.js
@@ -15,7 +15,7 @@
@@ -73,7 +73,7 @@ module.exports = Util;
diff --git a/package.json b/package.json
index 915c908..d654fa6 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "whatsapp-web.js",
- "version": "1.6.1-post",
+ "version": "1.7.0",
"description": "Library for interacting with the WhatsApp Web API ",
"main": "./index.js",
"typings": "./index.d.ts",