From 037cb9500e3f4121da58af934025a30258ea1065 Mon Sep 17 00:00:00 2001 From: DaviSM Date: Tue, 17 Oct 2023 21:50:47 -0300 Subject: [PATCH] menu teste 10 --- package.json | 7 +-- src/{WhatsApp.d.ts => WhatsApp.ts} | 78 ++++++++++++++++-------------- src/index.ts | 13 ++--- tsconfig.json | 3 -- 4 files changed, 49 insertions(+), 52 deletions(-) rename src/{WhatsApp.d.ts => WhatsApp.ts} (71%) diff --git a/package.json b/package.json index e1e4a98..c1e3ced 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "business-whatsapp", "author": "frkr", "license": "MIT", - "version": "18.0.09", + "version": "18.0.10", "description": "WhatsApp Business API Client unofficial", "homepage": "https://ideias.casa/", "repository": { @@ -11,10 +11,7 @@ }, "main": "./dist/index.js", "types": "./dist/index.d.ts", - "files": [ - "dist", - "src/WhatsApp.d.ts" - ], + "files": ["dist"], "keywords": [ "whatsapp", "business", diff --git a/src/WhatsApp.d.ts b/src/WhatsApp.ts similarity index 71% rename from src/WhatsApp.d.ts rename to src/WhatsApp.ts index c155e5e..317f897 100644 --- a/src/WhatsApp.d.ts +++ b/src/WhatsApp.ts @@ -1,19 +1,25 @@ -interface WhatsAppNotification { + +export class WAAuth { + accid: string; + apikey: string; +} + +export class WhatsAppNotification { object: "whatsapp_business_account"; entry: Array; } -interface EntryEntity { +export class EntryEntity { id: string; changes: Array; } -interface ValueObject { +export class ValueObject { value: ValueEntity; field: "messages"; } -interface ValueEntity { +export class ValueEntity { messaging_product: "whatsapp"; metadata: MetadataEntity; contacts?: Array; @@ -23,17 +29,17 @@ interface ValueEntity { statuses: any // TODO } -interface MetadataEntity { +export class MetadataEntity { display_phone_number: string; phone_number_id: string; } -interface ContactsEntity { +export class ContactsEntity { profile: ProfileEntity; wa_id: string; } -interface ProfileEntity { +export class ProfileEntity { name: string; } @@ -51,23 +57,7 @@ type MessageTypes = "button" | "system" | "unknown" | MessageTypesRequest type MediaTypes = "audio" | "document" | "image" | "sticker" | "video" -interface MessageObjectRequest extends MessageObject { - messaging_product: "whatsapp"; - recipient_type?: "individual" - to: string; - type: MessageTypesRequest; - //ttl?: number - template?: any // TODO - hsm?: any // TODO -} - -interface MessageObjectEvent extends MessageObject { - from: string; - id: string; - timestamp: string; -} - -interface MessageObject { +export class MessageObject { type: MessageTypes; audio?: MediaObject // TODO @@ -86,11 +76,27 @@ interface MessageObject { video?: MediaMessage; } +export class MessageObjectRequest extends MessageObject { + messaging_product: "whatsapp"; + recipient_type?: "individual" + to: string; + type: MessageTypesRequest=null; + //ttl?: number + template?: any // TODO + hsm?: any // TODO +} -interface MessageEntity { +export class MessageObjectEvent extends MessageObject { + from: string; + id: string; + timestamp: string; } -interface InteractiveMessage { + +export class MessageEntity { +} + +export class InteractiveMessage { type: "list"; header?: VariableEntity; body?: VariableEntity; @@ -98,39 +104,39 @@ interface InteractiveMessage { action?: ActionEntity; } -interface ActionEntity { +export class ActionEntity { button: string; sections: Array; } -interface SectionsEntity { +export class SectionsEntity { title:string; rows: Array; } -interface RowsEntity { +export class RowsEntity { id?: string; title?: string; description?: string; } -interface VariableEntity { +export class VariableEntity { type?: 'text'; text?: string; } -interface MenuRequest { +export class MenuRequest { titulo?: string; msg?: string; rodape?: string; itens: string[]; } -interface TextMessage extends MessageEntity { +export class TextMessage extends MessageEntity { preview_url?: boolean; body: string; } -interface MediaMessage extends MessageEntity { +export class MediaMessage extends MessageEntity { id?: string; link?: string; filename?: string; @@ -138,12 +144,12 @@ interface MediaMessage extends MessageEntity { } -interface MediaObject { - messaging_product: "whatsapp", +export class MediaObject { + messaging_product: "whatsapp"; url?: string mime_type?: string sha256?: string - file_size?: number, + file_size?: number; id?: string caption?: string } diff --git a/src/index.ts b/src/index.ts index c3fb00a..149b2b4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,4 @@ -export interface WAAuth { - accid: string; - apikey: string; -} +import {InteractiveMessage, MediaMessage, MediaObject, MenuRequest, MessageObjectRequest, RowsEntity, WAAuth } from "./WhatsApp"; export function onlyNumbers(waid: string): string { return waid.replace(/[^0-9]/g, ''); @@ -152,7 +149,7 @@ export async function getMedia(apikey: string, url: string): Promise { } export async function sendMenu(auth: WAAuth, waid: string, menu: MenuRequest): Promise { - let msgInteractive:any = { + let msgInteractive:InteractiveMessage = { type: "list", action: { button: 'Menu', @@ -169,18 +166,18 @@ export async function sendMenu(auth: WAAuth, waid: string, menu: MenuRequest): P } } if (menu.titulo) { - msgInteractive['header'] = { + msgInteractive.header = { type: "text", text: menu.titulo, } } if (menu.msg) { - msgInteractive['body'] = { + msgInteractive.body = { text: menu.msg, } } if (menu.rodape) { - msgInteractive['footer'] = { + msgInteractive.footer= { text: menu.rodape, } } diff --git a/tsconfig.json b/tsconfig.json index 17ae5f3..5bb38cc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,8 +5,5 @@ "outDir": "./dist", "declaration": true, "esModuleInterop": true, - "types": [ - "./src/WhatsApp.d.ts" - ] } }