whatsapp-web.js
A WhatsApp API client that connects through the WhatsApp Web browser app
It uses Puppeteer to run a real instance of Whatsapp Web to avoid getting blocked.
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();
@@ -84,7 +84,7 @@ client.initialize();
Send media (video)
- ✅ (requires google chrome)
+ ✅ (requires google chrome)
Send stickers
@@ -138,6 +138,10 @@ client.initialize();
Mention users
✅
+
+ Mute/unmute chats
+ ✅
+
Get contact info
✅
@@ -155,11 +159,27 @@ client.initialize();
Something missing? Make an issue and let us know!
Links
- - Documentation (preview)
+ - Reference
+ - Guide (work in progress)
- GitHub
Contributing
Pull requests are welcome! If you see something you'd like to add, please do. For drastic changes, please open an issue first.
+ Donating
+ You can support the maintainer of this project through the link below
+
+ Disclaimer
+ This project is not affiliated, associated, authorized, endorsed by, or in any way officially connected with WhatsApp or any of its subsidiaries or its affiliates. The official WhatsApp website can be found at https://whatsapp.com. "WhatsApp" as well as related names, marks, emblems and images are registered trademarks of their respective owners.
+ License
+ Copyright 2019 Pedro S Lopez
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this project except in compliance with the License.
+ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
@@ -316,15 +336,15 @@ client.initialize();
-
-
-
+
+
-
Chat#
id
@@ -340,6 +360,11 @@ client.initialize();
-
+ -
+ Chat#
mute(unmuteDate)
+
+ -
+
-
Chat#
name
@@ -350,15 +375,15 @@ client.initialize();
-
-
-
-
-
+
+
+
-
Chat#
sendStateRecording()
@@ -379,6 +404,11 @@ client.initialize();
-
+ -
+ Chat#
unmute()
+
+ -
+
-
Chat#
unreadCount
@@ -444,6 +474,11 @@ client.initialize();
-
+ -
+ Client#
createGroup(name, participants)
+
+ -
+
-
Client#
destroy()
@@ -459,6 +494,11 @@ client.initialize();
-
+ -
+ Client#
event:change_battery
+
+ -
+
-
Client#
event:change_state
@@ -479,15 +519,20 @@ client.initialize();
-
-
-
-
-
-
Client#
event:group_update
-
+ -
+ Client#
event:media_uploaded
+
+ -
+
+
+
+
+
-
Client#
event:message
@@ -533,10 +578,6 @@ client.initialize();
-
-
-
-
-
-
Client#
getContactById(contactId)
@@ -547,16 +588,50 @@ client.initialize();
-
+ -
+ Client#
getInviteInfo(inviteCode)
+
+ -
+
+ -
+ Client#
getProfilePicUrl(contactId)
+
+ -
+
-
Client#
getState()
-
+
+
+
+
+ -
+ Client#
getWWebVersion()
+
+ -
+
-
Client#
initialize()
-
+ -
+ Client#
isRegisteredUser()
+
+ -
+
+ -
+ Client#
logout()
+
+ -
+
+ -
+ Client#
muteChat(chatId, unmuteDate)
+
+ -
+
-
Client#
resetState()
@@ -567,6 +642,11 @@ client.initialize();
-
+ -
+ Client#
sendPresenceAvailable()
+
+ -
+
-
Client#
sendSeen(chatId)
@@ -582,6 +662,11 @@ client.initialize();
-
+ -
+ Client#
unmuteChat(chatId)
+
+ -
+
@@ -599,7 +684,7 @@ client.initialize();
- ClientInfo#me
+ ClientInfo#getBatteryStatus()
@@ -607,20 +692,25 @@ client.initialize();
+ -
+ ClientInfo#
me
+
+ -
+
-
ClientInfo#
phone
-
+
+
+
+
-
-
-
-
ClientInfo#
pushname
@@ -736,6 +826,11 @@ client.initialize();
-
+ -
+ Events.
BATTERY_CHANGED
+
+ -
+
-
Events.
DISCONNECTED
@@ -760,6 +855,11 @@ client.initialize();
-
+ -
+ Events.
MEDIA_UPLOADED
+
+ -
+
-
Events.
MESSAGE_ACK
@@ -820,16 +920,6 @@ client.initialize();
-
- -
- GroupChat.
getInviteInfo(inviteCode)
-
- -
-
- -
- GroupChat.
join(inviteCode)
-
- -
-
-
GroupChat#
addParticipants(participantIds)
@@ -870,10 +960,6 @@ client.initialize();
-
-
-
-
-
-
GroupChat#
description
@@ -884,6 +970,10 @@ client.initialize();
-
+
+
+
+
-
GroupChat#
getInviteCode()
@@ -909,6 +999,11 @@ client.initialize();
-
+ -
+ GroupChat#
mute(unmuteDate)
+
+ -
+
-
GroupChat#
name
@@ -929,15 +1024,15 @@ client.initialize();
-
-
-
-
+
+
-
GroupChat#
revokeInvite()
@@ -983,6 +1078,11 @@ client.initialize();
-
+ -
+ GroupChat#
unmute()
+
+ -
+
-
GroupChat#
unreadCount
@@ -1136,6 +1236,50 @@ client.initialize();
+
+
+ InterfaceController
+
+
+
+ -
+ InterfaceController()
+
+ -
+
+ -
+ InterfaceController#
closeRightDrawer()
+
+ -
+
+
+
+
+
+ -
+ InterfaceController#
openChatDrawer(chatId)
+
+ -
+
+ -
+ InterfaceController#
openChatWindow(chatId)
+
+ -
+
+
+
+
+
+ -
+ InterfaceController#
openMessageDrawer(msgId)
+
+ -
+
+
+
+
+
+
Location
@@ -1186,6 +1330,11 @@ client.initialize();
+
+ Message#ack
+
+
+
Message#author
@@ -1216,15 +1365,15 @@ client.initialize();
+
+
+
+
-
-
-
-
Message#
getChat()
@@ -1260,20 +1409,25 @@ client.initialize();
-
- -
- Message#
isForwarded
-
- -
-
+ -
+ Message#
isForwarded
+
+ -
+
-
Message#
location
-
+ -
+ Message#
mediaKey
+
+ -
+
-
Message#
mentionedIds
@@ -1365,7 +1519,7 @@ client.initialize();
-
-
- MessageMedia#
data
+ MessageMedia.fromFilePath(filePath)
-
@@ -1373,11 +1527,20 @@ client.initialize();
+ -
+ MessageMedia#
data
+
+ -
+
-
MessageMedia#
filename
-
+
+
+
+
-
MessageMedia#
mimetype
@@ -1385,10 +1548,6 @@ client.initialize();
-
-
-
-
@@ -1507,15 +1666,15 @@ client.initialize();
-
-
-
+
+
-
PrivateChat#
id
@@ -1531,6 +1690,11 @@ client.initialize();
-
+ -
+ PrivateChat#
mute(unmuteDate)
+
+ -
+
-
PrivateChat#
name
@@ -1541,15 +1705,15 @@ client.initialize();
-
-
-
-
-
+
+
+
-
PrivateChat#
sendStateRecording()
@@ -1570,6 +1734,11 @@ client.initialize();
-
+ -
+ PrivateChat#
unmute()
+
+ -
+
-
PrivateChat#
unreadCount
@@ -1815,7 +1984,7 @@ client.initialize();
diff --git a/whatsapp-web.js/docs/scripts/jsdoc-toc.js b/whatsapp-web.js/docs/scripts/jsdoc-toc.js
index 02c2838..a472d9b 100644
--- a/whatsapp-web.js/docs/scripts/jsdoc-toc.js
+++ b/whatsapp-web.js/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/whatsapp-web.js/docs/structures_Base.js.html b/whatsapp-web.js/docs/structures_Base.js.html
index aaf5ffd..28d9be6 100644
--- a/whatsapp-web.js/docs/structures_Base.js.html
+++ b/whatsapp-web.js/docs/structures_Base.js.html
@@ -2,9 +2,9 @@
-
+
- whatsapp-web.js 1.2.1-post » 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/whatsapp-web.js/docs/structures_BusinessContact.js.html b/whatsapp-web.js/docs/structures_BusinessContact.js.html
index e6d10c7..a49983b 100644
--- a/whatsapp-web.js/docs/structures_BusinessContact.js.html
+++ b/whatsapp-web.js/docs/structures_BusinessContact.js.html
@@ -2,9 +2,9 @@
-
+
- whatsapp-web.js 1.2.1-post » 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/whatsapp-web.js/docs/structures_Chat.js.html b/whatsapp-web.js/docs/structures_Chat.js.html
index bf1ac59..c4cb72a 100644
--- a/whatsapp-web.js/docs/structures_Chat.js.html
+++ b/whatsapp-web.js/docs/structures_Chat.js.html
@@ -2,9 +2,9 @@
-
+
- whatsapp-web.js 1.2.1-post » Source: structures/Chat.js
+ whatsapp-web.js 1.7.0 » Source: structures/Chat.js
@@ -15,7 +15,7 @@
@@ -143,6 +143,21 @@ class Chat extends Base {
return this.client.unarchiveChat(this.id._serialized);
}
+ /**
+ * Mutes this chat until a specified date
+ * @param {Date} unmuteDate Date at which the Chat will be unmuted
+ */
+ async mute(unmuteDate) {
+ return this.client.muteChat(this.id._serialized, unmuteDate);
+ }
+
+ /**
+ * Unmutes this chat
+ */
+ async unmute() {
+ return this.client.unmuteChat(this.id._serialized);
+ }
+
/**
* Loads chat messages, sorted from earliest to latest.
* @param {Object} searchOptions Options for searching messages. Right now only limit is supported.
@@ -192,7 +207,7 @@ class Chat extends Base {
return true;
}, this.id._serialized);
}
-
+
/**
* Stops typing or recording in chat immediately.
*/
@@ -215,7 +230,7 @@ module.exports = Chat;
diff --git a/whatsapp-web.js/docs/structures_ClientInfo.js.html b/whatsapp-web.js/docs/structures_ClientInfo.js.html
index 18bf267..2da9977 100644
--- a/whatsapp-web.js/docs/structures_ClientInfo.js.html
+++ b/whatsapp-web.js/docs/structures_ClientInfo.js.html
@@ -2,9 +2,9 @@
-
+
- whatsapp-web.js 1.2.1-post » 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/whatsapp-web.js/docs/structures_Contact.js.html b/whatsapp-web.js/docs/structures_Contact.js.html
index e1473ac..b9f238e 100644
--- a/whatsapp-web.js/docs/structures_Contact.js.html
+++ b/whatsapp-web.js/docs/structures_Contact.js.html
@@ -2,9 +2,9 @@
-
+
- whatsapp-web.js 1.2.1-post » Source: structures/Contact.js
+ whatsapp-web.js 1.7.0 » Source: structures/Contact.js
@@ -15,7 +15,7 @@
@@ -134,11 +134,7 @@ class Contact extends Base {
* @returns {Promise<string>}
*/
async getProfilePicUrl() {
- const profilePic = await this.client.pupPage.evaluate((contactId) => {
- return window.Store.Wap.profilePicFind(contactId);
- }, this.id._serialized);
-
- return profilePic ? profilePic.eurl : undefined;
+ return await this.client.getProfilePicUrl(this.id._serialized);
}
}
@@ -153,7 +149,7 @@ module.exports = Contact;
diff --git a/whatsapp-web.js/docs/structures_GroupChat.js.html b/whatsapp-web.js/docs/structures_GroupChat.js.html
index 6968400..e8fafb0 100644
--- a/whatsapp-web.js/docs/structures_GroupChat.js.html
+++ b/whatsapp-web.js/docs/structures_GroupChat.js.html
@@ -2,9 +2,9 @@
-
+
- whatsapp-web.js 1.2.1-post » 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/whatsapp-web.js/docs/structures_GroupNotification.js.html b/whatsapp-web.js/docs/structures_GroupNotification.js.html
index 033227d..a2c6a77 100644
--- a/whatsapp-web.js/docs/structures_GroupNotification.js.html
+++ b/whatsapp-web.js/docs/structures_GroupNotification.js.html
@@ -2,9 +2,9 @@
-
+
- whatsapp-web.js 1.2.1-post » Source: structures/GroupNotification.js
+ whatsapp-web.js 1.7.0 » Source: structures/GroupNotification.js
@@ -15,7 +15,7 @@
@@ -74,7 +74,7 @@ class GroupNotification extends Base {
*
* @type {string}
*/
- this.chatId = typeof (data.to) === 'object' ? data.to._serialized : data.to;
+ this.chatId = typeof (data.from) === 'object' ? data.from._serialized : data.from;
/**
* ContactId for the user that produced the GroupNotification.
@@ -143,7 +143,7 @@ module.exports = GroupNotification;
diff --git a/whatsapp-web.js/docs/structures_Location.js.html b/whatsapp-web.js/docs/structures_Location.js.html
index 77032dd..1edbebf 100644
--- a/whatsapp-web.js/docs/structures_Location.js.html
+++ b/whatsapp-web.js/docs/structures_Location.js.html
@@ -2,9 +2,9 @@
-
+
- whatsapp-web.js 1.2.1-post » 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/whatsapp-web.js/docs/structures_Message.js.html b/whatsapp-web.js/docs/structures_Message.js.html
index 3869c61..e6f2dcf 100644
--- a/whatsapp-web.js/docs/structures_Message.js.html
+++ b/whatsapp-web.js/docs/structures_Message.js.html
@@ -2,9 +2,9 @@
-
+
- whatsapp-web.js 1.2.1-post » Source: structures/Message.js
+ whatsapp-web.js 1.7.0 » Source: structures/Message.js
@@ -15,7 +15,7 @@
@@ -48,12 +48,25 @@ class Message extends Base {
}
_patch(data) {
+ /**
+ * MediaKey that represents the sticker 'ID'
+ * @type {string}
+ */
+ this.mediaKey = data.mediaKey;
+
+
/**
* ID that represents the message
* @type {object}
*/
this.id = data.id;
+ /**
+ * ACK status for the message
+ * @type {MessageAck}
+ */
+ this.ack = data.ack;
+
/**
* Indicates if the message has media available for download
* @type {boolean}
@@ -82,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.
@@ -91,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
@@ -217,8 +230,19 @@ class Message extends Base {
return undefined;
}
- const {data, mimetype, filename} = await this.client.pupPage.evaluate(async (msgId) => {
+ const result = await this.client.pupPage.evaluate(async (msgId) => {
const msg = window.Store.Msg.get(msgId);
+
+ if(msg.mediaData.mediaStage != 'RESOLVED') {
+ // try to resolve media
+ await msg.downloadMedia(true, 1);
+ }
+
+ if(msg.mediaData.mediaStage.includes('ERROR')) {
+ // media could not be downloaded
+ return undefined;
+ }
+
const buffer = await window.WWebJS.downloadBuffer(msg.clientUrl);
const decrypted = await window.Store.CryptoLib.decryptE2EMedia(msg.type, buffer, msg.mediaKey, msg.mimetype);
const data = await window.WWebJS.readBlobAsync(decrypted._blob);
@@ -231,7 +255,8 @@ class Message extends Base {
}, this.id._serialized);
- return new MessageMedia(mimetype, data, filename);
+ if(!result) return undefined;
+ return new MessageMedia(result.mimetype, result.data, result.filename);
}
/**
@@ -262,7 +287,7 @@ module.exports = Message;
diff --git a/whatsapp-web.js/docs/structures_MessageMedia.js.html b/whatsapp-web.js/docs/structures_MessageMedia.js.html
index e3f1976..0e3d474 100644
--- a/whatsapp-web.js/docs/structures_MessageMedia.js.html
+++ b/whatsapp-web.js/docs/structures_MessageMedia.js.html
@@ -2,9 +2,9 @@
-
+
- whatsapp-web.js 1.2.1-post » Source: structures/MessageMedia.js
+ whatsapp-web.js 1.7.0 » Source: structures/MessageMedia.js
@@ -15,7 +15,7 @@
@@ -31,6 +31,10 @@
'use strict';
+const fs = require('fs');
+const path = require('path');
+const mime = require('mime');
+
/**
* Media attached to a message
* @param {string} mimetype MIME type of the attachment
@@ -57,6 +61,19 @@ class MessageMedia {
*/
this.filename = filename;
}
+
+ /**
+ * Creates a MessageMedia instance from a local file path
+ * @param {string} filePath
+ * @returns {MessageMedia}
+ */
+ static fromFilePath(filePath) {
+ const b64data = fs.readFileSync(filePath, {encoding: 'base64'});
+ const mimetype = mime.getType(filePath);
+ const filename = path.basename(filePath);
+
+ return new MessageMedia(mimetype, b64data, filename);
+ }
}
module.exports = MessageMedia;
@@ -69,7 +86,7 @@ module.exports = MessageMedia;
diff --git a/whatsapp-web.js/docs/structures_PrivateChat.js.html b/whatsapp-web.js/docs/structures_PrivateChat.js.html
index 3d31b2c..4b0236e 100644
--- a/whatsapp-web.js/docs/structures_PrivateChat.js.html
+++ b/whatsapp-web.js/docs/structures_PrivateChat.js.html
@@ -2,9 +2,9 @@
-
+
- whatsapp-web.js 1.2.1-post » 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/whatsapp-web.js/docs/structures_PrivateContact.js.html b/whatsapp-web.js/docs/structures_PrivateContact.js.html
index a8aae10..f2a62ec 100644
--- a/whatsapp-web.js/docs/structures_PrivateContact.js.html
+++ b/whatsapp-web.js/docs/structures_PrivateContact.js.html
@@ -2,9 +2,9 @@
-
+
- whatsapp-web.js 1.2.1-post » 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/whatsapp-web.js/docs/util_Constants.js.html b/whatsapp-web.js/docs/util_Constants.js.html
index 6cb75f4..0890487 100644
--- a/whatsapp-web.js/docs/util_Constants.js.html
+++ b/whatsapp-web.js/docs/util_Constants.js.html
@@ -2,9 +2,9 @@
-
+
- whatsapp-web.js 1.2.1-post » Source: util/Constants.js
+ whatsapp-web.js 1.7.0 » Source: util/Constants.js
@@ -15,7 +15,7 @@
@@ -37,9 +37,15 @@ exports.UserAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) A
exports.DefaultOptions = {
puppeteer: {
- headless: true
+ headless: true,
+ defaultViewport: null
},
- session: false
+ session: false,
+ qrTimeoutMs: 45000,
+ qrRefreshIntervalMs: 20000,
+ authTimeoutMs: 45000,
+ takeoverOnConflict: false,
+ takeoverTimeoutMs: 0
};
/**
@@ -67,12 +73,14 @@ exports.Events = {
MESSAGE_REVOKED_EVERYONE: 'message_revoke_everyone',
MESSAGE_REVOKED_ME: 'message_revoke_me',
MESSAGE_ACK: 'message_ack',
+ MEDIA_UPLOADED: 'media_uploaded',
GROUP_JOIN: 'group_join',
GROUP_LEAVE: 'group_leave',
GROUP_UPDATE: 'group_update',
QR_RECEIVED: 'qr',
DISCONNECTED: 'disconnected',
STATE_CHANGED: 'change_state',
+ BATTERY_CHANGED: 'change_battery'
};
/**
@@ -166,7 +174,7 @@ exports.MessageAck = {
diff --git a/whatsapp-web.js/docs/util_InterfaceController.js.html b/whatsapp-web.js/docs/util_InterfaceController.js.html
new file mode 100644
index 0000000..43c9006
--- /dev/null
+++ b/whatsapp-web.js/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/whatsapp-web.js/docs/util_Util.js.html b/whatsapp-web.js/docs/util_Util.js.html
index 333e5c7..642044b 100644
--- a/whatsapp-web.js/docs/util_Util.js.html
+++ b/whatsapp-web.js/docs/util_Util.js.html
@@ -2,9 +2,9 @@
-
+
- whatsapp-web.js 1.2.1-post » 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/whatsapp-web.js/example.js b/whatsapp-web.js/example.js
index 63c927f..c495e80 100644
--- a/whatsapp-web.js/example.js
+++ b/whatsapp-web.js/example.js
@@ -169,6 +169,12 @@ client.on('message', async msg => {
} else if (msg.body === '!archive') {
const chat = await msg.getChat();
chat.archive();
+ } else if (msg.body === '!mute') {
+ const chat = await msg.getChat();
+ // mute the chat for 20 seconds
+ const unmuteDate = new Date();
+ unmuteDate.setSeconds(unmuteDate.getSeconds() + 20);
+ await chat.mute(unmuteDate);
} else if (msg.body === '!typing') {
const chat = await msg.getChat();
// simulates typing in the chat
@@ -237,6 +243,12 @@ client.on('group_update', (notification) => {
console.log('update', notification);
});
+client.on('change_battery', (batteryInfo) => {
+ // Battery percentage for attached device has changed
+ const { battery, plugged } = batteryInfo;
+ console.log(`Battery: ${battery}% - Charging? ${plugged}`);
+});
+
client.on('disconnected', (reason) => {
console.log('Client was logged out', reason);
});
diff --git a/whatsapp-web.js/index.d.ts b/whatsapp-web.js/index.d.ts
new file mode 100644
index 0000000..fd7014f
--- /dev/null
+++ b/whatsapp-web.js/index.d.ts
@@ -0,0 +1,697 @@
+
+import { EventEmitter } from 'events'
+import puppeteer = require('puppeteer')
+
+declare namespace WAWebJS {
+
+ export class Client extends EventEmitter {
+ constructor(options: ClientOptions)
+
+ /**
+ * Current connection information
+ * @todo add this in the official docs
+ */
+ public info: ClientInfo
+
+ /**Accepts an invitation to join a group */
+ acceptInvite(inviteCode: string): Promise
+
+ /**Returns an object with information about the invite code's group */
+ getInviteInfo(inviteCode: string): Promise