-

npm Depfu WhatsApp_Web 2.2301.6 Discord Chat

+

npm Depfu WhatsApp_Web 2.2306.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.

@@ -3281,7 +3281,7 @@ client.initialize();
diff --git a/docs/structures_Base.js.html b/docs/structures_Base.js.html index d028984..ecd596e 100644 --- a/docs/structures_Base.js.html +++ b/docs/structures_Base.js.html @@ -2,9 +2,9 @@ - + - whatsapp-web.js 1.19.3 » Source: structures/Base.js + whatsapp-web.js 1.19.4 » 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 0f575ef..9a97e69 100644 --- a/docs/structures_BusinessContact.js.html +++ b/docs/structures_BusinessContact.js.html @@ -2,9 +2,9 @@ - + - whatsapp-web.js 1.19.3 » Source: structures/BusinessContact.js + whatsapp-web.js 1.19.4 » 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 d5baa7f..2ea9add 100644 --- a/docs/structures_Buttons.js.html +++ b/docs/structures_Buttons.js.html @@ -2,9 +2,9 @@ - + - whatsapp-web.js 1.19.3 » Source: structures/Buttons.js + whatsapp-web.js 1.19.4 » 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 b2fd323..9d9593b 100644 --- a/docs/structures_Call.js.html +++ b/docs/structures_Call.js.html @@ -2,9 +2,9 @@ - + - whatsapp-web.js 1.19.3 » Source: structures/Call.js + whatsapp-web.js 1.19.4 » Source: structures/Call.js @@ -15,7 +15,7 @@ @@ -114,7 +114,7 @@ module.exports = Call;
diff --git a/docs/structures_Chat.js.html b/docs/structures_Chat.js.html index 6997d81..70eb9e2 100644 --- a/docs/structures_Chat.js.html +++ b/docs/structures_Chat.js.html @@ -2,9 +2,9 @@ - + - whatsapp-web.js 1.19.3 » Source: structures/Chat.js + whatsapp-web.js 1.19.4 » Source: structures/Chat.js @@ -15,7 +15,7 @@ @@ -299,7 +299,7 @@ module.exports = Chat;
diff --git a/docs/structures_ClientInfo.js.html b/docs/structures_ClientInfo.js.html index 4c4003f..790e591 100644 --- a/docs/structures_ClientInfo.js.html +++ b/docs/structures_ClientInfo.js.html @@ -2,9 +2,9 @@ - + - whatsapp-web.js 1.19.3 » Source: structures/ClientInfo.js + whatsapp-web.js 1.19.4 » 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 ebbaf09..96f2323 100644 --- a/docs/structures_Contact.js.html +++ b/docs/structures_Contact.js.html @@ -2,9 +2,9 @@ - + - whatsapp-web.js 1.19.3 » Source: structures/Contact.js + whatsapp-web.js 1.19.4 » 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 c8fd25e..badebae 100644 --- a/docs/structures_GroupChat.js.html +++ b/docs/structures_GroupChat.js.html @@ -2,9 +2,9 @@ - + - whatsapp-web.js 1.19.3 » Source: structures/GroupChat.js + whatsapp-web.js 1.19.4 » Source: structures/GroupChat.js @@ -15,7 +15,7 @@ @@ -294,7 +294,7 @@ module.exports = GroupChat;
diff --git a/docs/structures_GroupNotification.js.html b/docs/structures_GroupNotification.js.html index 8c6e3b6..9ef074d 100644 --- a/docs/structures_GroupNotification.js.html +++ b/docs/structures_GroupNotification.js.html @@ -2,9 +2,9 @@ - + - whatsapp-web.js 1.19.3 » Source: structures/GroupNotification.js + whatsapp-web.js 1.19.4 » 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 77bebb7..01aed26 100644 --- a/docs/structures_Label.js.html +++ b/docs/structures_Label.js.html @@ -2,9 +2,9 @@ - + - whatsapp-web.js 1.19.3 » Source: structures/Label.js + whatsapp-web.js 1.19.4 » 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 b33b8a7..e18dfd4 100644 --- a/docs/structures_List.js.html +++ b/docs/structures_List.js.html @@ -2,9 +2,9 @@ - + - whatsapp-web.js 1.19.3 » Source: structures/List.js + whatsapp-web.js 1.19.4 » 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 3d614df..9707f6b 100644 --- a/docs/structures_Location.js.html +++ b/docs/structures_Location.js.html @@ -2,9 +2,9 @@ - + - whatsapp-web.js 1.19.3 » Source: structures/Location.js + whatsapp-web.js 1.19.4 » 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 b57e883..e5676a2 100644 --- a/docs/structures_Message.js.html +++ b/docs/structures_Message.js.html @@ -2,9 +2,9 @@ - + - whatsapp-web.js 1.19.3 » Source: structures/Message.js + whatsapp-web.js 1.19.4 » Source: structures/Message.js @@ -15,7 +15,7 @@ @@ -573,7 +573,7 @@ module.exports = Message;
diff --git a/docs/structures_MessageMedia.js.html b/docs/structures_MessageMedia.js.html index 5d8cf74..d52fd3b 100644 --- a/docs/structures_MessageMedia.js.html +++ b/docs/structures_MessageMedia.js.html @@ -2,9 +2,9 @@ - + - whatsapp-web.js 1.19.3 » Source: structures/MessageMedia.js + whatsapp-web.js 1.19.4 » Source: structures/MessageMedia.js @@ -15,7 +15,7 @@ @@ -150,7 +150,7 @@ module.exports = MessageMedia;
diff --git a/docs/structures_Order.js.html b/docs/structures_Order.js.html index dca025e..f2d76fb 100644 --- a/docs/structures_Order.js.html +++ b/docs/structures_Order.js.html @@ -2,9 +2,9 @@ - + - whatsapp-web.js 1.19.3 » Source: structures/Order.js + whatsapp-web.js 1.19.4 » 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 4cf4d1f..0d56ba4 100644 --- a/docs/structures_Payment.js.html +++ b/docs/structures_Payment.js.html @@ -2,9 +2,9 @@ - + - whatsapp-web.js 1.19.3 » Source: structures/Payment.js + whatsapp-web.js 1.19.4 » 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 ea8345b..ff74a37 100644 --- a/docs/structures_PrivateChat.js.html +++ b/docs/structures_PrivateChat.js.html @@ -2,9 +2,9 @@ - + - whatsapp-web.js 1.19.3 » Source: structures/PrivateChat.js + whatsapp-web.js 1.19.4 » 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 00d3549..7f14e29 100644 --- a/docs/structures_PrivateContact.js.html +++ b/docs/structures_PrivateContact.js.html @@ -2,9 +2,9 @@ - + - whatsapp-web.js 1.19.3 » Source: structures/PrivateContact.js + whatsapp-web.js 1.19.4 » 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 a81ff95..882d704 100644 --- a/docs/structures_Product.js.html +++ b/docs/structures_Product.js.html @@ -2,9 +2,9 @@ - + - whatsapp-web.js 1.19.3 » Source: structures/Product.js + whatsapp-web.js 1.19.4 » 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 aac6781..c4a071d 100644 --- a/docs/structures_ProductMetadata.js.html +++ b/docs/structures_ProductMetadata.js.html @@ -2,9 +2,9 @@ - + - whatsapp-web.js 1.19.3 » Source: structures/ProductMetadata.js + whatsapp-web.js 1.19.4 » 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 index b03702f..1dfda61 100644 --- a/docs/structures_Reaction.js.html +++ b/docs/structures_Reaction.js.html @@ -2,9 +2,9 @@ - + - whatsapp-web.js 1.19.3 » Source: structures/Reaction.js + whatsapp-web.js 1.19.4 » Source: structures/Reaction.js @@ -15,7 +15,7 @@ @@ -107,7 +107,7 @@ module.exports = Reaction;
diff --git a/docs/util_Constants.js.html b/docs/util_Constants.js.html index 6fa4463..7b66690 100644 --- a/docs/util_Constants.js.html +++ b/docs/util_Constants.js.html @@ -2,9 +2,9 @@ - + - whatsapp-web.js 1.19.3 » Source: util/Constants.js + whatsapp-web.js 1.19.4 » Source: util/Constants.js @@ -15,7 +15,7 @@ @@ -200,7 +200,7 @@ exports.MessageAck = {
diff --git a/docs/util_InterfaceController.js.html b/docs/util_InterfaceController.js.html index d4a7f1f..cc963e9 100644 --- a/docs/util_InterfaceController.js.html +++ b/docs/util_InterfaceController.js.html @@ -2,9 +2,9 @@ - + - whatsapp-web.js 1.19.3 » Source: util/InterfaceController.js + whatsapp-web.js 1.19.4 » Source: util/InterfaceController.js @@ -15,7 +15,7 @@ @@ -164,7 +164,7 @@ module.exports = InterfaceController;
diff --git a/docs/util_Util.js.html b/docs/util_Util.js.html index dec3fc7..539ac5d 100644 --- a/docs/util_Util.js.html +++ b/docs/util_Util.js.html @@ -2,9 +2,9 @@ - + - whatsapp-web.js 1.19.3 » Source: util/Util.js + whatsapp-web.js 1.19.4 » Source: util/Util.js @@ -15,7 +15,7 @@ @@ -225,7 +225,7 @@ module.exports = Util;
diff --git a/package.json b/package.json index b51832e..49c6d78 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "whatsapp-web.js", - "version": "1.19.3", + "version": "1.19.4", "description": "Library for interacting with the WhatsApp Web API ", "main": "./index.js", "typings": "./index.d.ts", From 2c084ef49e0aa26296cfb089ff23b5b6d5ac8087 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sun, 19 Feb 2023 05:22:36 +0200 Subject: [PATCH 07/16] Basic changes; no real change --- example.js | 3 +-- src/structures/Buttons.js | 12 ++++++------ src/util/Injected.js | 3 ++- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/example.js b/example.js index e169bb3..150607b 100644 --- a/example.js +++ b/example.js @@ -195,9 +195,8 @@ client.on('message', async msg => { client.interface.openChatWindowAt(quotedMsg.id._serialized); } } else if (msg.body === '!buttons') { - // Limited to 5 buttons per message and limited to 3 buttons for each kind, in this case the third quick reply button will be removed let button = new Buttons( - 'Button body', + 'Button body\n\nWant to test buttons some more? Check out https://github.com/wwebjs/buttons-test', [ { body: 'Some text' }, { body: 'Try clicking me (id:test)', id: 'test'}, diff --git a/src/structures/Buttons.js b/src/structures/Buttons.js index 908f2bb..dca16bf 100644 --- a/src/structures/Buttons.js +++ b/src/structures/Buttons.js @@ -7,8 +7,8 @@ const MessageMedia = require('./MessageMedia'); * @typedef {Object} ButtonSpec * @property {string} body - The text to show on the button. * @property {string=} id - Custom ID to set on the button. A random one will be generated if one is not passed. - * @ property {string=} url - Custom URL to set on the button. Optional and will change the type of the button - * @ property {string=} number - Custom URL to set on the button. Optional and will change the type of the button + * @property {string=} url - Custom URL to set on the button. Optional and will change the type of the button + * @property {string=} number - Custom URL to set on the button. Optional and will change the type of the button */ /** @@ -79,22 +79,22 @@ class Buttons { if (button.url && button.number && button.id) throw 'Only pick one of the following (url/number/id)'; if (button.number) { throw 'Not supported, URL and Call buttons are not supported on IOS'; - /* return { + return { index, callButton: { displayText: button.body, phoneNumber: button.number || '' } - }; */ + }; } else if (button.url) { throw 'Not supported, URL and Call buttons are not supported on IOS'; - /* return { + return { index, urlButton: { displayText: button.body, url: button.url || '' } - }; */ + }; } else { return { index, diff --git a/src/util/Injected.js b/src/util/Injected.js index 23a77db..90c749f 100644 --- a/src/util/Injected.js +++ b/src/util/Injected.js @@ -105,12 +105,13 @@ exports.ExposeStore = (moduleRaidStr) => { }; // Function to modify functions. + // This function simply just runs the callback you provide with the original code in the first argument and all the arguments passed to that function. window.injectToFunction = (selector, callback) => { const oldFunct = window.mR.findModule(selector.name)[selector.index][selector.property]; window.mR.findModule(selector.name)[selector.index][selector.property] = (...args) => callback(oldFunct, args); }; - // Find button models + // Find Template models window.Store.TemplateButtonModel = window.findProxyModel('TemplateButtonModel'); window.Store.TemplateButtonCollection = window.mR.findModule('TemplateButtonCollection')[0].TemplateButtonCollection; From f655453ca43d6ed08fde7a8b7756312fb371f144 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sun, 19 Feb 2023 05:29:11 +0200 Subject: [PATCH 08/16] Release all limiters --- src/structures/Buttons.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/structures/Buttons.js b/src/structures/Buttons.js index dca16bf..f5de27b 100644 --- a/src/structures/Buttons.js +++ b/src/structures/Buttons.js @@ -71,14 +71,14 @@ class Buttons { */ _format(buttons){ // Limit the buttons (max 3 of regular and 3 of special buttons) 5 buttons total at the same time - const templateButtons = buttons.filter(button => button.url || button.number).slice(0,3); - const regularButtons = buttons.filter(button => !button.url && !button.number).slice(0,3); - buttons = templateButtons.concat(regularButtons).slice(0,5); + const templateButtons = buttons.filter(button => button.url || button.number); + const regularButtons = buttons.filter(button => !button.url && !button.number); + buttons = templateButtons.concat(regularButtons); return buttons.map((button, index) => { if (button.url && button.number && button.id) throw 'Only pick one of the following (url/number/id)'; if (button.number) { - throw 'Not supported, URL and Call buttons are not supported on IOS'; + console.log("[WARNING] THIS FEATURE (CALL BUTTONS) IS UNSTABLE AND IS NOT TESTED OR EXPECTED TO WORK ON ALL PLATFORMS. Help test this feature with us on https://github.com/wwebjs/buttons-test") return { index, callButton: { @@ -87,7 +87,7 @@ class Buttons { } }; } else if (button.url) { - throw 'Not supported, URL and Call buttons are not supported on IOS'; + console.log("[WARNING] THIS FEATURE (URL BUTTONS) IS UNSTABLE AND IS NOT TESTED OR EXPECTED TO WORK ON ALL PLATFORMS. Help test this feature with us on https://github.com/wwebjs/buttons-test") return { index, urlButton: { From 7e3b2f6bdec045178a2c6e6b5fdcfc7b8bfe0be4 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sun, 19 Feb 2023 15:16:29 +0200 Subject: [PATCH 09/16] ESLINT + Clean --- src/structures/Buttons.js | 22 ++++++++---- src/util/Injected.js | 71 +++++++++++++++------------------------ 2 files changed, 43 insertions(+), 50 deletions(-) diff --git a/src/structures/Buttons.js b/src/structures/Buttons.js index f5de27b..3a2027f 100644 --- a/src/structures/Buttons.js +++ b/src/structures/Buttons.js @@ -17,6 +17,7 @@ const MessageMedia = require('./MessageMedia'); * @property {{displayText: string, url: string}=} urlButton * @property {{displayText: string, phoneNumber: string}=} callButton * @property {{displayText: string, id: string}=} quickReplyButton + * @property {{regularButtons: {text: string, id: string}}=} regularButtons */ /** @@ -28,8 +29,9 @@ class Buttons { * @param {ButtonSpec[]} buttons - See {@link ButtonSpec} * @param {string?} title * @param {string?} footer + * @param {boolean?} templateOverride */ - constructor(body, buttons, title, footer) { + constructor(body, buttons, title, footer, templateOverride) { /** * Message body * @type {string|MessageMedia} @@ -59,7 +61,7 @@ class Buttons { * buttons of message * @type {FormattedButtonSpec[]} */ - this.buttons = this._format(buttons); + this.buttons = this._format(buttons, templateOverride); if(!this.buttons.length){ throw '[BT01] No buttons';} } @@ -69,7 +71,7 @@ class Buttons { * @param {ButtonSpec[]} buttons * @returns {FormattedButtonSpec[]} */ - _format(buttons){ + _format(buttons, templateOverride){ // Limit the buttons (max 3 of regular and 3 of special buttons) 5 buttons total at the same time const templateButtons = buttons.filter(button => button.url || button.number); const regularButtons = buttons.filter(button => !button.url && !button.number); @@ -78,7 +80,7 @@ class Buttons { return buttons.map((button, index) => { if (button.url && button.number && button.id) throw 'Only pick one of the following (url/number/id)'; if (button.number) { - console.log("[WARNING] THIS FEATURE (CALL BUTTONS) IS UNSTABLE AND IS NOT TESTED OR EXPECTED TO WORK ON ALL PLATFORMS. Help test this feature with us on https://github.com/wwebjs/buttons-test") + console.log('[WARNING] THIS FEATURE (CALL BUTTONS) IS UNSTABLE AND IS NOT TESTED OR EXPECTED TO WORK ON ALL PLATFORMS. Help test this feature with us on https://github.com/wwebjs/buttons-test'); return { index, callButton: { @@ -87,7 +89,7 @@ class Buttons { } }; } else if (button.url) { - console.log("[WARNING] THIS FEATURE (URL BUTTONS) IS UNSTABLE AND IS NOT TESTED OR EXPECTED TO WORK ON ALL PLATFORMS. Help test this feature with us on https://github.com/wwebjs/buttons-test") + console.log('[WARNING] THIS FEATURE (URL BUTTONS) IS UNSTABLE AND IS NOT TESTED OR EXPECTED TO WORK ON ALL PLATFORMS. Help test this feature with us on https://github.com/wwebjs/buttons-test'); return { index, urlButton: { @@ -96,13 +98,21 @@ class Buttons { } }; } else { - return { + if (templateOverride) return { index, quickReplyButton: { displayText: button.body, id: button.id || `${index}` } }; + + return { + index, + regularButtons: { + id: button.id, + text: button.body + } + } } }); diff --git a/src/util/Injected.js b/src/util/Injected.js index 90c749f..92deb0a 100644 --- a/src/util/Injected.js +++ b/src/util/Injected.js @@ -251,6 +251,20 @@ exports.ExposeStore = (moduleRaidStr) => { property: 'typeAttributeFromProtobuf' }, (func, args) => { const [proto] = args; + + if (proto.ephemeralMessage) { + const { message } = proto.ephemeralMessage; + return message ? func(message) : 'text'; + } + if (proto.deviceSentMessage) { + const { message } = proto.deviceSentMessage; + return message ? func(message) : 'text'; + } + if (proto.viewOnceMessage) { + const { message } = proto.viewOnceMessage; + return message ? func(message) : 'text'; + } + if (proto.templateMessage?.hydratedTemplate) { const keys = Object.keys(proto.templateMessage?.hydratedTemplate); const messagePart = [ @@ -271,29 +285,6 @@ exports.ExposeStore = (moduleRaidStr) => { ) { return 'text'; } - - return func(...args); - }); - - window.injectToFunction({ - index: 0, - name: 'typeAttributeFromProtobuf', - property: 'typeAttributeFromProtobuf' - }, (func, args) => { - const [proto] = args; - - if (proto.ephemeralMessage) { - const { message } = proto.ephemeralMessage; - return message ? func(message) : 'text'; - } - if (proto.deviceSentMessage) { - const { message } = proto.deviceSentMessage; - return message ? func(message) : 'text'; - } - if (proto.viewOnceMessage) { - const { message } = proto.viewOnceMessage; - return message ? func(message) : 'text'; - } return func(...args); }); @@ -304,30 +295,22 @@ exports.ExposeStore = (moduleRaidStr) => { property: 'mediaTypeFromProtobuf' }, (func, args) => { const [proto] = args; + if (proto.deviceSentMessage) { + const { message } = proto.deviceSentMessage; + return message ? func(message) : null; + } + if (proto.ephemeralMessage) { + const { message } = proto.ephemeralMessage; + return message ? func(message) : null; + } + if (proto.viewOnceMessage) { + const { message } = proto.viewOnceMessage; + return message ? func(message) : null; + } + if (proto.templateMessage?.hydratedTemplate) { return func(proto.templateMessage.hydratedTemplate); } - return func(...args); - }); - - window.injectToFunction({ - index: 0, - name: 'mediaTypeFromProtobuf', - property: 'mediaTypeFromProtobuf' - }, (func, args) => { - const [proto] = args; - if (proto.deviceSentMessage) { - const { message } = proto.deviceSentMessage; - return message ? func(message) : null; - } - if (proto.ephemeralMessage) { - const { message } = proto.ephemeralMessage; - return message ? func(message) : null; - } - if (proto.viewOnceMessage) { - const { message } = proto.viewOnceMessage; - return message ? func(message) : null; - } return func(...args); }); From c0f9e78f6c9b4d7952534901995209db32355a51 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sun, 19 Feb 2023 15:47:07 +0200 Subject: [PATCH 10/16] missing semicolon --- src/structures/Buttons.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structures/Buttons.js b/src/structures/Buttons.js index 3a2027f..278443a 100644 --- a/src/structures/Buttons.js +++ b/src/structures/Buttons.js @@ -112,7 +112,7 @@ class Buttons { id: button.id, text: button.body } - } + }; } }); From e810b5146de7b7a8cb2c92fd58bfa0d2e7af3667 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Tue, 21 Feb 2023 00:04:51 +0200 Subject: [PATCH 11/16] Final fixes --- src/structures/Buttons.js | 25 +++---- src/util/Injected.js | 141 ++++++++++++++++++-------------------- 2 files changed, 77 insertions(+), 89 deletions(-) diff --git a/src/structures/Buttons.js b/src/structures/Buttons.js index 278443a..00e8e8b 100644 --- a/src/structures/Buttons.js +++ b/src/structures/Buttons.js @@ -31,7 +31,7 @@ class Buttons { * @param {string?} footer * @param {boolean?} templateOverride */ - constructor(body, buttons, title, footer, templateOverride) { + constructor(body, buttons, title, footer, templateOverride = false) { /** * Message body * @type {string|MessageMedia} @@ -61,9 +61,14 @@ class Buttons { * buttons of message * @type {FormattedButtonSpec[]} */ - this.buttons = this._format(buttons, templateOverride); + this.buttons = this._format(buttons); if(!this.buttons.length){ throw '[BT01] No buttons';} - + + /** + * Override buttons with templates + * @type {boolean} + */ + this.useTemplateButtons = templateOverride; } /** @@ -71,11 +76,11 @@ class Buttons { * @param {ButtonSpec[]} buttons * @returns {FormattedButtonSpec[]} */ - _format(buttons, templateOverride){ + _format(buttons){ // Limit the buttons (max 3 of regular and 3 of special buttons) 5 buttons total at the same time const templateButtons = buttons.filter(button => button.url || button.number); const regularButtons = buttons.filter(button => !button.url && !button.number); - buttons = templateButtons.concat(regularButtons); + buttons = regularButtons.concat(templateButtons); return buttons.map((button, index) => { if (button.url && button.number && button.id) throw 'Only pick one of the following (url/number/id)'; @@ -98,21 +103,13 @@ class Buttons { } }; } else { - if (templateOverride) return { + return { index, quickReplyButton: { displayText: button.body, id: button.id || `${index}` } }; - - return { - index, - regularButtons: { - id: button.id, - text: button.body - } - }; } }); diff --git a/src/util/Injected.js b/src/util/Injected.js index 92deb0a..dfd42b4 100644 --- a/src/util/Injected.js +++ b/src/util/Injected.js @@ -212,38 +212,40 @@ exports.ExposeStore = (moduleRaidStr) => { return proto; }); - window.injectToFunction({ - index: 0, - name: 'createMsgProtobuf', - property: 'createMsgProtobuf' - }, (func, args) => { - const proto = func(...args); - if (proto.templateMessage) { - proto.viewOnceMessage = { - message: { - templateMessage: proto.templateMessage, - }, - }; - delete proto.templateMessage; - } - if (proto.buttonsMessage) { - proto.viewOnceMessage = { - message: { - buttonsMessage: proto.buttonsMessage, - }, - }; - delete proto.buttonsMessage; - } - if (proto.listMessage) { - proto.viewOnceMessage = { - message: { - listMessage: proto.listMessage, - }, - }; - delete proto.listMessage; - } - return proto; - }); + setTimeout(() => { + window.injectToFunction({ + index: 0, + name: 'createMsgProtobuf', + property: 'createMsgProtobuf' + }, (func, args) => { + const proto = func(...args); + if (proto.templateMessage) { + proto.viewOnceMessage = { + message: { + templateMessage: proto.templateMessage, + }, + }; + delete proto.templateMessage; + } + if (proto.buttonsMessage) { + proto.viewOnceMessage = { + message: { + buttonsMessage: proto.buttonsMessage, + }, + }; + delete proto.buttonsMessage; + } + if (proto.listMessage) { + proto.viewOnceMessage = { + message: { + listMessage: proto.listMessage, + }, + }; + delete proto.listMessage; + } + return proto; + }); + }, 100); window.injectToFunction({ index: 0, @@ -286,6 +288,10 @@ exports.ExposeStore = (moduleRaidStr) => { return 'text'; } + if (proto.listMessage) { + return 'text'; + } + return func(...args); }); @@ -295,23 +301,9 @@ exports.ExposeStore = (moduleRaidStr) => { property: 'mediaTypeFromProtobuf' }, (func, args) => { const [proto] = args; - if (proto.deviceSentMessage) { - const { message } = proto.deviceSentMessage; - return message ? func(message) : null; - } - if (proto.ephemeralMessage) { - const { message } = proto.ephemeralMessage; - return message ? func(message) : null; - } - if (proto.viewOnceMessage) { - const { message } = proto.viewOnceMessage; - return message ? func(message) : null; - } - if (proto.templateMessage?.hydratedTemplate) { - return func(proto.templateMessage.hydratedTemplate); + return func(proto.templateMessage.hydratedTemplate); } - return func(...args); }); @@ -365,45 +357,44 @@ exports.LoadUtils = () => { return returnObject; } - if (typeof buttonsOptions.useTemplateButtons === 'undefined' || buttonsOptions.useTemplateButtons === null) { - buttonsOptions.useTemplateButtons = buttonsOptions.buttons.some((button) => { - return 'callButton' in button || 'urlButton' in button; - }); - } - returnObject.title = buttonsOptions.title; returnObject.footer = buttonsOptions.footer; if (buttonsOptions.useTemplateButtons) { returnObject.isFromTemplate = true; returnObject.hydratedButtons = buttonsOptions.buttons; - returnObject.buttons = new window.Store.TemplateButtonCollection; + returnObject.buttons = new window.Store.TemplateButtonCollection(); - returnObject.buttons.add(returnObject.hydratedButtons.map((button, index) => { - const buttonIndex = button.index ? button.index : index; - if (button.urlButton) { + message.buttons.add( + message.hydratedButtons.map((button, index) => { + const i = `${null != button.index ? button.index : index}`; + + if (button.urlButton) { return new window.Store.TemplateButtonModel({ - id: buttonIndex, - displayText: button.urlButton?.displayText || '', - url: button.urlButton?.url, - subtype: 'url' + id: i, + displayText: button.urlButton?.displayText, + url: button.urlButton?.url, + subtype: 'url', }); - } else if (button.callButton) { + } + + if (button.callButton) { return new window.Store.TemplateButtonModel({ - id: buttonIndex, - displayText: button.callButton?.displayText, - phoneNumber: button.callButton?.phoneNumber, - subtype: 'call' + id: i, + displayText: button.callButton.displayText, + phoneNumber: button.callButton.phoneNumber, + subtype: 'call', }); - } else { - return new window.Store.TemplateButtonModel({ - id: buttonIndex, - displayText: button.quickReplyButton?.displayText, - selectionId: button.quickReplyButton?.id, - subtype: 'quick_reply' - }); - } - })); + } + + return new window.Store.TemplateButtonModel({ + id: i, + displayText: button.quickReplyButton?.displayText, + selectionId: button.quickReplyButton?.id, + subtype: 'quick_reply', + }); + }) + ); } else { returnObject.isDynamicReplyButtonsMsg = true; From 8a84b5388de6aa9d7af4954fe86c5437bcf4dcda Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Tue, 21 Feb 2023 00:36:35 +0200 Subject: [PATCH 12/16] Spacing & undefined variables --- src/util/Injected.js | 52 ++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/util/Injected.js b/src/util/Injected.js index dfd42b4..57c42cd 100644 --- a/src/util/Injected.js +++ b/src/util/Injected.js @@ -302,7 +302,7 @@ exports.ExposeStore = (moduleRaidStr) => { }, (func, args) => { const [proto] = args; if (proto.templateMessage?.hydratedTemplate) { - return func(proto.templateMessage.hydratedTemplate); + return func(proto.templateMessage.hydratedTemplate); } return func(...args); }); @@ -365,34 +365,34 @@ exports.LoadUtils = () => { returnObject.hydratedButtons = buttonsOptions.buttons; returnObject.buttons = new window.Store.TemplateButtonCollection(); - message.buttons.add( - message.hydratedButtons.map((button, index) => { - const i = `${null != button.index ? button.index : index}`; - - if (button.urlButton) { + returnObject.buttons.add( + returnObject.hydratedButtons.map((button, index) => { + const i = `${null != button.index ? button.index : index}`; + + if (button.urlButton) { + return new window.Store.TemplateButtonModel({ + id: i, + displayText: button.urlButton?.displayText, + url: button.urlButton?.url, + subtype: 'url', + }); + } + + if (button.callButton) { + return new window.Store.TemplateButtonModel({ + id: i, + displayText: button.callButton.displayText, + phoneNumber: button.callButton.phoneNumber, + subtype: 'call', + }); + } + return new window.Store.TemplateButtonModel({ id: i, - displayText: button.urlButton?.displayText, - url: button.urlButton?.url, - subtype: 'url', + displayText: button.quickReplyButton?.displayText, + selectionId: button.quickReplyButton?.id, + subtype: 'quick_reply', }); - } - - if (button.callButton) { - return new window.Store.TemplateButtonModel({ - id: i, - displayText: button.callButton.displayText, - phoneNumber: button.callButton.phoneNumber, - subtype: 'call', - }); - } - - return new window.Store.TemplateButtonModel({ - id: i, - displayText: button.quickReplyButton?.displayText, - selectionId: button.quickReplyButton?.id, - subtype: 'quick_reply', - }); }) ); } From d126c35e1d59de67a31e444aeb25030316c2c4a4 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Tue, 21 Feb 2023 00:43:12 +0200 Subject: [PATCH 13/16] ESLint has dyslexia so spacing is important --- src/util/Injected.js | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/util/Injected.js b/src/util/Injected.js index 57c42cd..0d8dff8 100644 --- a/src/util/Injected.js +++ b/src/util/Injected.js @@ -367,31 +367,31 @@ exports.LoadUtils = () => { returnObject.buttons.add( returnObject.hydratedButtons.map((button, index) => { - const i = `${null != button.index ? button.index : index}`; + const i = `${null != button.index ? button.index : index}`; if (button.urlButton) { - return new window.Store.TemplateButtonModel({ - id: i, - displayText: button.urlButton?.displayText, - url: button.urlButton?.url, - subtype: 'url', - }); + return new window.Store.TemplateButtonModel({ + id: i, + displayText: button.urlButton?.displayText, + url: button.urlButton?.url, + subtype: 'url', + }); } if (button.callButton) { - return new window.Store.TemplateButtonModel({ - id: i, - displayText: button.callButton.displayText, - phoneNumber: button.callButton.phoneNumber, - subtype: 'call', - }); + return new window.Store.TemplateButtonModel({ + id: i, + displayText: button.callButton.displayText, + phoneNumber: button.callButton.phoneNumber, + subtype: 'call', + }); } return new window.Store.TemplateButtonModel({ - id: i, - displayText: button.quickReplyButton?.displayText, - selectionId: button.quickReplyButton?.id, - subtype: 'quick_reply', + id: i, + displayText: button.quickReplyButton?.displayText, + selectionId: button.quickReplyButton?.id, + subtype: 'quick_reply', }); }) ); From eafdfe12f2e5af9ae017dbe3accf5f38adf4a697 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Tue, 21 Feb 2023 01:13:43 +0200 Subject: [PATCH 14/16] space --- src/util/Injected.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/Injected.js b/src/util/Injected.js index 0d8dff8..eb4f6c5 100644 --- a/src/util/Injected.js +++ b/src/util/Injected.js @@ -394,7 +394,7 @@ exports.LoadUtils = () => { subtype: 'quick_reply', }); }) - ); + ); } else { returnObject.isDynamicReplyButtonsMsg = true; From b4c2915334bf25fa440a0a59a3c603663b7233e1 Mon Sep 17 00:00:00 2001 From: Jose Alberto Guerra Ugalde Date: Tue, 21 Feb 2023 03:45:13 -0600 Subject: [PATCH 15/16] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 49c6d78..f96c857 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "whatsapp-web.js", "version": "1.19.4", - "description": "Library for interacting with the WhatsApp Web API ", + "description": "Library for interacting with the WhatsApp Web API - Buttons templagtes and others added.", "main": "./index.js", "typings": "./index.d.ts", "scripts": { From 7f62f2b62b889440c7e0f1c939952cb413ec561b Mon Sep 17 00:00:00 2001 From: Jose Alberto Guerra Ugalde Date: Tue, 21 Feb 2023 03:46:44 -0600 Subject: [PATCH 16/16] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f96c857..6830562 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "whatsapp-web.js", "version": "1.19.4", - "description": "Library for interacting with the WhatsApp Web API - Buttons templagtes and others added.", + "description": "Library for interacting with the WhatsApp Web API - Buttons templates and others added.", "main": "./index.js", "typings": "./index.d.ts", "scripts": {