Skip to content

Commit

Permalink
envio de opcoes
Browse files Browse the repository at this point in the history
  • Loading branch information
frkr committed Nov 5, 2023
1 parent e8475da commit f86a9ff
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 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.16",
"version": "18.0.17",
"description": "WhatsApp Business API Client unofficial",
"homepage": "https://ideias.casa/",
"repository": {
Expand Down
23 changes: 19 additions & 4 deletions src/WhatsApp.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ interface MessageObject {
identity?: any // TODO
image?: MediaMessage // TODO
interactive?: InteractiveMessage
location?: LocationMessage
order?: any // TODO
referral?: any // TODO
system?: any // TODO
Expand All @@ -87,23 +88,37 @@ interface MessageObject {

}

interface LocationMessage {
longitude?: string,
latitude?: string,
name?: string,
address?: string,
}

interface MessageEntity {
}

interface InteractiveMessage {
type: "list";
type: "list" | "button"
header?: VariableEntity;
body?: VariableEntity;
footer?: VariableEntity;
action?: ActionEntity;
}

interface ButtonEntity {
type: 'reply',
reply?: RowsEntity;
}

interface ActionEntity {
button: string;
sections: Array<SectionsEntity>;
buttons?: Array<ButtonEntity>;
button?: string;
sections?: Array<SectionsEntity>;
}

interface SectionsEntity {
title:string;
title: string;
rows: Array<RowsEntity>;
}

Expand Down
28 changes: 28 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,34 @@ export async function getMedia(apikey: string, url: string): Promise<Blob> {
)).blob();
}

export async function sendOptions(auth: WAAuth, waid: string, body: string, ...options: string[]): Promise<Response> {
let content: MessageObjectRequest = {
recipient_type: "individual",
messaging_product: "whatsapp",
to: waid,
type: "interactive",
interactive: {
type: "button",
body: {
text: body
},
action: {
buttons: options.map((item, index) => {
return {
type: 'reply',
reply: {
id: `${index}`,
title: item as string,
} as RowsEntity
} as ButtonEntity;
})
}
}
};

return defaultFetch(auth, content);
}

export async function sendMenu(auth: WAAuth, waid: string, menu: MenuRequest): Promise<Response> {
let msgInteractive: InteractiveMessage = {
type: 'list',
Expand Down

0 comments on commit f86a9ff

Please sign in to comment.