From 552afe5c24f418087aecb3e8e5862dfe4f49b365 Mon Sep 17 00:00:00 2001 From: Ibnu syawal <46734417+ibnusyawall@users.noreply.github.com> Date: Wed, 7 Jul 2021 23:26:04 +0700 Subject: [PATCH] Added method to send list message (#574) * Added method to send list message * Added method to send list message --- src/WAConnection/6.MessagesSend.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/WAConnection/6.MessagesSend.ts b/src/WAConnection/6.MessagesSend.ts index 3dd2fe4..6bf700f 100644 --- a/src/WAConnection/6.MessagesSend.ts +++ b/src/WAConnection/6.MessagesSend.ts @@ -35,6 +35,34 @@ export class WAConnection extends Base { await this.relayWAMessage (waMessage, { waitForAck: options.waitForAck !== false }) return waMessage } + /** + * Send a list message + * @param id the id to send to + * @param button the optional button text, title and description button + * @param rows the rows of sections list message + */ + async sendListMessage( + id: string, + button: { buttonText?: string; description?: string; title?: string }, + rows: any = [], + ) { + let messageList = WAMessageProto.Message.fromObject({ + listMessage: WAMessageProto.ListMessage.fromObject({ + buttonText: button.buttonText, + description: button.description, + listType: 1, + sections: [ + { + title: button.title, + rows: [ ...rows ] + } + ] + }) + }) + let waMessageList = await this.prepareMessageFromContent(id, messageList, {}) + await this.relayWAMessage (waMessageList, { waitForAck: true }) + return waMessageList + } /** Prepares a message for sending via sendWAMessage () */ async prepareMessage( id: string,