From 617ea37b71491b759b062a8d6e6704306c6c121a Mon Sep 17 00:00:00 2001 From: Sergio Carvalho Date: Mon, 15 Aug 2022 15:04:12 -0300 Subject: [PATCH] Fix buttons list (#1656) * fix: change the individual buttons limti to 3, still 5 on total * docs: Change buttons example to include clipboard --- example.js | 6 ++++-- src/structures/Buttons.js | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/example.js b/example.js index ab8c740..ede0063 100644 --- a/example.js +++ b/example.js @@ -189,16 +189,18 @@ 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', [ { body: 'whatsapp-web.js', url: 'https://wwebjs.dev/' }, + { body: 'Copy', url: 'https://www.whatsapp.com/otp/copy/This text will be copied to your clipboard' }, { body: 'Call me', number: '+1 (805) 457-4992' }, - { body: 'third special button', number: '+1 (202) 968-6161' },// Limited to 2 especial buttons, this one will be ignored + // Limited to 3 template buttons, any more will be ignored { body: 'Some text' }, { body: 'Another text' }, { body: 'Another another text' }, - { body: 'Fourth button' }// Limited to 3 regular buttons, this one will be ignored + // Limited to 3 quick reply buttons, any more will be ignored ], 'title', 'footer' diff --git a/src/structures/Buttons.js b/src/structures/Buttons.js index 567240b..d727042 100644 --- a/src/structures/Buttons.js +++ b/src/structures/Buttons.js @@ -70,10 +70,10 @@ class Buttons { * @returns {FormattedButtonSpec[]} */ _format(buttons){ - // Limit the buttons (max 3 of regular and 2 of special buttons) - const templateButtons = buttons.filter(button => button.url || button.number).slice(0,2); + // 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); + 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)';