Compare commits

...

18 Commits

Author SHA1 Message Date
14f7854bb8 Update Injected.js 2023-02-27 04:53:34 -06:00
22720038b5 Update package.json 2023-02-27 00:06:45 -06:00
83560a2b56 regresamos a version anterios - botones normales 2023-02-21 05:02:01 -06:00
bf93c6a10c Update package.json 2023-02-21 04:50:51 -06:00
d7d7df4b74 Merge branch 'WaWJS2' of https://github.com/cheveguerra/whatsapp-web.js into WaWJS2 2023-02-21 04:47:45 -06:00
7f62f2b62b Update package.json 2023-02-21 03:46:44 -06:00
b4c2915334 Update package.json 2023-02-21 03:45:13 -06:00
Rajeh Taher
e3442e5748 space 2023-02-21 03:34:12 -06:00
Rajeh Taher
d03c1a65c2 ESLint has dyslexia so spacing is important 2023-02-21 03:34:12 -06:00
Rajeh Taher
9cb90ff457 Spacing & undefined variables 2023-02-21 03:34:12 -06:00
Rajeh Taher
9c6b1ab7b1 Final fixes 2023-02-21 03:34:12 -06:00
Rajeh Taher
70b32705c9 missing semicolon 2023-02-21 03:33:46 -06:00
Rajeh Taher
ceabbd5177 ESLINT + Clean 2023-02-21 03:33:46 -06:00
Rajeh Taher
ec0ee3c243 Release all limiters 2023-02-21 03:33:46 -06:00
Rajeh Taher
2ce2c7e97d Basic changes; no real change 2023-02-21 03:33:46 -06:00
tuyuribr
74a02cb736 Merge branch 'main' into fix-buttons-list 2023-02-18 10:45:47 -06:00
29b61b396b Merge branch 'pedroslopez:main' into WaWJS2 2023-02-10 13:18:04 -06:00
025f9914c3 Merge branch 'pedroslopez:main' into test2 2023-01-15 17:19:13 -06:00
4 changed files with 119 additions and 101 deletions

View File

@@ -1,7 +1,7 @@
{ {
"name": "whatsapp-web.js", "name": "whatsapp-web.js",
"version": "1.19.4", "version": "1.19.4",
"description": "Library for interacting with the WhatsApp Web API ", "description": "Library for interacting with the WhatsApp Web API - WaWJS2",
"main": "./index.js", "main": "./index.js",
"typings": "./index.d.ts", "typings": "./index.d.ts",
"scripts": { "scripts": {

View File

@@ -937,7 +937,7 @@ class Client extends EventEmitter {
unmuteDate = unmuteDate ? unmuteDate.getTime() / 1000 : -1; unmuteDate = unmuteDate ? unmuteDate.getTime() / 1000 : -1;
await this.pupPage.evaluate(async (chatId, timestamp) => { await this.pupPage.evaluate(async (chatId, timestamp) => {
let chat = await window.Store.Chat.get(chatId); let chat = await window.Store.Chat.get(chatId);
await chat.mute.mute({expiration: timestamp, sendDevice:!0}); await chat.mute.mute(timestamp, !0);
}, chatId, unmuteDate || -1); }, chatId, unmuteDate || -1);
} }

View File

@@ -7,8 +7,8 @@ const MessageMedia = require('./MessageMedia');
* @typedef {Object} ButtonSpec * @typedef {Object} ButtonSpec
* @property {string} body - The text to show on the button. * @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=} 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=} 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=} number - Custom URL to set on the button. Optional and will change the type of the button
*/ */
/** /**
@@ -17,7 +17,6 @@ const MessageMedia = require('./MessageMedia');
* @property {{displayText: string, url: string}=} urlButton * @property {{displayText: string, url: string}=} urlButton
* @property {{displayText: string, phoneNumber: string}=} callButton * @property {{displayText: string, phoneNumber: string}=} callButton
* @property {{displayText: string, id: string}=} quickReplyButton * @property {{displayText: string, id: string}=} quickReplyButton
* @property {{regularButtons: {text: string, id: string}}=} regularButtons
*/ */
/** /**
@@ -29,9 +28,8 @@ class Buttons {
* @param {ButtonSpec[]} buttons - See {@link ButtonSpec} * @param {ButtonSpec[]} buttons - See {@link ButtonSpec}
* @param {string?} title * @param {string?} title
* @param {string?} footer * @param {string?} footer
* @param {boolean?} templateOverride
*/ */
constructor(body, buttons, title, footer, templateOverride = false) { constructor(body, buttons, title, footer) {
/** /**
* Message body * Message body
* @type {string|MessageMedia} * @type {string|MessageMedia}
@@ -64,11 +62,6 @@ class Buttons {
this.buttons = this._format(buttons); this.buttons = this._format(buttons);
if(!this.buttons.length){ throw '[BT01] No buttons';} if(!this.buttons.length){ throw '[BT01] No buttons';}
/**
* Override buttons with templates
* @type {boolean}
*/
this.useTemplateButtons = templateOverride;
} }
/** /**
@@ -78,30 +71,30 @@ class Buttons {
*/ */
_format(buttons){ _format(buttons){
// Limit the buttons (max 3 of regular and 3 of special buttons) 5 buttons total at the same time // 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 templateButtons = buttons.filter(button => button.url || button.number).slice(0,3);
const regularButtons = buttons.filter(button => !button.url && !button.number); const regularButtons = buttons.filter(button => !button.url && !button.number).slice(0,3);
buttons = regularButtons.concat(templateButtons); buttons = templateButtons.concat(regularButtons).slice(0,5);
return buttons.map((button, index) => { return buttons.map((button, index) => {
if (button.url && button.number && button.id) throw 'Only pick one of the following (url/number/id)'; if (button.url && button.number && button.id) throw 'Only pick one of the following (url/number/id)';
if (button.number) { 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'); throw 'Not supported, URL and Call buttons are not supported on IOS';
return { /* return {
index, index,
callButton: { callButton: {
displayText: button.body, displayText: button.body,
phoneNumber: button.number || '' phoneNumber: button.number || ''
} }
}; }; */
} else if (button.url) { } 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'); throw 'Not supported, URL and Call buttons are not supported on IOS';
return { /* return {
index, index,
urlButton: { urlButton: {
displayText: button.body, displayText: button.body,
url: button.url || '' url: button.url || ''
} }
}; }; */
} else { } else {
return { return {
index, index,

View File

@@ -105,13 +105,12 @@ exports.ExposeStore = (moduleRaidStr) => {
}; };
// Function to modify functions. // 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) => { window.injectToFunction = (selector, callback) => {
const oldFunct = window.mR.findModule(selector.name)[selector.index][selector.property]; const oldFunct = window.mR.findModule(selector.name)[selector.index][selector.property];
window.mR.findModule(selector.name)[selector.index][selector.property] = (...args) => callback(oldFunct, args); window.mR.findModule(selector.name)[selector.index][selector.property] = (...args) => callback(oldFunct, args);
}; };
// Find Template models // Find button models
window.Store.TemplateButtonModel = window.findProxyModel('TemplateButtonModel'); window.Store.TemplateButtonModel = window.findProxyModel('TemplateButtonModel');
window.Store.TemplateButtonCollection = window.mR.findModule('TemplateButtonCollection')[0].TemplateButtonCollection; window.Store.TemplateButtonCollection = window.mR.findModule('TemplateButtonCollection')[0].TemplateButtonCollection;
@@ -212,40 +211,38 @@ exports.ExposeStore = (moduleRaidStr) => {
return proto; return proto;
}); });
setTimeout(() => { window.injectToFunction({
window.injectToFunction({ index: 0,
index: 0, name: 'createMsgProtobuf',
name: 'createMsgProtobuf', property: 'createMsgProtobuf'
property: 'createMsgProtobuf' }, (func, args) => {
}, (func, args) => { const proto = func(...args);
const proto = func(...args); if (proto.templateMessage) {
if (proto.templateMessage) { proto.viewOnceMessage = {
proto.viewOnceMessage = { message: {
message: { templateMessage: proto.templateMessage,
templateMessage: proto.templateMessage, },
}, };
}; delete proto.templateMessage;
delete proto.templateMessage; }
} if (proto.buttonsMessage) {
if (proto.buttonsMessage) { proto.viewOnceMessage = {
proto.viewOnceMessage = { message: {
message: { buttonsMessage: proto.buttonsMessage,
buttonsMessage: proto.buttonsMessage, },
}, };
}; delete proto.buttonsMessage;
delete proto.buttonsMessage; }
} if (proto.listMessage) {
if (proto.listMessage) { proto.viewOnceMessage = {
proto.viewOnceMessage = { message: {
message: { listMessage: proto.listMessage,
listMessage: proto.listMessage, },
}, };
}; delete proto.listMessage;
delete proto.listMessage; }
} return proto;
return proto; });
});
}, 100);
window.injectToFunction({ window.injectToFunction({
index: 0, index: 0,
@@ -253,20 +250,6 @@ exports.ExposeStore = (moduleRaidStr) => {
property: 'typeAttributeFromProtobuf' property: 'typeAttributeFromProtobuf'
}, (func, args) => { }, (func, args) => {
const [proto] = 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) { if (proto.templateMessage?.hydratedTemplate) {
const keys = Object.keys(proto.templateMessage?.hydratedTemplate); const keys = Object.keys(proto.templateMessage?.hydratedTemplate);
const messagePart = [ const messagePart = [
@@ -288,8 +271,27 @@ exports.ExposeStore = (moduleRaidStr) => {
return 'text'; return 'text';
} }
if (proto.listMessage) { return func(...args);
return 'text'; });
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); return func(...args);
@@ -307,6 +309,28 @@ exports.ExposeStore = (moduleRaidStr) => {
return func(...args); 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);
});
window.injectToFunction({ window.injectToFunction({
index: 0, index: 0,
name: 'encodeMaybeMediaType', name: 'encodeMaybeMediaType',
@@ -357,44 +381,45 @@ exports.LoadUtils = () => {
return returnObject; 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.title = buttonsOptions.title;
returnObject.footer = buttonsOptions.footer; returnObject.footer = buttonsOptions.footer;
if (buttonsOptions.useTemplateButtons) { if (buttonsOptions.useTemplateButtons) {
returnObject.isFromTemplate = true; returnObject.isFromTemplate = true;
returnObject.hydratedButtons = buttonsOptions.buttons; 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 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',
});
}
returnObject.buttons.add(returnObject.hydratedButtons.map((button, index) => {
const buttonIndex = button.index ? button.index : index;
if (button.urlButton) {
return new window.Store.TemplateButtonModel({ return new window.Store.TemplateButtonModel({
id: i, id: buttonIndex,
displayText: button.urlButton?.displayText || '',
url: button.urlButton?.url,
subtype: 'url'
});
} else if (button.callButton) {
return new window.Store.TemplateButtonModel({
id: buttonIndex,
displayText: button.callButton?.displayText,
phoneNumber: button.callButton?.phoneNumber,
subtype: 'call'
});
} else {
return new window.Store.TemplateButtonModel({
id: buttonIndex,
displayText: button.quickReplyButton?.displayText, displayText: button.quickReplyButton?.displayText,
selectionId: button.quickReplyButton?.id, selectionId: button.quickReplyButton?.id,
subtype: 'quick_reply', subtype: 'quick_reply'
}); });
}) }
); }));
} }
else { else {
returnObject.isDynamicReplyButtonsMsg = true; returnObject.isDynamicReplyButtonsMsg = true;