From f0b6293f51bd0fa1d9d17b30a4ac06e054d29e93 Mon Sep 17 00:00:00 2001 From: DaviSM Date: Tue, 17 Oct 2023 21:29:40 -0300 Subject: [PATCH] menu teste 6 --- package.json | 2 +- src/WhatsApp.d.ts | 13 ++++++++++--- src/index.ts | 39 ++++++++++++++++++++++++--------------- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index b228053..c031734 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "business-whatsapp", "author": "frkr", "license": "MIT", - "version": "18.0.05", + "version": "18.0.06", "description": "WhatsApp Business API Client unofficial", "homepage": "https://ideias.casa/", "repository": { diff --git a/src/WhatsApp.d.ts b/src/WhatsApp.d.ts index b52ecbd..c155e5e 100644 --- a/src/WhatsApp.d.ts +++ b/src/WhatsApp.d.ts @@ -108,9 +108,9 @@ interface SectionsEntity { } interface RowsEntity { - id: string; - title: string; - description: string; + id?: string; + title?: string; + description?: string; } interface VariableEntity { @@ -118,6 +118,13 @@ interface VariableEntity { text?: string; } +interface MenuRequest { + titulo?: string; + msg?: string; + rodape?: string; + itens: string[]; +} + interface TextMessage extends MessageEntity { preview_url?: boolean; body: string; diff --git a/src/index.ts b/src/index.ts index 2ec5fbb..4d6ba42 100644 --- a/src/index.ts +++ b/src/index.ts @@ -151,28 +151,37 @@ export async function getMedia(apikey: string, url: string): Promise { )).blob(); } -export async function sendMenu(auth: WAAuth, waid: string, posicao: string, button: string, body: string, ...item: RowsEntity[]): Promise { +export async function sendMenu(auth: WAAuth, waid: string, menu: MenuRequest): Promise { let msgInteractive: InteractiveMessage = { type: "list", - header: { - type: "text", - text: "i", - }, - footer: { - text: posicao, - }, - body: { - text: body, - }, action: { - button: button, + button: 'Menu', sections: [{ - title: posicao, - rows: item, + title: 'Menu', + rows: menu.itens.map((item, index) => { + return { + title: item, + } as RowsEntity; + }) }] } } - + if (menu.titulo) { + msgInteractive["header"] = { + type: "text", + text: menu.titulo, + } + } + if (menu.msg) { + msgInteractive["body"] = { + text: menu.msg, + } + } + if (menu.rodape) { + msgInteractive["footer"] = { + text: menu.rodape, + } + } let content: MessageObjectRequest = { recipient_type: "individual",