diff --git a/package.json b/package.json index 5f56f34..97c4e2a 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/WhatsApp.d.ts b/src/WhatsApp.d.ts index 16c814f..8530694 100644 --- a/src/WhatsApp.d.ts +++ b/src/WhatsApp.d.ts @@ -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 @@ -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; + buttons?: Array; + button?: string; + sections?: Array; } + interface SectionsEntity { - title:string; + title: string; rows: Array; } diff --git a/src/index.ts b/src/index.ts index 1e37eca..4acca4e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -151,6 +151,34 @@ export async function getMedia(apikey: string, url: string): Promise { )).blob(); } +export async function sendOptions(auth: WAAuth, waid: string, body: string, ...options: string[]): Promise { + 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 { let msgInteractive: InteractiveMessage = { type: 'list',