mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 03:29:14 +00:00
Compare commits
18 Commits
fix-button
...
WaWJS2
| Author | SHA1 | Date | |
|---|---|---|---|
| 14f7854bb8 | |||
| 22720038b5 | |||
| 83560a2b56 | |||
| bf93c6a10c | |||
| d7d7df4b74 | |||
| 7f62f2b62b | |||
| b4c2915334 | |||
|
|
e3442e5748 | ||
|
|
d03c1a65c2 | ||
|
|
9cb90ff457 | ||
|
|
9c6b1ab7b1 | ||
|
|
70b32705c9 | ||
|
|
ceabbd5177 | ||
|
|
ec0ee3c243 | ||
|
|
2ce2c7e97d | ||
|
|
74a02cb736 | ||
| 29b61b396b | |||
| 025f9914c3 |
@@ -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": {
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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}
|
||||||
@@ -63,12 +61,7 @@ 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,
|
||||||
|
|||||||
@@ -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 = [
|
||||||
@@ -287,9 +270,28 @@ exports.ExposeStore = (moduleRaidStr) => {
|
|||||||
) {
|
) {
|
||||||
return 'text';
|
return 'text';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return func(...args);
|
||||||
|
});
|
||||||
|
|
||||||
if (proto.listMessage) {
|
window.injectToFunction({
|
||||||
return 'text';
|
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);
|
||||||
@@ -306,6 +308,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,
|
||||||
@@ -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.buttons.add(returnObject.hydratedButtons.map((button, index) => {
|
||||||
returnObject.hydratedButtons.map((button, index) => {
|
const buttonIndex = button.index ? button.index : index;
|
||||||
const i = `${null != button.index ? button.index : index}`;
|
if (button.urlButton) {
|
||||||
|
|
||||||
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({
|
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user