regresamos a version anterios - botones normales

This commit is contained in:
2023-02-21 05:02:01 -06:00
parent bf93c6a10c
commit 83560a2b56
3 changed files with 119 additions and 101 deletions

View File

@@ -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
*/
/**
@@ -17,7 +17,6 @@ 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
*/
/**
@@ -29,9 +28,8 @@ class Buttons {
* @param {ButtonSpec[]} buttons - See {@link ButtonSpec}
* @param {string?} title
* @param {string?} footer
* @param {boolean?} templateOverride
*/
constructor(body, buttons, title, footer, templateOverride = false) {
constructor(body, buttons, title, footer) {
/**
* Message body
* @type {string|MessageMedia}
@@ -63,12 +61,7 @@ class Buttons {
*/
this.buttons = this._format(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){
// 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 = regularButtons.concat(templateButtons);
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);
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');
return {
throw 'Not supported, URL and Call buttons are not supported on IOS';
/* return {
index,
callButton: {
displayText: button.body,
phoneNumber: button.number || ''
}
};
}; */
} 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');
return {
throw 'Not supported, URL and Call buttons are not supported on IOS';
/* return {
index,
urlButton: {
displayText: button.body,
url: button.url || ''
}
};
}; */
} else {
return {
index,