Skip to content

Commit

Permalink
menu teste 6
Browse files Browse the repository at this point in the history
  • Loading branch information
frkr committed Oct 18, 2023
1 parent d69f8c3 commit f0b6293
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
13 changes: 10 additions & 3 deletions src/WhatsApp.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,23 @@ interface SectionsEntity {
}

interface RowsEntity {
id: string;
title: string;
description: string;
id?: string;
title?: string;
description?: string;
}

interface VariableEntity {
type?: 'text';
text?: string;
}

interface MenuRequest {
titulo?: string;
msg?: string;
rodape?: string;
itens: string[];
}

interface TextMessage extends MessageEntity {
preview_url?: boolean;
body: string;
Expand Down
39 changes: 24 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,28 +151,37 @@ export async function getMedia(apikey: string, url: string): Promise<Blob> {
)).blob();
}

export async function sendMenu(auth: WAAuth, waid: string, posicao: string, button: string, body: string, ...item: RowsEntity[]): Promise<Response> {
export async function sendMenu(auth: WAAuth, waid: string, menu: MenuRequest): Promise<Response> {
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",
Expand Down

0 comments on commit f0b6293

Please sign in to comment.