diff --git a/src/api/dto/sendMessage.dto.ts b/src/api/dto/sendMessage.dto.ts index ba9ecf527..797ca111b 100644 --- a/src/api/dto/sendMessage.dto.ts +++ b/src/api/dto/sendMessage.dto.ts @@ -14,6 +14,7 @@ export class Options { mentionsEveryOne?: boolean; mentioned?: string[]; webhookUrl?: string; + messageId?: string; } export class MediaMessage { @@ -45,6 +46,7 @@ export class Metadata { mentioned?: string[]; encoding?: boolean; notConvertSticker?: boolean; + messageId?: string; } export class SendTextDto extends Metadata { diff --git a/src/api/integrations/channel/evolution/evolution.channel.service.ts b/src/api/integrations/channel/evolution/evolution.channel.service.ts index 87bea08e6..76a154fb1 100644 --- a/src/api/integrations/channel/evolution/evolution.channel.service.ts +++ b/src/api/integrations/channel/evolution/evolution.channel.service.ts @@ -318,7 +318,7 @@ export class EvolutionStartupService extends ChannelStartupService { let audioFile; - const messageId = v4(); + const messageId = options?.messageId ?? v4(); let messageRaw: any; @@ -548,6 +548,7 @@ export class EvolutionStartupService extends ChannelStartupService { linkPreview: data?.linkPreview, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, + messageId: data?.messageId, }, null, isIntegration, @@ -613,6 +614,7 @@ export class EvolutionStartupService extends ChannelStartupService { linkPreview: data?.linkPreview, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, + messageId: data?.messageId, }, file, isIntegration, @@ -711,6 +713,7 @@ export class EvolutionStartupService extends ChannelStartupService { linkPreview: data?.linkPreview, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, + messageId: data?.messageId, }, file, isIntegration, @@ -736,6 +739,7 @@ export class EvolutionStartupService extends ChannelStartupService { quoted: data?.quoted, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, + messageId: data?.messageId, }, null, isIntegration, diff --git a/src/api/integrations/channel/whatsapp/baileys.controller.ts b/src/api/integrations/channel/whatsapp/baileys.controller.ts index ee547338d..5a6e121dd 100644 --- a/src/api/integrations/channel/whatsapp/baileys.controller.ts +++ b/src/api/integrations/channel/whatsapp/baileys.controller.ts @@ -10,6 +10,12 @@ export class BaileysController { return instance.baileysOnWhatsapp(body?.jid); } + public async generateMessageID({ instanceName }: InstanceDto) { + const instance = this.waMonitor.waInstances[instanceName]; + + return instance.generateMessageID(); + } + public async profilePictureUrl({ instanceName }: InstanceDto, body: any) { const instance = this.waMonitor.waInstances[instanceName]; diff --git a/src/api/integrations/channel/whatsapp/baileys.router.ts b/src/api/integrations/channel/whatsapp/baileys.router.ts index 04a1d565f..354995e04 100644 --- a/src/api/integrations/channel/whatsapp/baileys.router.ts +++ b/src/api/integrations/channel/whatsapp/baileys.router.ts @@ -19,6 +19,16 @@ export class BaileysRouter extends RouterBroker { res.status(HttpStatus.OK).json(response); }) + .get(this.routerPath('generateMessageID'), ...guards, async (req, res) => { + const response = await this.dataValidate({ + request: req, + schema: instanceSchema, + ClassRef: InstanceDto, + execute: (instance) => baileysController.generateMessageID(instance), + }); + + res.status(HttpStatus.OK).json(response); + }) .post(this.routerPath('profilePictureUrl'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index c87342013..b2c291f01 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -103,6 +103,7 @@ import makeWASocket, { DisconnectReason, downloadContentFromMessage, downloadMediaMessage, + generateMessageIDV2, generateWAMessageFromContent, getAggregateVotesInPollMessage, GetCatalogOptions, @@ -1978,6 +1979,11 @@ export class BaileysStartupService extends ChannelStartupService { return error; } } + public generateMessageID() { + return { + id: generateMessageIDV2(this.client.user?.id), + }; + } private async sendMessage( sender: string, @@ -2242,7 +2248,7 @@ export class BaileysStartupService extends ChannelStartupService { mentions, linkPreview, quoted, - null, + options?.messageId ?? null, group?.ephemeralDuration, // group?.participants, ); @@ -2264,7 +2270,7 @@ export class BaileysStartupService extends ChannelStartupService { mentions, linkPreview, quoted, - null, + options?.messageId ?? null, undefined, contextInfo, ); @@ -2490,6 +2496,7 @@ export class BaileysStartupService extends ChannelStartupService { linkPreview: data?.linkPreview, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, + messageId: data?.messageId, }, isIntegration, ); @@ -2506,6 +2513,7 @@ export class BaileysStartupService extends ChannelStartupService { linkPreview: data?.linkPreview, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, + messageId: data?.messageId, }, ); } @@ -2819,6 +2827,7 @@ export class BaileysStartupService extends ChannelStartupService { quoted: data?.quoted, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, + messageId: data?.messageId, }, ); @@ -2841,6 +2850,7 @@ export class BaileysStartupService extends ChannelStartupService { quoted: data?.quoted, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, + messageId: data?.messageId, }, isIntegration, ); @@ -2857,6 +2867,7 @@ export class BaileysStartupService extends ChannelStartupService { quoted: data?.quoted, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, + messageId: data?.messageId, }; if (file) mediaData.media = file.buffer.toString('base64'); @@ -2872,6 +2883,7 @@ export class BaileysStartupService extends ChannelStartupService { quoted: data?.quoted, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, + messageId: data?.messageId, }, isIntegration, );