From ef3eadc6e5e237316d4154f19a2f25eb5d2cf56f Mon Sep 17 00:00:00 2001 From: Pedro Lopez Date: Fri, 21 Oct 2022 00:25:57 -0400 Subject: [PATCH] chore: mark version 1.18.0 --- docs/Base.html | 6 +- docs/BaseAuthStrategy.html | 6 +- docs/BusinessContact.html | 6 +- docs/Buttons.html | 6 +- docs/Call.html | 6 +- docs/Chat.html | 22 +- docs/Client.html | 182 +++++++++++- docs/Client.js.html | 105 ++++++- docs/ClientInfo.html | 6 +- docs/Contact.html | 6 +- docs/GroupChat.html | 22 +- docs/GroupNotification.html | 6 +- docs/InterfaceController.html | 6 +- docs/Label.html | 6 +- docs/LegacySessionAuth.html | 6 +- docs/List.html | 6 +- docs/LocalAuth.html | 6 +- docs/Location.html | 6 +- docs/Message.html | 10 +- docs/MessageMedia.html | 43 ++- docs/NoAuth.html | 6 +- docs/Order.html | 6 +- docs/PrivateChat.html | 22 +- docs/PrivateContact.html | 6 +- docs/Product.html | 6 +- docs/Reaction.html | 159 +++++++++++ docs/RemoteAuth.html | 163 +++++++++++ docs/Util.html | 6 +- docs/authStrategies_BaseAuthStrategy.js.html | 9 +- docs/authStrategies_LegacySessionAuth.js.html | 6 +- docs/authStrategies_LocalAuth.js.html | 6 +- docs/authStrategies_NoAuth.js.html | 6 +- docs/authStrategies_RemoteAuth.js.html | 258 ++++++++++++++++++ docs/global.html | 45 ++- docs/index.html | 166 +++++++++-- docs/scripts/jsdoc-toc.js | 2 +- docs/structures_Base.js.html | 6 +- docs/structures_BusinessContact.js.html | 6 +- docs/structures_Buttons.js.html | 6 +- docs/structures_Call.js.html | 6 +- docs/structures_Chat.js.html | 19 +- docs/structures_ClientInfo.js.html | 6 +- docs/structures_Contact.js.html | 6 +- docs/structures_GroupChat.js.html | 6 +- docs/structures_GroupNotification.js.html | 6 +- docs/structures_Label.js.html | 6 +- docs/structures_List.js.html | 6 +- docs/structures_Location.js.html | 6 +- docs/structures_Message.js.html | 23 +- docs/structures_MessageMedia.js.html | 24 +- docs/structures_Order.js.html | 6 +- docs/structures_Payment.js.html | 6 +- docs/structures_PrivateChat.js.html | 6 +- docs/structures_PrivateContact.js.html | 6 +- docs/structures_Product.js.html | 6 +- docs/structures_ProductMetadata.js.html | 6 +- docs/structures_Reaction.js.html | 122 +++++++++ docs/util_Constants.js.html | 13 +- docs/util_InterfaceController.js.html | 6 +- docs/util_Util.js.html | 6 +- package.json | 2 +- 61 files changed, 1437 insertions(+), 220 deletions(-) create mode 100644 docs/Reaction.html create mode 100644 docs/RemoteAuth.html create mode 100644 docs/authStrategies_RemoteAuth.js.html create mode 100644 docs/structures_Reaction.js.html diff --git a/docs/Base.html b/docs/Base.html index 146705d..8d659f4 100644 --- a/docs/Base.html +++ b/docs/Base.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Class: Base + whatsapp-web.js 1.18.0 » Class: Base @@ -15,7 +15,7 @@ @@ -50,7 +50,7 @@ diff --git a/docs/BaseAuthStrategy.html b/docs/BaseAuthStrategy.html index eb1fd0d..f3b4668 100644 --- a/docs/BaseAuthStrategy.html +++ b/docs/BaseAuthStrategy.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Class: BaseAuthStrategy + whatsapp-web.js 1.18.0 » Class: BaseAuthStrategy @@ -15,7 +15,7 @@ @@ -50,7 +50,7 @@ diff --git a/docs/BusinessContact.html b/docs/BusinessContact.html index 86a7d39..f82c6ee 100644 --- a/docs/BusinessContact.html +++ b/docs/BusinessContact.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Class: BusinessContact + whatsapp-web.js 1.18.0 » Class: BusinessContact @@ -15,7 +15,7 @@ @@ -326,7 +326,7 @@ diff --git a/docs/Buttons.html b/docs/Buttons.html index a526910..e5c7e30 100644 --- a/docs/Buttons.html +++ b/docs/Buttons.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Class: Buttons + whatsapp-web.js 1.18.0 » Class: Buttons @@ -15,7 +15,7 @@ @@ -234,7 +234,7 @@ Returns: [{ buttonId:'customId',buttonText:{'displayText':&# diff --git a/docs/Call.html b/docs/Call.html index d6ecec6..7c80fc9 100644 --- a/docs/Call.html +++ b/docs/Call.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Class: Call + whatsapp-web.js 1.18.0 » Class: Call @@ -15,7 +15,7 @@ @@ -144,7 +144,7 @@ diff --git a/docs/Chat.html b/docs/Chat.html index a1f3a9a..eebcf58 100644 --- a/docs/Chat.html +++ b/docs/Chat.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Class: Chat + whatsapp-web.js 1.18.0 » Class: Chat @@ -15,7 +15,7 @@ @@ -271,7 +271,7 @@

 

-

Options for searching messages. Right now only limit is supported.

+

Options for searching messages. Right now only limit and fromMe is supported.

Values in searchOptions have the following properties:

@@ -297,6 +297,20 @@

The amount of messages to return. If no limit is specified, the available messages will be returned. Note that the actual number of returned messages may be smaller if there aren't enough messages in the conversation. Set this to Infinity to load all messages.

+ + + + + +
+

fromMe

+
+

Boolean

+
+

Yes

+
+

Return only messages from the bot number or vise versa. To get all messages, leave the option undefined.

+
@@ -483,7 +497,7 @@ diff --git a/docs/Client.html b/docs/Client.html index 599d86a..24b52a0 100644 --- a/docs/Client.html +++ b/docs/Client.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Class: Client + whatsapp-web.js 1.18.0 » Class: Client @@ -15,7 +15,7 @@ @@ -236,6 +236,9 @@
message_create
+
message_reaction
+
+
message_revoke_everyone
@@ -2181,6 +2184,179 @@
+

message_reaction

+

Emitted when a reaction is sent, received, updated or removed

+
+

Parameters

+ + + + + + + + + + + + + + + + + +
NameTypeOptionalDescription
+

reaction

+
+

object

+
+

 

+
+

Values in reaction have the following properties:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeOptionalDescription
+

id

+
+

object

+
+

 

+
+

Reaction id

+
+

orphan

+
+

number

+
+

 

+
+

Orphan

+
+

orphanReason

+
+

string

+
+

 

+
+

Orphan reason

+

Value can be null.

+
+

timestamp

+
+

number

+
+

 

+
+

Timestamp

+
+

reaction

+
+

string

+
+

 

+
+

Reaction

+
+

read

+
+

boolean

+
+

 

+
+

Read

+
+

msgId

+
+

object

+
+

 

+
+

Parent message id

+
+

senderId

+
+

string

+
+

 

+
+

Sender id

+
+

ack

+
+

number

+
+

 

+
+

Ack

+

Value can be null.

+
+
+
+
+

message_revoke_everyone

Emitted when a message is deleted for everyone in the chat.

@@ -2310,7 +2486,7 @@
diff --git a/docs/Client.js.html b/docs/Client.js.html index 1e5b887..c39799f 100644 --- a/docs/Client.js.html +++ b/docs/Client.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: Client.js + whatsapp-web.js 1.18.0 » Source: Client.js @@ -15,7 +15,7 @@ @@ -41,7 +41,7 @@ const { WhatsWebURL, DefaultOptions, Events, WAState } = require('./ut const { ExposeStore, LoadUtils } = require('./util/Injected'); const ChatFactory = require('./factories/ChatFactory'); const ContactFactory = require('./factories/ContactFactory'); -const { ClientInfo, Message, MessageMedia, Contact, Location, GroupNotification, Label, Call, Buttons, List} = require('./structures'); +const { ClientInfo, Message, MessageMedia, Contact, Location, GroupNotification, Label, Call, Buttons, List, Reaction } = require('./structures'); const LegacySessionAuth = require('./authStrategies/LegacySessionAuth'); const NoAuth = require('./authStrategies/NoAuth'); @@ -146,6 +146,52 @@ class Client extends EventEmitter { referer: 'https://whatsapp.com/' }); + await page.evaluate(`function getElementByXpath(path) { + return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; + }`); + + let lastPercent = null, + lastPercentMessage = null; + + await page.exposeFunction('loadingScreen', async (percent, message) => { + if (lastPercent !== percent || lastPercentMessage !== message) { + this.emit(Events.LOADING_SCREEN, percent, message); + lastPercent = percent; + lastPercentMessage = message; + } + }); + + await page.evaluate( + async function (selectors) { + var observer = new MutationObserver(function () { + let progressBar = window.getElementByXpath( + selectors.PROGRESS + ); + let progressMessage = window.getElementByXpath( + selectors.PROGRESS_MESSAGE + ); + + if (progressBar) { + window.loadingScreen( + progressBar.value, + progressMessage.innerText + ); + } + }); + + observer.observe(document, { + attributes: true, + childList: true, + characterData: true, + subtree: true, + }); + }, + { + PROGRESS: '//*[@id=\'app\']/div/div/div[2]/progress', + PROGRESS_MESSAGE: '//*[@id=\'app\']/div/div/div[3]', + } + ); + const INTRO_IMG_SELECTOR = '[data-testid="intro-md-beta-logo-dark"], [data-testid="intro-md-beta-logo-light"], [data-asset-intro-image-light="true"], [data-asset-intro-image-dark="true"]'; const INTRO_QRCODE_SELECTOR = 'div[data-ref] canvas'; @@ -404,7 +450,7 @@ class Client extends EventEmitter { this.emit(Events.MEDIA_UPLOADED, message); }); - await page.exposeFunction('onAppStateChangedEvent', (state) => { + await page.exposeFunction('onAppStateChangedEvent', async (state) => { /** * Emitted when the connection state changes @@ -431,6 +477,7 @@ class Client extends EventEmitter { * @event Client#disconnected * @param {WAState|"NAVIGATION"} reason reason that caused the disconnect */ + await this.authStrategy.disconnect(); this.emit(Events.DISCONNECTED, state); this.destroy(); } @@ -470,6 +517,27 @@ class Client extends EventEmitter { this.emit(Events.INCOMING_CALL, cll); }); + await page.exposeFunction('onReaction', (reactions) => { + for (const reaction of reactions) { + /** + * Emitted when a reaction is sent, received, updated or removed + * @event Client#message_reaction + * @param {object} reaction + * @param {object} reaction.id - Reaction id + * @param {number} reaction.orphan - Orphan + * @param {?string} reaction.orphanReason - Orphan reason + * @param {number} reaction.timestamp - Timestamp + * @param {string} reaction.reaction - Reaction + * @param {boolean} reaction.read - Read + * @param {object} reaction.msgId - Parent message id + * @param {string} reaction.senderId - Sender id + * @param {?number} reaction.ack - Ack + */ + + this.emit(Events.MESSAGE_REACTION, new Reaction(this, reaction)); + } + }); + await page.evaluate(() => { window.Store.Msg.on('change', (msg) => { window.onChangeMessageEvent(window.WWebJS.getMessageModel(msg)); }); window.Store.Msg.on('change:type', (msg) => { window.onChangeMessageTypeEvent(window.WWebJS.getMessageModel(msg)); }); @@ -489,6 +557,22 @@ class Client extends EventEmitter { } } }); + + { + const module = window.Store.createOrUpdateReactionsModule; + const ogMethod = module.createOrUpdateReactions; + module.createOrUpdateReactions = ((...args) => { + window.onReaction(args[0].map(reaction => { + const msgKey = window.Store.MsgKey.fromString(reaction.msgKey); + const parentMsgKey = window.Store.MsgKey.fromString(reaction.parentMsgKey); + const timestamp = reaction.timestamp / 1000; + + return {...reaction, msgKey, parentMsgKey, timestamp }; + })); + + return ogMethod(...args); + }).bind(module); + } }); /** @@ -496,11 +580,13 @@ class Client extends EventEmitter { * @event Client#ready */ this.emit(Events.READY); + this.authStrategy.afterAuthReady(); // Disconnect when navigating away when in PAIRING state (detect logout) this.pupPage.on('framenavigated', async () => { const appState = await this.getState(); if(!appState || appState === WAState.PAIRING) { + await this.authStrategy.disconnect(); this.emit(Events.DISCONNECTED, 'NAVIGATION'); await this.destroy(); } @@ -512,6 +598,7 @@ class Client extends EventEmitter { */ async destroy() { await this.pupBrowser.close(); + await this.authStrategy.destroy(); } /** @@ -933,7 +1020,13 @@ class Client extends EventEmitter { */ async getCommonGroups(contactId) { const commonGroups = await this.pupPage.evaluate(async (contactId) => { - const contact = window.Store.Contact.get(contactId); + let contact = window.Store.Contact.get(contactId); + if (!contact) { + const wid = window.Store.WidFactory.createUserWid(contactId); + const chatConstructor = window.Store.Contact.getModelsArray().find(c=>!c.isGroup).constructor; + contact = new chatConstructor({id: wid}); + } + if (contact.commonGroups) { return contact.commonGroups.serialize(); } @@ -1131,7 +1224,7 @@ module.exports = Client;
diff --git a/docs/ClientInfo.html b/docs/ClientInfo.html index 0bb31af..064991c 100644 --- a/docs/ClientInfo.html +++ b/docs/ClientInfo.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Class: ClientInfo + whatsapp-web.js 1.18.0 » Class: ClientInfo @@ -15,7 +15,7 @@ @@ -242,7 +242,7 @@
diff --git a/docs/Contact.html b/docs/Contact.html index 5988ce3..4594061 100644 --- a/docs/Contact.html +++ b/docs/Contact.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Class: Contact + whatsapp-web.js 1.18.0 » Class: Contact @@ -15,7 +15,7 @@ @@ -293,7 +293,7 @@
diff --git a/docs/GroupChat.html b/docs/GroupChat.html index a54f8df..a39e454 100644 --- a/docs/GroupChat.html +++ b/docs/GroupChat.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Class: GroupChat + whatsapp-web.js 1.18.0 » Class: GroupChat @@ -15,7 +15,7 @@ @@ -436,7 +436,7 @@

 

-

Options for searching messages. Right now only limit is supported.

+

Options for searching messages. Right now only limit and fromMe is supported.

Values in searchOptions have the following properties:

@@ -462,6 +462,20 @@

The amount of messages to return. If no limit is specified, the available messages will be returned. Note that the actual number of returned messages may be smaller if there aren't enough messages in the conversation. Set this to Infinity to load all messages.

+ + + + + +
+

fromMe

+
+

 

+
+

Yes

+
+

Return only messages from the bot number or vise versa. To get all messages, leave the option undefined.

+
@@ -927,7 +941,7 @@
diff --git a/docs/GroupNotification.html b/docs/GroupNotification.html index 64aeb49..eb9ce7c 100644 --- a/docs/GroupNotification.html +++ b/docs/GroupNotification.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Class: GroupNotification + whatsapp-web.js 1.18.0 » Class: GroupNotification @@ -15,7 +15,7 @@ @@ -233,7 +233,7 @@
diff --git a/docs/InterfaceController.html b/docs/InterfaceController.html index 5776e72..707aee2 100644 --- a/docs/InterfaceController.html +++ b/docs/InterfaceController.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Class: InterfaceController + whatsapp-web.js 1.18.0 » Class: InterfaceController @@ -15,7 +15,7 @@ @@ -382,7 +382,7 @@
diff --git a/docs/Label.html b/docs/Label.html index e678cd7..ab642e9 100644 --- a/docs/Label.html +++ b/docs/Label.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Class: Label + whatsapp-web.js 1.18.0 » Class: Label @@ -15,7 +15,7 @@ @@ -163,7 +163,7 @@
diff --git a/docs/LegacySessionAuth.html b/docs/LegacySessionAuth.html index 5455ef3..cc1aedb 100644 --- a/docs/LegacySessionAuth.html +++ b/docs/LegacySessionAuth.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Class: LegacySessionAuth + whatsapp-web.js 1.18.0 » Class: LegacySessionAuth @@ -15,7 +15,7 @@ @@ -173,7 +173,7 @@
diff --git a/docs/List.html b/docs/List.html index 953b5dc..dce13cf 100644 --- a/docs/List.html +++ b/docs/List.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Class: List + whatsapp-web.js 1.18.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 96ec06c..dbf9ed2 100644 --- a/docs/LocalAuth.html +++ b/docs/LocalAuth.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Class: LocalAuth + whatsapp-web.js 1.18.0 » Class: LocalAuth @@ -15,7 +15,7 @@ @@ -120,7 +120,7 @@
diff --git a/docs/Location.html b/docs/Location.html index a41e833..cfb20a0 100644 --- a/docs/Location.html +++ b/docs/Location.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Class: Location + whatsapp-web.js 1.18.0 » Class: Location @@ -15,7 +15,7 @@ @@ -149,7 +149,7 @@
diff --git a/docs/Message.html b/docs/Message.html index 95fb491..04e7b38 100644 --- a/docs/Message.html +++ b/docs/Message.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Class: Message + whatsapp-web.js 1.18.0 » Class: Message @@ -15,7 +15,7 @@ @@ -400,7 +400,7 @@

 

-

If true and the message is sent by the current user, will delete it for everyone in the chat.

+

If true and the message is sent by the current user or the user is an admin, will delete it for everyone in the chat.

Value can be null.

@@ -420,7 +420,7 @@
async

forward(chat) → Promise

-

Forwards this message to another chat

+

Forwards this message to another chat (that you chatted before, otherwise it will fail)

Parameter

@@ -650,7 +650,7 @@
diff --git a/docs/MessageMedia.html b/docs/MessageMedia.html index c2857b5..1dc5e9a 100644 --- a/docs/MessageMedia.html +++ b/docs/MessageMedia.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Class: MessageMedia + whatsapp-web.js 1.18.0 » Class: MessageMedia @@ -15,7 +15,7 @@ @@ -26,7 +26,7 @@
@@ -135,7 +136,22 @@

 

+ + + + + + @@ -155,7 +171,12 @@

filename  nullable string

-

Name of the file (for documents)

+

Document file name. Value can be null

+
+
+

filesize +  nullable number

+

Document file size in bytes. Value can be null

mimetype @@ -343,7 +364,7 @@
diff --git a/docs/NoAuth.html b/docs/NoAuth.html index 8ff57ef..688a6ac 100644 --- a/docs/NoAuth.html +++ b/docs/NoAuth.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Class: NoAuth + whatsapp-web.js 1.18.0 » Class: NoAuth @@ -15,7 +15,7 @@ @@ -51,7 +51,7 @@
diff --git a/docs/Order.html b/docs/Order.html index dde65ee..1cdda96 100644 --- a/docs/Order.html +++ b/docs/Order.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Class: Order + whatsapp-web.js 1.18.0 » Class: Order @@ -15,7 +15,7 @@ @@ -102,7 +102,7 @@
diff --git a/docs/PrivateChat.html b/docs/PrivateChat.html index 3203df9..1922966 100644 --- a/docs/PrivateChat.html +++ b/docs/PrivateChat.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Class: PrivateChat + whatsapp-web.js 1.18.0 » Class: PrivateChat @@ -15,7 +15,7 @@ @@ -295,7 +295,7 @@

 

@@ -519,7 +533,7 @@
diff --git a/docs/PrivateContact.html b/docs/PrivateContact.html index 35d012f..b5257e0 100644 --- a/docs/PrivateContact.html +++ b/docs/PrivateContact.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Class: PrivateContact + whatsapp-web.js 1.18.0 » Class: PrivateContact @@ -15,7 +15,7 @@ @@ -319,7 +319,7 @@
diff --git a/docs/Product.html b/docs/Product.html index 746dd69..3f595d3 100644 --- a/docs/Product.html +++ b/docs/Product.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Class: Product + whatsapp-web.js 1.18.0 » Class: Product @@ -15,7 +15,7 @@ @@ -127,7 +127,7 @@
diff --git a/docs/Reaction.html b/docs/Reaction.html new file mode 100644 index 0000000..b291413 --- /dev/null +++ b/docs/Reaction.html @@ -0,0 +1,159 @@ + + + + + + + whatsapp-web.js 1.18.0 » Class: Reaction + + + + + + + + +
+
+
+
+ +
+
+

Properties

+
+
+
+
ack
+
+
+
id
+
+
+
msgId
+
+
+
+
+
+
+
orphan
+
+
+
orphanReason
+
+
+
reaction
+
+
+
+
+
+
+
read
+
+
+
senderId
+
+
+
timestamp
+
+
+
+
+
+
+
+
+

new Reaction()

+
+
Extends
+
Base
+
+
+
+

Properties

+
+

ack +  nullable number

+

ACK

+
+
+

id +  object

+

Reaction ID

+
+
+

msgId +  object

+

Message ID

+
+
+

orphan +  number

+

Orphan

+
+
+

orphanReason +  nullable string

+

Orphan reason

+
+
+

reaction +  string

+

Reaction

+
+
+

read +  boolean

+

Read

+
+
+

senderId +  string

+

Sender ID

+
+
+

timestamp +  number

+

Unix timestamp for when the reaction was created

+
+
+
+
+
+
+ +
+
+
+ +
+ + + + + + + + + \ No newline at end of file diff --git a/docs/RemoteAuth.html b/docs/RemoteAuth.html new file mode 100644 index 0000000..9a028bc --- /dev/null +++ b/docs/RemoteAuth.html @@ -0,0 +1,163 @@ + + + + + + + whatsapp-web.js 1.18.0 » Class: RemoteAuth + + + + + + + + +
+
+
+
+ +
+
+
+

new RemoteAuth(options)

+
+

Parameters

+
-

Document file name

+

Document file name. Value can be null

+

Value can be null.

+
+

filesize

+
+

 

+
+

 

+
+

Document file size in bytes. Value can be null

Value can be null.

-

Options for searching messages. Right now only limit is supported.

+

Options for searching messages. Right now only limit and fromMe is supported.

Values in searchOptions have the following properties:

@@ -321,6 +321,20 @@

The amount of messages to return. If no limit is specified, the available messages will be returned. Note that the actual number of returned messages may be smaller if there aren't enough messages in the conversation. Set this to Infinity to load all messages.

+ + + + + +
+

fromMe

+
+

 

+
+

Yes

+
+

Return only messages from the bot number or vise versa. To get all messages, leave the option undefined.

+
+ + + + + + + + + + + + + + + + +
NameTypeOptionalDescription
+

options

+
+

 

+
+

 

+
+

options

+

Values in options have the following properties:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeOptionalDescription
+

store

+
+

 

+
+

 

+
+

Remote database store instance

+
+

clientId

+
+

 

+
+

 

+
+

Client id to distinguish instances if you are using multiple, otherwise keep null if you are using only one instance

+
+

dataPath

+
+

 

+
+

 

+
+

Change the default path for saving session files, default is: "./.wwebjs_auth/"

+
+

backupSyncIntervalMs

+
+

 

+
+

 

+
+

Sets the time interval for periodic session backups. Accepts values starting from 60000ms {1 minute}

+
+
+
+
+
+
+
+
+ + + + + +
+ +
+ + + + + + + + + \ No newline at end of file diff --git a/docs/Util.html b/docs/Util.html index b64b606..86ed99c 100644 --- a/docs/Util.html +++ b/docs/Util.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Class: Util + whatsapp-web.js 1.18.0 » Class: Util @@ -15,7 +15,7 @@ @@ -243,7 +243,7 @@
diff --git a/docs/authStrategies_BaseAuthStrategy.js.html b/docs/authStrategies_BaseAuthStrategy.js.html index 2bbcd7f..0912654 100644 --- a/docs/authStrategies_BaseAuthStrategy.js.html +++ b/docs/authStrategies_BaseAuthStrategy.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: authStrategies/BaseAuthStrategy.js + whatsapp-web.js 1.18.0 » Source: authStrategies/BaseAuthStrategy.js @@ -15,7 +15,7 @@ @@ -49,6 +49,9 @@ class BaseAuthStrategy { }; } async getAuthEventPayload() {} + async afterAuthReady() {} + async disconnect() {} + async destroy() {} async logout() {} } @@ -62,7 +65,7 @@ module.exports = BaseAuthStrategy;
diff --git a/docs/authStrategies_LegacySessionAuth.js.html b/docs/authStrategies_LegacySessionAuth.js.html index 6167ba9..344cfbf 100644 --- a/docs/authStrategies_LegacySessionAuth.js.html +++ b/docs/authStrategies_LegacySessionAuth.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: authStrategies/LegacySessionAuth.js + whatsapp-web.js 1.18.0 » Source: authStrategies/LegacySessionAuth.js @@ -15,7 +15,7 @@ @@ -111,7 +111,7 @@ module.exports = LegacySessionAuth;
diff --git a/docs/authStrategies_LocalAuth.js.html b/docs/authStrategies_LocalAuth.js.html index ac7832c..83cf47b 100644 --- a/docs/authStrategies_LocalAuth.js.html +++ b/docs/authStrategies_LocalAuth.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: authStrategies/LocalAuth.js + whatsapp-web.js 1.18.0 » Source: authStrategies/LocalAuth.js @@ -15,7 +15,7 @@ @@ -91,7 +91,7 @@ module.exports = LocalAuth;
diff --git a/docs/authStrategies_NoAuth.js.html b/docs/authStrategies_NoAuth.js.html index 50349b0..f6ee7a4 100644 --- a/docs/authStrategies_NoAuth.js.html +++ b/docs/authStrategies_NoAuth.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: authStrategies/NoAuth.js + whatsapp-web.js 1.18.0 » Source: authStrategies/NoAuth.js @@ -15,7 +15,7 @@ @@ -50,7 +50,7 @@ module.exports = NoAuth;
diff --git a/docs/authStrategies_RemoteAuth.js.html b/docs/authStrategies_RemoteAuth.js.html new file mode 100644 index 0000000..63709bd --- /dev/null +++ b/docs/authStrategies_RemoteAuth.js.html @@ -0,0 +1,258 @@ + + + + + + + whatsapp-web.js 1.18.0 » Source: authStrategies/RemoteAuth.js + + + + + + + + +
+
+
+ +
+ +
+
'use strict';
+
+/* Require Optional Dependencies */
+try {
+    var fs = require('fs-extra');
+    var unzipper = require('unzipper');
+    var archiver = require('archiver');
+} catch {
+    fs = undefined;
+    unzipper = undefined;
+    archiver = undefined;
+}
+
+const path = require('path');
+const { Events } = require('./../util/Constants');
+const BaseAuthStrategy = require('./BaseAuthStrategy');
+
+/**
+ * Remote-based authentication
+ * @param {object} options - options
+ * @param {object} options.store - Remote database store instance
+ * @param {string} options.clientId - Client id to distinguish instances if you are using multiple, otherwise keep null if you are using only one instance
+ * @param {string} options.dataPath - Change the default path for saving session files, default is: "./.wwebjs_auth/" 
+ * @param {number} options.backupSyncIntervalMs - Sets the time interval for periodic session backups. Accepts values starting from 60000ms {1 minute}
+ */
+class RemoteAuth extends BaseAuthStrategy {
+    constructor({ clientId, dataPath, store, backupSyncIntervalMs } = {}) {
+        if (!fs && !unzipper && !archiver) throw new Error('Optional Dependencies [fs-extra, unzipper, archiver] are required to use RemoteAuth. Make sure to run npm install correctly and remove the --no-optional flag');
+        super();
+
+        const idRegex = /^[-_\w]+$/i;
+        if (clientId && !idRegex.test(clientId)) {
+            throw new Error('Invalid clientId. Only alphanumeric characters, underscores and hyphens are allowed.');
+        }
+        if (!backupSyncIntervalMs || backupSyncIntervalMs < 60000) {
+            throw new Error('Invalid backupSyncIntervalMs. Accepts values starting from 60000ms {1 minute}.');
+        }
+        if(!store) throw new Error('Remote database store is required.');
+
+        this.store = store;
+        this.clientId = clientId;
+        this.backupSyncIntervalMs = backupSyncIntervalMs;
+        this.dataPath = path.resolve(dataPath || './.wwebjs_auth/');
+        this.tempDir = `${this.dataPath}/wwebjs_temp_session`;
+        this.requiredDirs = ['Default', 'IndexedDB', 'Local Storage']; /* => Required Files & Dirs in WWebJS to restore session */
+    }
+
+    async beforeBrowserInitialized() {
+        const puppeteerOpts = this.client.options.puppeteer;
+        const sessionDirName = this.clientId ? `RemoteAuth-${this.clientId}` : 'RemoteAuth';
+        const dirPath = path.join(this.dataPath, sessionDirName);
+
+        if (puppeteerOpts.userDataDir && puppeteerOpts.userDataDir !== dirPath) {
+            throw new Error('RemoteAuth is not compatible with a user-supplied userDataDir.');
+        }
+
+        this.userDataDir = dirPath;
+        this.sessionName = sessionDirName;
+
+        await this.extractRemoteSession();
+
+        this.client.options.puppeteer = {
+            ...puppeteerOpts,
+            userDataDir: dirPath
+        };
+    }
+
+    async logout() {
+        await this.disconnect();
+    }
+
+    async destroy() {
+        clearInterval(this.backupSync);
+    }
+
+    async disconnect() {
+        await this.deleteRemoteSession();
+
+        let pathExists = await this.isValidPath(this.userDataDir);
+        if (pathExists) {
+            await fs.promises.rm(this.userDataDir, {
+                recursive: true,
+                force: true
+            }).catch(() => {});
+        }
+        clearInterval(this.backupSync);
+    }
+
+    async afterAuthReady() {
+        const sessionExists = await this.store.sessionExists({session: this.sessionName});
+        if(!sessionExists) {
+            await this.delay(60000); /* Initial delay sync required for session to be stable enough to recover */
+            await this.storeRemoteSession({emit: true});
+        }
+        var self = this;
+        this.backupSync = setInterval(async function () {
+            await self.storeRemoteSession();
+        }, this.backupSyncIntervalMs);
+    }
+
+    async storeRemoteSession(options) {
+        /* Compress & Store Session */
+        const pathExists = await this.isValidPath(this.userDataDir);
+        if (pathExists) {
+            await this.compressSession();
+            await this.store.save({session: this.sessionName});
+            await fs.promises.unlink(`${this.sessionName}.zip`);
+            await fs.promises.rm(`${this.tempDir}`, {
+                recursive: true,
+                force: true
+            }).catch(() => {});
+            if(options && options.emit) this.client.emit(Events.REMOTE_SESSION_SAVED);
+        }
+    }
+
+    async extractRemoteSession() {
+        const pathExists = await this.isValidPath(this.userDataDir);
+        const compressedSessionPath = `${this.sessionName}.zip`;
+        const sessionExists = await this.store.sessionExists({session: this.sessionName});
+        if (pathExists) {
+            await fs.promises.rm(this.userDataDir, {
+                recursive: true,
+                force: true
+            }).catch(() => {});
+        }
+        if (sessionExists) {
+            await this.store.extract({session: this.sessionName, path: compressedSessionPath});
+            await this.unCompressSession(compressedSessionPath);
+        } else {
+            fs.mkdirSync(this.userDataDir, { recursive: true });
+        }
+    }
+
+    async deleteRemoteSession() {
+        const sessionExists = await this.store.sessionExists({session: this.sessionName});
+        if (sessionExists) await this.store.delete({session: this.sessionName});
+    }
+
+    async compressSession() {
+        const archive = archiver('zip');
+        const stream = fs.createWriteStream(`${this.sessionName}.zip`);
+
+        await fs.copy(this.userDataDir, this.tempDir).catch(() => {});
+        await this.deleteMetadata();
+        return new Promise((resolve, reject) => {
+            archive
+                .directory(this.tempDir, false)
+                .on('error', err => reject(err))
+                .pipe(stream);
+
+            stream.on('close', () => resolve());
+            archive.finalize();
+        });
+    }
+
+    async unCompressSession(compressedSessionPath) {
+        var stream = fs.createReadStream(compressedSessionPath);
+        await new Promise((resolve, reject) => {
+            stream.pipe(unzipper.Extract({
+                path: this.userDataDir
+            }))
+                .on('error', err => reject(err))
+                .on('finish', () => resolve());
+        });
+        await fs.promises.unlink(compressedSessionPath);
+    }
+
+    async deleteMetadata() {
+        const sessionDirs = [this.tempDir, path.join(this.tempDir, 'Default')];
+        for (const dir of sessionDirs) {
+            const sessionFiles = await fs.promises.readdir(dir);
+            for (const element of sessionFiles) {
+                if (!this.requiredDirs.includes(element)) {
+                    const dirElement = path.join(dir, element);
+                    const stats = await fs.promises.lstat(dirElement);
+    
+                    if (stats.isDirectory()) {
+                        await fs.promises.rm(dirElement, {
+                            recursive: true,
+                            force: true
+                        }).catch(() => {});
+                    } else {
+                        await fs.promises.unlink(dirElement).catch(() => {});
+                    }
+                }
+            }
+        }
+    }
+
+    async isValidPath(path) {
+        try {
+            await fs.promises.access(path);
+            return true;
+        } catch {
+            return false;
+        }
+    }
+
+    async delay(ms) {
+        return new Promise(resolve => setTimeout(resolve, ms));
+    }
+}
+
+module.exports = RemoteAuth;
+
+
+
+
+ +
+
+
+ +
+ + + + + + + + + \ No newline at end of file diff --git a/docs/global.html b/docs/global.html index d20b79b..89c6ad9 100644 --- a/docs/global.html +++ b/docs/global.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Globals + whatsapp-web.js 1.18.0 » Globals @@ -15,7 +15,7 @@ @@ -285,6 +285,19 @@ + + +

MESSAGE_REACTION

+ + +

 

+ + +

 

+ + + +

MEDIA_UPLOADED

@@ -350,6 +363,19 @@ + + +

LOADING_SCREEN

+ + +

 

+ + +

 

+ + + +

DISCONNECTED

@@ -402,6 +428,19 @@ + + +

REMOTE_SESSION_SAVED

+ + +

 

+ + +

 

+ + + + @@ -1980,7 +2019,7 @@
diff --git a/docs/index.html b/docs/index.html index caff238..3e2c8fd 100644 --- a/docs/index.html +++ b/docs/index.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Home + whatsapp-web.js 1.18.0 » Home @@ -15,7 +15,7 @@ @@ -27,11 +27,11 @@
-

npm Depfu WhatsApp_Web 2.2220.8 Discord Chat

+

npm Depfu WhatsApp_Web 2.2240.7 Discord Chat

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.

@@ -808,7 +808,7 @@ client.initialize();
- Client#event:message_revoke_everyone + Client#event:message_reaction
@@ -816,6 +816,11 @@ client.initialize();
+
+ Client#event:message_revoke_everyone +
+
+
Client#event:message_revoke_me
@@ -911,15 +916,15 @@ client.initialize();
+
+
+ -
-
Client#info
@@ -1234,20 +1239,25 @@ client.initialize();
-
-
- +
+
Events.INCOMING_CALL
+
+ Events.LOADING_SCREEN +
+
+
Events.MEDIA_UPLOADED
@@ -1263,6 +1273,11 @@ client.initialize();
+
+ Events.MESSAGE_REACTION +
+
+
Events.MESSAGE_RECEIVED
@@ -1292,6 +1307,11 @@ client.initialize();
+
+ Events.REMOTE_SESSION_SAVED +
+
+
Events.STATE_CHANGED
@@ -2243,7 +2263,7 @@ client.initialize(); - +
-
- MessageMedia#filename -
-
-
MessageMedia#mimetype
@@ -2992,6 +3017,99 @@ client.initialize();
+
+
+

Reaction

+
+
+
+
+ Reaction() +
+
+
+
+ Reaction#ack +
+
+
+
+ Reaction#id +
+
+
+
+ Reaction#msgId +
+
+
+
+
+
+
+
+ Reaction#orphan +
+
+
+
+ Reaction#orphanReason +
+
+
+
+ Reaction#reaction +
+
+
+
+ Reaction#read +
+
+
+
+
+
+
+
+ Reaction#senderId +
+
+
+
+ Reaction#timestamp +
+
+
+
+
+
+
+
+
+
+

RemoteAuth

+
+
+
+
+ RemoteAuth(options) +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

Status

@@ -3158,7 +3276,7 @@ client.initialize();
diff --git a/docs/scripts/jsdoc-toc.js b/docs/scripts/jsdoc-toc.js index 62e7e8f..f910b01 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":"BaseAuthStrategy","id":"BaseAuthStrategy","children":[]},{"label":"BusinessContact","id":"BusinessContact","children":[]},{"label":"Buttons","id":"Buttons","children":[]},{"label":"Call","id":"Call","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":"Label","id":"Label","children":[]},{"label":"LegacySessionAuth","id":"LegacySessionAuth","children":[]},{"label":"List","id":"List","children":[]},{"label":"LocalAuth","id":"LocalAuth","children":[]},{"label":"Location","id":"Location","children":[]},{"label":"Message","id":"Message","children":[]},{"label":"MessageMedia","id":"MessageMedia","children":[]},{"label":"NoAuth","id":"NoAuth","children":[]},{"label":"Order","id":"Order","children":[]},{"label":"PrivateChat","id":"PrivateChat","children":[]},{"label":"PrivateContact","id":"PrivateContact","children":[]},{"label":"Product","id":"Product","children":[]},{"label":"Util","id":"Util","children":[]}], + data: [{"label":"Globals","id":"global","children":[]},{"label":"Base","id":"Base","children":[]},{"label":"BaseAuthStrategy","id":"BaseAuthStrategy","children":[]},{"label":"BusinessContact","id":"BusinessContact","children":[]},{"label":"Buttons","id":"Buttons","children":[]},{"label":"Call","id":"Call","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":"Label","id":"Label","children":[]},{"label":"LegacySessionAuth","id":"LegacySessionAuth","children":[]},{"label":"List","id":"List","children":[]},{"label":"LocalAuth","id":"LocalAuth","children":[]},{"label":"Location","id":"Location","children":[]},{"label":"Message","id":"Message","children":[]},{"label":"MessageMedia","id":"MessageMedia","children":[]},{"label":"NoAuth","id":"NoAuth","children":[]},{"label":"Order","id":"Order","children":[]},{"label":"PrivateChat","id":"PrivateChat","children":[]},{"label":"PrivateContact","id":"PrivateContact","children":[]},{"label":"Product","id":"Product","children":[]},{"label":"Reaction","id":"Reaction","children":[]},{"label":"RemoteAuth","id":"RemoteAuth","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 b62302b..65d6ae7 100644 --- a/docs/structures_Base.js.html +++ b/docs/structures_Base.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: structures/Base.js + whatsapp-web.js 1.18.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 1569c33..c6740cb 100644 --- a/docs/structures_BusinessContact.js.html +++ b/docs/structures_BusinessContact.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: structures/BusinessContact.js + whatsapp-web.js 1.18.0 » Source: structures/BusinessContact.js @@ -15,7 +15,7 @@ @@ -59,7 +59,7 @@ module.exports = BusinessContact;
diff --git a/docs/structures_Buttons.js.html b/docs/structures_Buttons.js.html index f118717..8be1944 100644 --- a/docs/structures_Buttons.js.html +++ b/docs/structures_Buttons.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: structures/Buttons.js + whatsapp-web.js 1.18.0 » Source: structures/Buttons.js @@ -15,7 +15,7 @@ @@ -120,7 +120,7 @@ module.exports = Buttons;
diff --git a/docs/structures_Call.js.html b/docs/structures_Call.js.html index cfe7007..81cb49b 100644 --- a/docs/structures_Call.js.html +++ b/docs/structures_Call.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: structures/Call.js + whatsapp-web.js 1.18.0 » Source: structures/Call.js @@ -15,7 +15,7 @@ @@ -106,7 +106,7 @@ module.exports = Call;
diff --git a/docs/structures_Chat.js.html b/docs/structures_Chat.js.html index 09d1986..5521da6 100644 --- a/docs/structures_Chat.js.html +++ b/docs/structures_Chat.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: structures/Chat.js + whatsapp-web.js 1.18.0 » Source: structures/Chat.js @@ -15,7 +15,7 @@ @@ -201,13 +201,22 @@ class Chat extends Base { /** * Loads chat messages, sorted from earliest to latest. - * @param {Object} searchOptions Options for searching messages. Right now only limit is supported. + * @param {Object} searchOptions Options for searching messages. Right now only limit and fromMe is supported. * @param {Number} [searchOptions.limit] The amount of messages to return. If no limit is specified, the available messages will be returned. Note that the actual number of returned messages may be smaller if there aren't enough messages in the conversation. Set this to Infinity to load all messages. + * @param {Boolean} [searchOptions.fromMe] Return only messages from the bot number or vise versa. To get all messages, leave the option undefined. * @returns {Promise<Array<Message>>} */ async fetchMessages(searchOptions) { let messages = await this.client.pupPage.evaluate(async (chatId, searchOptions) => { - const msgFilter = m => !m.isNotification; // dont include notification messages + const msgFilter = (m) => { + if (m.isNotification) { + return false; // dont include notification messages + } + if (searchOptions && searchOptions.fromMe && m.id.fromMe !== searchOptions.fromMe) { + return false; + } + return true; + }; const chat = window.Store.Chat.get(chatId); let msgs = chat.msgs.getModelsArray().filter(msgFilter); @@ -290,7 +299,7 @@ module.exports = Chat;
diff --git a/docs/structures_ClientInfo.js.html b/docs/structures_ClientInfo.js.html index fe6a725..f591d3d 100644 --- a/docs/structures_ClientInfo.js.html +++ b/docs/structures_ClientInfo.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: structures/ClientInfo.js + whatsapp-web.js 1.18.0 » Source: structures/ClientInfo.js @@ -15,7 +15,7 @@ @@ -109,7 +109,7 @@ module.exports = ClientInfo;
diff --git a/docs/structures_Contact.js.html b/docs/structures_Contact.js.html index 1344f74..9280f80 100644 --- a/docs/structures_Contact.js.html +++ b/docs/structures_Contact.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: structures/Contact.js + whatsapp-web.js 1.18.0 » Source: structures/Contact.js @@ -15,7 +15,7 @@ @@ -245,7 +245,7 @@ module.exports = Contact;
diff --git a/docs/structures_GroupChat.js.html b/docs/structures_GroupChat.js.html index c0d97de..a3043e0 100644 --- a/docs/structures_GroupChat.js.html +++ b/docs/structures_GroupChat.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: structures/GroupChat.js + whatsapp-web.js 1.18.0 » Source: structures/GroupChat.js @@ -15,7 +15,7 @@ @@ -272,7 +272,7 @@ module.exports = GroupChat;
diff --git a/docs/structures_GroupNotification.js.html b/docs/structures_GroupNotification.js.html index 943eb50..dcc45b4 100644 --- a/docs/structures_GroupNotification.js.html +++ b/docs/structures_GroupNotification.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: structures/GroupNotification.js + whatsapp-web.js 1.18.0 » Source: structures/GroupNotification.js @@ -15,7 +15,7 @@ @@ -143,7 +143,7 @@ module.exports = GroupNotification;
diff --git a/docs/structures_Label.js.html b/docs/structures_Label.js.html index 1a28b12..8edcac8 100644 --- a/docs/structures_Label.js.html +++ b/docs/structures_Label.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: structures/Label.js + whatsapp-web.js 1.18.0 » Source: structures/Label.js @@ -15,7 +15,7 @@ @@ -88,7 +88,7 @@ module.exports = Label;
diff --git a/docs/structures_List.js.html b/docs/structures_List.js.html index 5f66e7a..85ada9e 100644 --- a/docs/structures_List.js.html +++ b/docs/structures_List.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: structures/List.js + whatsapp-web.js 1.18.0 » Source: structures/List.js @@ -15,7 +15,7 @@ @@ -118,7 +118,7 @@ module.exports = List;
diff --git a/docs/structures_Location.js.html b/docs/structures_Location.js.html index 1dfb302..788874f 100644 --- a/docs/structures_Location.js.html +++ b/docs/structures_Location.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: structures/Location.js + whatsapp-web.js 1.18.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 d937dd5..193ada0 100644 --- a/docs/structures_Message.js.html +++ b/docs/structures_Message.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: structures/Message.js + whatsapp-web.js 1.18.0 » Source: structures/Message.js @@ -15,7 +15,7 @@ @@ -373,6 +373,8 @@ class Message extends Base { */ async react(reaction){ await this.client.pupPage.evaluate(async (messageId, reaction) => { + if (!messageId) { return undefined; } + const msg = await window.Store.Msg.get(messageId); await window.Store.sendReactionToMsg(msg, reaction); }, this.id._serialized, reaction); @@ -387,7 +389,7 @@ class Message extends Base { } /** - * Forwards this message to another chat + * Forwards this message to another chat (that you chatted before, otherwise it will fail) * * @param {string|Chat} chat Chat model or chat ID to which the message will be forwarded * @returns {Promise} @@ -439,12 +441,13 @@ class Message extends Base { signal: (new AbortController).signal }); - const data = window.WWebJS.arrayBufferToBase64(decryptedMedia); + const data = await window.WWebJS.arrayBufferToBase64Async(decryptedMedia); return { data, mimetype: msg.mimetype, - filename: msg.filename + filename: msg.filename, + filesize: msg.size }; } catch (e) { if(e.status && e.status === 404) return undefined; @@ -453,19 +456,19 @@ class Message extends Base { }, this.id._serialized); if (!result) return undefined; - return new MessageMedia(result.mimetype, result.data, result.filename); + return new MessageMedia(result.mimetype, result.data, result.filename, result.filesize); } /** * Deletes a message from the chat - * @param {?boolean} everyone If true and the message is sent by the current user, will delete it for everyone in the chat. + * @param {?boolean} everyone If true and the message is sent by the current user or the user is an admin, will delete it for everyone in the chat. */ async delete(everyone) { await this.client.pupPage.evaluate((msgId, everyone) => { let msg = window.Store.Msg.get(msgId); - if (everyone && msg.id.fromMe && msg._canRevoke()) { - return window.Store.Cmd.sendRevokeMsgs(msg.chat, [msg], {type: 'Sender'}); + if (everyone && msg._canRevoke()) { + return window.Store.Cmd.sendRevokeMsgs(msg.chat, [msg], { type: msg.id.fromMe ? 'Sender' : 'Admin' }); } return window.Store.Cmd.sendDeleteMsgs(msg.chat, [msg], true); @@ -566,7 +569,7 @@ module.exports = Message;
diff --git a/docs/structures_MessageMedia.js.html b/docs/structures_MessageMedia.js.html index f1886fa..07dc863 100644 --- a/docs/structures_MessageMedia.js.html +++ b/docs/structures_MessageMedia.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: structures/MessageMedia.js + whatsapp-web.js 1.18.0 » Source: structures/MessageMedia.js @@ -15,7 +15,7 @@ @@ -41,10 +41,11 @@ const { URL } = require('url'); * Media attached to a message * @param {string} mimetype MIME type of the attachment * @param {string} data Base64-encoded data of the file - * @param {?string} filename Document file name + * @param {?string} filename Document file name. Value can be null + * @param {?number} filesize Document file size in bytes. Value can be null */ class MessageMedia { - constructor(mimetype, data, filename) { + constructor(mimetype, data, filename, filesize) { /** * MIME type of the attachment * @type {string} @@ -58,10 +59,16 @@ class MessageMedia { this.data = data; /** - * Name of the file (for documents) + * Document file name. Value can be null * @type {?string} */ this.filename = filename; + + /** + * Document file size in bytes. Value can be null + * @type {?number} + */ + this.filesize = filesize; } /** @@ -99,6 +106,7 @@ class MessageMedia { const reqOptions = Object.assign({ headers: { accept: 'image/* video/* text/* audio/*' } }, options); const response = await fetch(url, reqOptions); const mime = response.headers.get('Content-Type'); + const size = response.headers.get('Content-Length'); const contentDisposition = response.headers.get('Content-Disposition'); const name = contentDisposition ? contentDisposition.match(/((?<=filename=")(.*)(?="))/) : null; @@ -114,7 +122,7 @@ class MessageMedia { data = btoa(data); } - return { data, mime, name }; + return { data, mime, name, size }; } const res = options.client @@ -127,7 +135,7 @@ class MessageMedia { if (!mimetype) mimetype = res.mime; - return new MessageMedia(mimetype, res.data, filename); + return new MessageMedia(mimetype, res.data, filename, res.size || null); } } @@ -142,7 +150,7 @@ module.exports = MessageMedia;
diff --git a/docs/structures_Order.js.html b/docs/structures_Order.js.html index 26461b3..e2b2716 100644 --- a/docs/structures_Order.js.html +++ b/docs/structures_Order.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: structures/Order.js + whatsapp-web.js 1.18.0 » Source: structures/Order.js @@ -15,7 +15,7 @@ @@ -90,7 +90,7 @@ module.exports = Order;
diff --git a/docs/structures_Payment.js.html b/docs/structures_Payment.js.html index 8e74292..bb84d74 100644 --- a/docs/structures_Payment.js.html +++ b/docs/structures_Payment.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: structures/Payment.js + whatsapp-web.js 1.18.0 » Source: structures/Payment.js @@ -15,7 +15,7 @@ @@ -118,7 +118,7 @@ module.exports = Payment;
diff --git a/docs/structures_PrivateChat.js.html b/docs/structures_PrivateChat.js.html index 3f32888..100c403 100644 --- a/docs/structures_PrivateChat.js.html +++ b/docs/structures_PrivateChat.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: structures/PrivateChat.js + whatsapp-web.js 1.18.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 40706a4..ebea085 100644 --- a/docs/structures_PrivateContact.js.html +++ b/docs/structures_PrivateContact.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: structures/PrivateContact.js + whatsapp-web.js 1.18.0 » Source: structures/PrivateContact.js @@ -15,7 +15,7 @@ @@ -51,7 +51,7 @@ module.exports = PrivateContact;
diff --git a/docs/structures_Product.js.html b/docs/structures_Product.js.html index 0c77d31..7fccd8a 100644 --- a/docs/structures_Product.js.html +++ b/docs/structures_Product.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: structures/Product.js + whatsapp-web.js 1.18.0 » Source: structures/Product.js @@ -15,7 +15,7 @@ @@ -106,7 +106,7 @@ module.exports = Product;
diff --git a/docs/structures_ProductMetadata.js.html b/docs/structures_ProductMetadata.js.html index 220bef0..62e786b 100644 --- a/docs/structures_ProductMetadata.js.html +++ b/docs/structures_ProductMetadata.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: structures/ProductMetadata.js + whatsapp-web.js 1.18.0 » Source: structures/ProductMetadata.js @@ -15,7 +15,7 @@ @@ -63,7 +63,7 @@ module.exports = ProductMetadata;
diff --git a/docs/structures_Reaction.js.html b/docs/structures_Reaction.js.html new file mode 100644 index 0000000..bcdc65e --- /dev/null +++ b/docs/structures_Reaction.js.html @@ -0,0 +1,122 @@ + + + + + + + whatsapp-web.js 1.18.0 » Source: structures/Reaction.js + + + + + + + + +
+
+
+ +
+ +
+
'use strict';
+
+const Base = require('./Base');
+
+/**
+ * Represents a Reaction on WhatsApp
+ * @extends {Base}
+ */
+class Reaction extends Base {
+    constructor(client, data) {
+        super(client);
+
+        if (data) this._patch(data);
+    }
+
+    _patch(data) {
+        /**
+         * Reaction ID
+         * @type {object}
+         */
+        this.id = data.msgKey;
+        /**
+         * Orphan
+         * @type {number}
+         */
+        this.orphan = data.orphan;
+        /**
+         * Orphan reason
+         * @type {?string}
+         */
+        this.orphanReason = data.orphanReason;
+        /**
+         * Unix timestamp for when the reaction was created
+         * @type {number}
+         */
+        this.timestamp = data.timestamp;
+        /**
+         * Reaction
+         * @type {string}
+         */
+        this.reaction = data.reactionText;
+        /**
+         * Read
+         * @type {boolean}
+         */
+        this.read = data.read;
+        /**
+         * Message ID
+         * @type {object}
+         */
+        this.msgId = data.parentMsgKey;
+        /**
+         * Sender ID
+         * @type {string}
+         */
+        this.senderId = data.senderUserJid;
+        /**
+         * ACK
+         * @type {?number}
+         */
+        this.ack = data.ack;
+        
+        
+        return super._patch(data);
+    }
+    
+}
+
+module.exports = Reaction;
+
+
+
+ +
+
+
+ +
+ + + + + + + + + \ No newline at end of file diff --git a/docs/util_Constants.js.html b/docs/util_Constants.js.html index ab0edca..84a5d6f 100644 --- a/docs/util_Constants.js.html +++ b/docs/util_Constants.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: util/Constants.js + whatsapp-web.js 1.18.0 » Source: util/Constants.js @@ -15,7 +15,7 @@ @@ -42,7 +42,7 @@ exports.DefaultOptions = { qrMaxRetries: 0, takeoverOnConflict: false, takeoverTimeoutMs: 0, - userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36', + userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36', ffmpegPath: 'ffmpeg', bypassCSP: false }; @@ -72,15 +72,18 @@ exports.Events = { MESSAGE_REVOKED_EVERYONE: 'message_revoke_everyone', MESSAGE_REVOKED_ME: 'message_revoke_me', MESSAGE_ACK: 'message_ack', + MESSAGE_REACTION: 'message_reaction', MEDIA_UPLOADED: 'media_uploaded', GROUP_JOIN: 'group_join', GROUP_LEAVE: 'group_leave', GROUP_UPDATE: 'group_update', QR_RECEIVED: 'qr', + LOADING_SCREEN: 'loading_screen', DISCONNECTED: 'disconnected', STATE_CHANGED: 'change_state', BATTERY_CHANGED: 'change_battery', - INCOMING_CALL: 'incoming_call' + INCOMING_CALL: 'incoming_call', + REMOTE_SESSION_SAVED: 'remote_session_saved' }; /** @@ -197,7 +200,7 @@ exports.MessageAck = {
diff --git a/docs/util_InterfaceController.js.html b/docs/util_InterfaceController.js.html index 0cdbf70..a036bd6 100644 --- a/docs/util_InterfaceController.js.html +++ b/docs/util_InterfaceController.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: util/InterfaceController.js + whatsapp-web.js 1.18.0 » Source: util/InterfaceController.js @@ -15,7 +15,7 @@ @@ -160,7 +160,7 @@ module.exports = InterfaceController;
diff --git a/docs/util_Util.js.html b/docs/util_Util.js.html index 50b56d0..6906bf1 100644 --- a/docs/util_Util.js.html +++ b/docs/util_Util.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.17.1 » Source: util/Util.js + whatsapp-web.js 1.18.0 » Source: util/Util.js @@ -15,7 +15,7 @@ @@ -225,7 +225,7 @@ module.exports = Util; diff --git a/package.json b/package.json index 46ce339..e7e47ae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "whatsapp-web.js", - "version": "1.18.0-alpha.1", + "version": "1.18.0", "description": "Library for interacting with the WhatsApp Web API ", "main": "./index.js", "typings": "./index.d.ts",