Skip to content

Commit

Permalink
menu teste 10
Browse files Browse the repository at this point in the history
  • Loading branch information
frkr committed Oct 18, 2023
1 parent 6185769 commit 037cb95
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 52 deletions.
7 changes: 2 additions & 5 deletions 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.09",
"version": "18.0.10",
"description": "WhatsApp Business API Client unofficial",
"homepage": "https://ideias.casa/",
"repository": {
Expand All @@ -11,10 +11,7 @@
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist",
"src/WhatsApp.d.ts"
],
"files": ["dist"],
"keywords": [
"whatsapp",
"business",
Expand Down
78 changes: 42 additions & 36 deletions src/WhatsApp.d.ts → src/WhatsApp.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
interface WhatsAppNotification {

export class WAAuth {
accid: string;
apikey: string;
}

export class WhatsAppNotification {
object: "whatsapp_business_account";
entry: Array<EntryEntity>;
}

interface EntryEntity {
export class EntryEntity {
id: string;
changes: Array<ValueObject>;
}

interface ValueObject {
export class ValueObject {
value: ValueEntity;
field: "messages";
}

interface ValueEntity {
export class ValueEntity {
messaging_product: "whatsapp";
metadata: MetadataEntity;
contacts?: Array<ContactsEntity>;
Expand All @@ -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;
}

Expand All @@ -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
Expand All @@ -86,64 +76,80 @@ 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;
footer?: VariableEntity;
action?: ActionEntity;
}

interface ActionEntity {
export class ActionEntity {
button: string;
sections: Array<SectionsEntity>;
}
interface SectionsEntity {
export class SectionsEntity {
title:string;
rows: Array<RowsEntity>;
}

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;
provider?: string;

}

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
}
13 changes: 5 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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, '');
Expand Down Expand Up @@ -152,7 +149,7 @@ export async function getMedia(apikey: string, url: string): Promise<Blob> {
}

export async function sendMenu(auth: WAAuth, waid: string, menu: MenuRequest): Promise<Response> {
let msgInteractive:any = {
let msgInteractive:InteractiveMessage = {
type: "list",
action: {
button: 'Menu',
Expand All @@ -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,
}
}
Expand Down
3 changes: 0 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@
"outDir": "./dist",
"declaration": true,
"esModuleInterop": true,
"types": [
"./src/WhatsApp.d.ts"
]
}
}

0 comments on commit 037cb95

Please sign in to comment.