Compare commits

..

1 Commits

Author SHA1 Message Date
5c8ef602f3 Update package.json 2023-02-21 03:44:22 -06:00
4 changed files with 101 additions and 119 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 - WaWJS2", "description": "Library for interacting with the WhatsApp Web API - Buttons Templates and others added.",
"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(timestamp, !0); await chat.mute.mute({expiration: timestamp, sendDevice:!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,6 +17,7 @@ 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
*/ */
/** /**
@@ -28,8 +29,9 @@ 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) { constructor(body, buttons, title, footer, templateOverride = false) {
/** /**
* Message body * Message body
* @type {string|MessageMedia} * @type {string|MessageMedia}
@@ -62,6 +64,11 @@ 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;
} }
/** /**
@@ -71,30 +78,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).slice(0,3); const templateButtons = buttons.filter(button => button.url || button.number);
const regularButtons = buttons.filter(button => !button.url && !button.number).slice(0,3); const regularButtons = buttons.filter(button => !button.url && !button.number);
buttons = templateButtons.concat(regularButtons).slice(0,5); buttons = regularButtons.concat(templateButtons);
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) {
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 { 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) {
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 { 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,12 +105,13 @@ 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 button models // Find Template 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;
@@ -211,38 +212,40 @@ exports.ExposeStore = (moduleRaidStr) => {
return proto; return proto;
}); });
window.injectToFunction({ setTimeout(() => {
index: 0, window.injectToFunction({
name: 'createMsgProtobuf', index: 0,
property: 'createMsgProtobuf' name: 'createMsgProtobuf',
}, (func, args) => { property: 'createMsgProtobuf'
const proto = func(...args); }, (func, args) => {
if (proto.templateMessage) { const proto = func(...args);
proto.viewOnceMessage = { if (proto.templateMessage) {
message: { proto.viewOnceMessage = {
templateMessage: proto.templateMessage, message: {
}, templateMessage: proto.templateMessage,
}; },
delete proto.templateMessage; };
} delete proto.templateMessage;
if (proto.buttonsMessage) { }
proto.viewOnceMessage = { if (proto.buttonsMessage) {
message: { proto.viewOnceMessage = {
buttonsMessage: proto.buttonsMessage, message: {
}, buttonsMessage: proto.buttonsMessage,
}; },
delete proto.buttonsMessage; };
} delete proto.buttonsMessage;
if (proto.listMessage) { }
proto.viewOnceMessage = { if (proto.listMessage) {
message: { proto.viewOnceMessage = {
listMessage: proto.listMessage, message: {
}, listMessage: proto.listMessage,
}; },
delete proto.listMessage; };
} delete proto.listMessage;
return proto; }
}); return proto;
});
}, 100);
window.injectToFunction({ window.injectToFunction({
index: 0, index: 0,
@@ -250,6 +253,20 @@ 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 = [
@@ -271,27 +288,8 @@ exports.ExposeStore = (moduleRaidStr) => {
return 'text'; return 'text';
} }
return func(...args); if (proto.listMessage) {
}); 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);
@@ -309,28 +307,6 @@ 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',
@@ -381,45 +357,44 @@ 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: buttonIndex, id: i,
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;