From 8a234e107340e57fa8c000850882382b1cb8fb5d Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Mon, 8 Aug 2022 16:25:20 +0530 Subject: [PATCH] feat: implement product message sending --- src/Types/Message.ts | 40 ++++++++++++++++++++++++++-------------- src/Utils/messages.ts | 12 ++++++++++++ 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/Types/Message.ts b/src/Types/Message.ts index 17e843a..21f05e9 100644 --- a/src/Types/Message.ts +++ b/src/Types/Message.ts @@ -79,27 +79,29 @@ export type AnyMediaMessageContent = ( image: WAMediaUpload caption?: string jpegThumbnail?: string - } & Mentionable & Buttonable & Templatable & WithDimensions) | - ({ + } & Mentionable & Buttonable & Templatable & WithDimensions) + | ({ video: WAMediaUpload caption?: string gifPlayback?: boolean jpegThumbnail?: string - } & Mentionable & Buttonable & Templatable & WithDimensions) | { + } & Mentionable & Buttonable & Templatable & WithDimensions) + | { audio: WAMediaUpload /** if set to true, will send as a `voice note` */ ptt?: boolean /** optionally tell the duration of the audio */ seconds?: number - } | ({ + } + | ({ sticker: WAMediaUpload isAnimated?: boolean } & WithDimensions) | ({ document: WAMediaUpload mimetype: string fileName?: string - } & Buttonable & Templatable)) & - { mimetype?: string } + } & Buttonable & Templatable)) + | { mimetype?: string } export type ButtonReplyInfo = { displayText: string @@ -107,27 +109,37 @@ export type ButtonReplyInfo = { index: number } +export type WASendableProduct = Omit & { + productImage: WAMediaUpload +} + export type AnyRegularMessageContent = ( ({ text: string linkPreview?: WAUrlInfo | null } - & Mentionable & Buttonable & Templatable & Listable) | - AnyMediaMessageContent | - { + & Mentionable & Buttonable & Templatable & Listable) + | AnyMediaMessageContent + | { contacts: { displayName?: string contacts: proto.Message.IContactMessage[] } - } | - { + } + | { location: WALocationMessage - } | { - react: proto.Message.IReactionMessage - } | { + } + | { react: proto.Message.IReactionMessage } + | { buttonReply: ButtonReplyInfo type: 'template' | 'plain' } + | { + product: WASendableProduct, + businessOwnerJid?: string + body?: string + footer?: string + } ) & ViewOnce export type AnyMessageContent = AnyRegularMessageContent | { diff --git a/src/Utils/messages.ts b/src/Utils/messages.ts index 3840c2a..cb9e4fc 100644 --- a/src/Utils/messages.ts +++ b/src/Utils/messages.ts @@ -340,6 +340,18 @@ export const generateWAMessageContent = async( } break } + } else if('product' in message) { + const { imageMessage } = await prepareWAMessageMedia( + { image: message.product.productImage }, + options + ) + m.productMessage = WAProto.Message.ProductMessage.fromObject({ + ...message, + product: { + ...message.product, + productImage: imageMessage, + } + }) } else { m = await prepareWAMessageMedia( message,