diff --git a/index.d.ts b/index.d.ts index 65b6ea9..f596284 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1211,11 +1211,11 @@ declare namespace WAWebJS { /** Message type buttons */ export class Buttons { body: string | MessageMedia - buttons: Array> + buttons: Array<{ buttonId: string; buttonText: {displayText: string}; type: number }> title?: string | null footer?: string | null - constructor(body: string, buttons: Array>, title?: string | null, footer?: string | null) + constructor(body: string, buttons: Array<{ id?: string; body: string }>, title?: string | null, footer?: string | null) } } diff --git a/src/structures/Buttons.js b/src/structures/Buttons.js index a67b3fa..66b7cdf 100644 --- a/src/structures/Buttons.js +++ b/src/structures/Buttons.js @@ -3,13 +3,27 @@ const MessageMedia = require('./MessageMedia'); const Util = require('../util/Util'); +/** + * Button spec used in Buttons constructor + * @typedef {Object} ButtonSpec + * @property {string=} id - Custom ID to set on the button. A random one will be generated if one is not passed. + * @property {string} body - The text to show on the button. + */ + +/** + * @typedef {Object} FormattedButtonSpec + * @property {string} buttonId + * @property {number} type + * @property {Object} buttonText + */ + /** * Message type buttons */ class Buttons { /** * @param {string|MessageMedia} body - * @param {Array>} buttons + * @param {ButtonSpec[]} buttons - See {@link ButtonSpec} * @param {string?} title * @param {string?} footer */ @@ -41,7 +55,7 @@ class Buttons { /** * buttons of message - * @type {Array>} + * @type {FormattedButtonSpec[]} */ this.buttons = this._format(buttons); if(!this.buttons.length){ throw '[BT01] No buttons';} @@ -50,8 +64,8 @@ class Buttons { /** * Creates button array from simple array - * @param {Array>} buttons - * @returns {Array>} + * @param {ButtonSpec[]} buttons + * @returns {FormattedButtonSpec[]} * @example * Input: [{id:'customId',body:'button1'},{body:'button2'},{body:'button3'},{body:'button4'}] * Returns: [{ buttonId:'customId',buttonText:{'displayText':'button1'},type: 1 },{buttonId:'n3XKsL',buttonText:{'displayText':'button2'},type:1},{buttonId:'NDJk0a',buttonText:{'displayText':'button3'},type:1}]