mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-20 12:39:20 +00:00
fix types and docs for Buttons class (#1070)
* fix: typing of buttons class * fix remaining types Co-authored-by: Pedro Lopez <pedroslopez@me.com>
This commit is contained in:
4
index.d.ts
vendored
4
index.d.ts
vendored
@@ -1211,11 +1211,11 @@ declare namespace WAWebJS {
|
|||||||
/** Message type buttons */
|
/** Message type buttons */
|
||||||
export class Buttons {
|
export class Buttons {
|
||||||
body: string | MessageMedia
|
body: string | MessageMedia
|
||||||
buttons: Array<Array<string>>
|
buttons: Array<{ buttonId: string; buttonText: {displayText: string}; type: number }>
|
||||||
title?: string | null
|
title?: string | null
|
||||||
footer?: string | null
|
footer?: string | null
|
||||||
|
|
||||||
constructor(body: string, buttons: Array<Array<string>>, title?: string | null, footer?: string | null)
|
constructor(body: string, buttons: Array<{ id?: string; body: string }>, title?: string | null, footer?: string | null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,27 @@
|
|||||||
const MessageMedia = require('./MessageMedia');
|
const MessageMedia = require('./MessageMedia');
|
||||||
const Util = require('../util/Util');
|
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
|
* Message type buttons
|
||||||
*/
|
*/
|
||||||
class Buttons {
|
class Buttons {
|
||||||
/**
|
/**
|
||||||
* @param {string|MessageMedia} body
|
* @param {string|MessageMedia} body
|
||||||
* @param {Array<Array<string>>} buttons
|
* @param {ButtonSpec[]} buttons - See {@link ButtonSpec}
|
||||||
* @param {string?} title
|
* @param {string?} title
|
||||||
* @param {string?} footer
|
* @param {string?} footer
|
||||||
*/
|
*/
|
||||||
@@ -41,7 +55,7 @@ class Buttons {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* buttons of message
|
* buttons of message
|
||||||
* @type {Array<Array<string>>}
|
* @type {FormattedButtonSpec[]}
|
||||||
*/
|
*/
|
||||||
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';}
|
||||||
@@ -50,8 +64,8 @@ class Buttons {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates button array from simple array
|
* Creates button array from simple array
|
||||||
* @param {Array<Array<string>>} buttons
|
* @param {ButtonSpec[]} buttons
|
||||||
* @returns {Array<Array<string>>}
|
* @returns {FormattedButtonSpec[]}
|
||||||
* @example
|
* @example
|
||||||
* Input: [{id:'customId',body:'button1'},{body:'button2'},{body:'button3'},{body:'button4'}]
|
* 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}]
|
* Returns: [{ buttonId:'customId',buttonText:{'displayText':'button1'},type: 1 },{buttonId:'n3XKsL',buttonText:{'displayText':'button2'},type:1},{buttonId:'NDJk0a',buttonText:{'displayText':'button3'},type:1}]
|
||||||
|
|||||||
Reference in New Issue
Block a user