+ getContacts()
+
+
getCountryCode(number)
@@ -190,6 +196,9 @@
resetState()
+ saveOrEditAddressbookContact(phoneNumber, firstName, lastName[, syncToAddressbook])
+
+
searchMessages(query[, options])
@@ -217,6 +226,9 @@
setAutoDownloadVideos(flag)
+ setBackgroundSync(flag)
+
+
setDisplayName(displayName)
@@ -624,6 +636,72 @@
Methods
+ async
+ _muteUnmuteChat (chatId, action, unmuteDateTs) → Promise containing {isMuted: boolean, muteExpiration: number}
+ Internal method to mute or unmute the chat
+
+ Parameters
+
+
+
+ Name
+ Type
+ Optional
+ Description
+
+
+
+
+
+ chatId
+
+
+ string
+
+
+
+
+
+ ID of the chat that will be muted/unmuted
+
+
+
+
+ action
+
+
+ string
+
+
+
+
+
+ The action: 'MUTE' or 'UNMUTE'
+
+
+
+
+ unmuteDateTs
+
+
+ number
+
+
+
+
+
+ Timestamp at which the chat will be unmuted
+
+
+
+
+
+
+ Returns
+
+ Promise containing {isMuted: boolean, muteExpiration: number}
+
+
async
acceptGroupV4Invite (inviteInfo) → Promise containing Object
Accepts a private invitation to join a group
@@ -919,6 +997,44 @@
async
+
+
Deletes the contact from user's addressbook
+
+ Parameter
+
+
+
+ Name
+ Type
+ Optional
+ Description
+
+
+
+
+
+ phoneNumber
+
+
+ string
+
+
+
+
+
+ The contact's phone number in a format "17182222222", where "1" is a country code
+
+
+
+
+
+
+ Returns
+
+ Promise containing void
+
+
+
async
deleteProfilePicture () → Promise containing boolean
Deletes the current user's profile picture.
@@ -1580,7 +1696,7 @@
async
- muteChat (chatId, unmuteDate)
+ muteChat (chatId, unmuteDate) → Promise containing {isMuted: boolean, muteExpiration: number}
Mutes this chat forever, unless a date is specified
Parameters
@@ -1619,7 +1735,7 @@
- Date when the chat will be unmuted, leave as is to mute forever
+ Date when the chat will be unmuted, don't provide a value to mute forever
Value can be null.
@@ -1627,6 +1743,10 @@
+ Returns
+
+ Promise containing {isMuted: boolean, muteExpiration: number}
+
async
pinChat () → Promise containing boolean
@@ -1756,6 +1876,83 @@
async
+
+ Save new contact to user's addressbook or edit the existing one
+
+ Parameters
+
+
+
+ Name
+ Type
+ Optional
+ Description
+
+
+
+
+
+ phoneNumber
+
+
+ string
+
+
+
+
+
+ The contact's phone number in a format "17182222222", where "1" is a country code
+
+
+
+
+ firstName
+
+
+ string
+
+
+
+
+
+
+
+
+
+ lastName
+
+
+ string
+
+
+
+
+
+
+
+
+
+ syncToAddressbook
+
+
+ boolean
+
+
+ Yes
+
+
+ If set to true, the contact will also be saved to the user's address book on their phone. False by default
+ Defaults to false.
+
+
+
+
+
+
+ Returns
+
+
+ async
searchMessages (query[, options]) → Promise containing Array of Message
Searches for messages
@@ -2109,6 +2306,45 @@
async
+ setBackgroundSync (flag) → Promise containing boolean
+ Setting background synchronization.
+ NOTE: this action will take effect after you restart the client.
+
+ Parameter
+
+
+
+ Name
+ Type
+ Optional
+ Description
+
+
+
+
+
+ flag
+
+
+ boolean
+
+
+
+
+
+ true/false
+
+
+
+
+
+
+ Returns
+
+ Promise containing boolean
+
+
+ async
setDisplayName (displayName) → Promise containing Boolean
Sets the current user's display name.
This is the name shown to WhatsApp users that have not added you as a contact beside your number in groups and in your profile.
@@ -2269,7 +2505,7 @@
async
-
unmuteChat (chatId)
+
unmuteChat (chatId) → Promise containing {isMuted: boolean, muteExpiration: number}
Unmutes the Chat
Parameter
@@ -2301,6 +2537,10 @@
+ Returns
+
+ Promise containing {isMuted: boolean, muteExpiration: number}
+
async
unpinChat () → Promise containing boolean
@@ -3580,7 +3820,7 @@
diff --git a/docs/Client.js.html b/docs/Client.js.html
index dfb9ab2..038e3d7 100644
--- a/docs/Client.js.html
+++ b/docs/Client.js.html
@@ -4,7 +4,7 @@
-
whatsapp-web.js 1.28.0 » Source: Client.js
+
whatsapp-web.js 1.28.1-alpha.0 » Source: Client.js
@@ -15,7 +15,7 @@
@@ -309,7 +309,7 @@ class Client extends EventEmitter {
await this.authStrategy.beforeBrowserInitialized();
const puppeteerOpts = this.options.puppeteer;
- if (puppeteerOpts && puppeteerOpts.browserWSEndpoint) {
+ if (puppeteerOpts && (puppeteerOpts.browserWSEndpoint || puppeteerOpts.browserURL)) {
browser = await puppeteer.connect(puppeteerOpts);
page = await browser.newPage();
} else {
@@ -1224,25 +1224,38 @@ class Client extends EventEmitter {
/**
* Mutes this chat forever, unless a date is specified
* @param {string} chatId ID of the chat that will be muted
- * @param {?Date} unmuteDate Date when the chat will be unmuted, leave as is to mute forever
+ * @param {?Date} unmuteDate Date when the chat will be unmuted, don't provide a value to mute forever
+ * @returns {Promise<{isMuted: boolean, muteExpiration: number}>}
*/
async muteChat(chatId, unmuteDate) {
- unmuteDate = unmuteDate ? unmuteDate.getTime() / 1000 : -1;
- await this.pupPage.evaluate(async (chatId, timestamp) => {
- let chat = await window.Store.Chat.get(chatId);
- await chat.mute.mute({expiration: timestamp, sendDevice:!0});
- }, chatId, unmuteDate || -1);
+ unmuteDate = unmuteDate ? Math.floor(unmuteDate.getTime() / 1000) : -1;
+ return this._muteUnmuteChat(chatId, 'MUTE', unmuteDate);
}
/**
* Unmutes the Chat
* @param {string} chatId ID of the chat that will be unmuted
+ * @returns {Promise<{isMuted: boolean, muteExpiration: number}>}
*/
async unmuteChat(chatId) {
- await this.pupPage.evaluate(async chatId => {
- let chat = await window.Store.Chat.get(chatId);
- await window.Store.Cmd.muteChat(chat, false);
- }, chatId);
+ return this._muteUnmuteChat(chatId, 'UNMUTE');
+ }
+
+ /**
+ * Internal method to mute or unmute the chat
+ * @param {string} chatId ID of the chat that will be muted/unmuted
+ * @param {string} action The action: 'MUTE' or 'UNMUTE'
+ * @param {number} unmuteDateTs Timestamp at which the chat will be unmuted
+ * @returns {Promise<{isMuted: boolean, muteExpiration: number}>}
+ */
+ async _muteUnmuteChat (chatId, action, unmuteDateTs) {
+ return this.pupPage.evaluate(async (chatId, action, unmuteDateTs) => {
+ const chat = window.Store.Chat.get(chatId) ?? await window.Store.Chat.find(chatId);
+ action === 'MUTE'
+ ? await chat.mute.mute({ expiration: unmuteDateTs, sendDevice: true })
+ : await chat.mute.unmute({ sendDevice: true });
+ return { isMuted: chat.mute.expiration !== 0, muteExpiration: chat.mute.expiration };
+ }, chatId, action, unmuteDateTs || -1);
}
/**
@@ -1312,7 +1325,7 @@ class Client extends EventEmitter {
*/
async resetState() {
await this.pupPage.evaluate(() => {
- window.Store.AppState.phoneWatchdog.shiftTimer.forceRunNow();
+ window.Store.AppState.reconnect();
});
}
@@ -1752,6 +1765,23 @@ class Client extends EventEmitter {
}, flag);
}
+ /**
+ * Setting background synchronization.
+ * NOTE: this action will take effect after you restart the client.
+ * @param {boolean} flag true/false
+ * @returns {Promise<boolean>}
+ */
+ async setBackgroundSync(flag) {
+ return await this.pupPage.evaluate(async flag => {
+ const backSync = window.Store.Settings.getGlobalOfflineNotifications();
+ if (backSync === flag) {
+ return flag;
+ }
+ await window.Store.Settings.setGlobalOfflineNotifications(flag);
+ return flag;
+ }, flag);
+ }
+
/**
* Get user device count by ID
* Each WaWeb Connection counts as one device, and the phone (if exists) counts as one
@@ -1776,8 +1806,9 @@ class Client extends EventEmitter {
*/
async syncHistory(chatId) {
return await this.pupPage.evaluate(async (chatId) => {
- const chat = await window.WWebJS.getChat(chatId);
- if (chat.endOfHistoryTransferType === 0) {
+ const chatWid = window.Store.WidFactory.createWid(chatId);
+ const chat = window.Store.Chat.get(chatWid) ?? (await window.Store.Chat.find(chatWid));
+ if (chat?.endOfHistoryTransferType === 0) {
await window.Store.HistorySync.sendPeerDataOperationRequest(3, {
chatId: chat.id
});
@@ -1786,6 +1817,39 @@ class Client extends EventEmitter {
return false;
}, chatId);
}
+
+ /**
+ * Save new contact to user's addressbook or edit the existing one
+ * @param {string} phoneNumber The contact's phone number in a format "17182222222", where "1" is a country code
+ * @param {string} firstName
+ * @param {string} lastName
+ * @param {boolean} [syncToAddressbook = false] If set to true, the contact will also be saved to the user's address book on their phone. False by default
+ * @returns {Promise<import('..').ChatId>} Object in a wid format
+ */
+ async saveOrEditAddressbookContact(phoneNumber, firstName, lastName, syncToAddressbook = false)
+ {
+ return await this.pupPage.evaluate(async (phoneNumber, firstName, lastName, syncToAddressbook) => {
+ return await window.Store.AddressbookContactUtils.saveContactAction(
+ phoneNumber,
+ null,
+ firstName,
+ lastName,
+ syncToAddressbook
+ );
+ }, phoneNumber, firstName, lastName, syncToAddressbook);
+ }
+
+ /**
+ * Deletes the contact from user's addressbook
+ * @param {string} phoneNumber The contact's phone number in a format "17182222222", where "1" is a country code
+ * @returns {Promise<void>}
+ */
+ async deleteAddressbookContact(phoneNumber)
+ {
+ return await this.pupPage.evaluate(async (phoneNumber) => {
+ return await window.Store.AddressbookContactUtils.deleteContactAction(phoneNumber);
+ }, phoneNumber);
+ }
}
module.exports = Client;
@@ -1799,7 +1863,7 @@ module.exports = Client;
diff --git a/docs/ClientInfo.html b/docs/ClientInfo.html
index a4a919a..069dcbc 100644
--- a/docs/ClientInfo.html
+++ b/docs/ClientInfo.html
@@ -4,7 +4,7 @@
-
whatsapp-web.js 1.28.0 » Class: ClientInfo
+
whatsapp-web.js 1.28.1-alpha.0 » Class: ClientInfo
@@ -15,7 +15,7 @@
@@ -242,7 +242,7 @@
diff --git a/docs/Contact.html b/docs/Contact.html
index ea55cf5..d82e377 100644
--- a/docs/Contact.html
+++ b/docs/Contact.html
@@ -4,7 +4,7 @@
-
whatsapp-web.js 1.28.0 » Class: Contact
+
whatsapp-web.js 1.28.1-alpha.0 » Class: Contact
@@ -15,7 +15,7 @@
@@ -293,7 +293,7 @@
diff --git a/docs/GroupChat.html b/docs/GroupChat.html
index 6f7ad48..0d8cfbe 100644
--- a/docs/GroupChat.html
+++ b/docs/GroupChat.html
@@ -4,7 +4,7 @@
-
whatsapp-web.js 1.28.0 » Class: GroupChat
+
whatsapp-web.js 1.28.1-alpha.0 » Class: GroupChat
@@ -15,7 +15,7 @@
@@ -684,7 +684,7 @@
Chat#markUnread
async
-
mute (unmuteDate)
+
mute (unmuteDate) → Promise containing {isMuted: boolean, muteExpiration: number}
Mutes this chat forever, unless a date is specified
Parameter
@@ -709,7 +709,7 @@
- Date at which the Chat will be unmuted, leave as is to mute forever
+ Date when the chat will be unmuted, don't provide a value to mute forever
Value can be null.
@@ -719,6 +719,8 @@
Inherited from
Chat#mute
+ Returns
+
async
pin () → Promise containing boolean
@@ -912,7 +914,7 @@
async
sendSeen () → Promise containing Boolean
- Set the message as seen
+ Set the chat as seen
Inherited from
Chat#sendSeen
@@ -1194,11 +1196,13 @@
Chat#unarchive
async
- unmute ()
+ unmute () → Promise containing {isMuted: boolean, muteExpiration: number}
Unmutes this chat
Inherited from
Chat#unmute
+ Returns
+
async
unpin () → Promise containing boolean
@@ -1221,7 +1225,7 @@
diff --git a/docs/GroupNotification.html b/docs/GroupNotification.html
index 3b71871..eb950da 100644
--- a/docs/GroupNotification.html
+++ b/docs/GroupNotification.html
@@ -4,7 +4,7 @@
- whatsapp-web.js 1.28.0 » Class: GroupNotification
+ whatsapp-web.js 1.28.1-alpha.0 » Class: GroupNotification
@@ -15,7 +15,7 @@
@@ -233,7 +233,7 @@
diff --git a/docs/InterfaceController.html b/docs/InterfaceController.html
index 721aa30..6c23bc9 100644
--- a/docs/InterfaceController.html
+++ b/docs/InterfaceController.html
@@ -4,7 +4,7 @@
- whatsapp-web.js 1.28.0 » Class: InterfaceController
+ whatsapp-web.js 1.28.1-alpha.0 » Class: InterfaceController
@@ -15,7 +15,7 @@
@@ -382,7 +382,7 @@
diff --git a/docs/Label.html b/docs/Label.html
index 4fb2323..2c4aef7 100644
--- a/docs/Label.html
+++ b/docs/Label.html
@@ -4,7 +4,7 @@
- whatsapp-web.js 1.28.0 » Class: Label
+ whatsapp-web.js 1.28.1-alpha.0 » Class: Label
@@ -15,7 +15,7 @@
@@ -163,7 +163,7 @@
diff --git a/docs/List.html b/docs/List.html
index 7a1a07c..7bb5bf5 100644
--- a/docs/List.html
+++ b/docs/List.html
@@ -4,7 +4,7 @@
- whatsapp-web.js 1.28.0 » Class: List
+ whatsapp-web.js 1.28.1-alpha.0 » Class: List
@@ -15,7 +15,7 @@
@@ -256,7 +256,7 @@ Returns: [{'title':'sectionTitle','rows':[{'r
diff --git a/docs/LocalAuth.html b/docs/LocalAuth.html
index 62fd8fd..0d0521f 100644
--- a/docs/LocalAuth.html
+++ b/docs/LocalAuth.html
@@ -4,7 +4,7 @@
- whatsapp-web.js 1.28.0 » Class: LocalAuth
+ whatsapp-web.js 1.28.1-alpha.0 » Class: LocalAuth
@@ -15,7 +15,7 @@
@@ -134,7 +134,7 @@
diff --git a/docs/LocalWebCache.html b/docs/LocalWebCache.html
index a27233d..2f96226 100644
--- a/docs/LocalWebCache.html
+++ b/docs/LocalWebCache.html
@@ -4,7 +4,7 @@
- whatsapp-web.js 1.28.0 » Class: LocalWebCache
+ whatsapp-web.js 1.28.1-alpha.0 » Class: LocalWebCache
@@ -15,7 +15,7 @@
@@ -120,7 +120,7 @@
diff --git a/docs/Location.html b/docs/Location.html
index 62ba28c..9e2fc00 100644
--- a/docs/Location.html
+++ b/docs/Location.html
@@ -4,7 +4,7 @@
- whatsapp-web.js 1.28.0 » Class: Location
+ whatsapp-web.js 1.28.1-alpha.0 » Class: Location
@@ -15,7 +15,7 @@
@@ -26,7 +26,7 @@