diff --git a/src/index.ts b/src/index.ts index e274c79c..40d6d433 100644 --- a/src/index.ts +++ b/src/index.ts @@ -218,10 +218,7 @@ export class WhatsAppAPI { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - TS dumb, the _type will always match the type - request[type] = - // Prettier will probably kill me, but this comment has a purpose. - // It prevents ts-ignore from ignoring more than intended. - message._build(); + request[type] = message; if (context) request.context = { message_id: context }; if (biz_opaque_callback_data) diff --git a/src/messages/contacts.ts b/src/messages/contacts.ts index d8a42e4c..6d4e864b 100644 --- a/src/messages/contacts.ts +++ b/src/messages/contacts.ts @@ -123,10 +123,9 @@ export class Contacts extends ClientMessage { } /** - * @override * @internal */ - _build(): string { + toJSON() { return JSON.stringify(this.component); } } diff --git a/src/types.ts b/src/types.ts index 938baecb..1505e21b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -7,6 +7,19 @@ * feel free to read the docs :) */ +import type { + Text, + Audio, + Document, + Image, + Sticker, + Video, + Location, + Interactive, + Template, + Reaction, + Contacts +} from "./messages"; import type { AtLeastOne } from "./utils"; export const DEFAULT_API_VERSION = "v20.0"; @@ -149,14 +162,6 @@ export abstract class ClientMessage { * @internal */ abstract get _type(): ClientMessageNames; - /** - * The message built as a string. In most cases it's just JSON.stringify(this) - * - * @internal - */ - _build(): string { - return JSON.stringify(this); - } } export interface ClientTypedMessageComponent { @@ -381,47 +386,47 @@ export type ClientMessageRequest = { } & ( | { type: "text"; - text?: string; + text?: Text; } | { type: "audio"; - audio?: string; + audio?: Audio; } | { type: "document"; - document?: string; + document?: Document; } | { type: "image"; - image?: string; + image?: Image; } | { type: "sticker"; - sticker?: string; + sticker?: Sticker; } | { type: "video"; - video?: string; + video?: Video; } | { type: "location"; - location?: string; + location?: Location; } | { type: "contacts"; - contacts?: string; + contacts?: Contacts; } | { type: "interactive"; - interactive?: string; + interactive?: Interactive; } | { type: "template"; - template?: string; + template?: Template; } | { type: "reaction"; - reaction?: string; + reaction?: Reaction; } ); diff --git a/test/index.test.js b/test/index.test.js index 31cd4bda..e1f82cf7 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -227,7 +227,7 @@ describe("WhatsAppAPI", () => { messaging_product: "whatsapp", type, to: user, - text: JSON.stringify(message) + text: message }; const id = "4"; @@ -405,7 +405,7 @@ describe("WhatsAppAPI", () => { messaging_product: "whatsapp", type, to: user, - text: JSON.stringify(message) + text: message }; const requestWithContext = {