From 5613dd4ec8893e4873fddc526062a3c59fa4e395 Mon Sep 17 00:00:00 2001 From: Jeferson Ramos Date: Wed, 14 Jan 2026 11:11:48 -0300 Subject: [PATCH 1/6] feat: add generateMessageID method and support for messageId in sendMessage DTO --- src/api/dto/sendMessage.dto.ts | 2 ++ .../evolution/evolution.channel.service.ts | 6 +++++- .../channel/whatsapp/baileys.controller.ts | 6 ++++++ .../channel/whatsapp/baileys.router.ts | 10 ++++++++++ .../whatsapp/whatsapp.baileys.service.ts | 18 ++++++++++++++++-- 5 files changed, 39 insertions(+), 3 deletions(-) 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..3d8e632e2 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..a5435bcc6 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -128,6 +128,7 @@ import makeWASocket, { WAMessageKey, WAPresence, WASocket, + generateMessageIDV2 } from 'baileys'; import { Label } from 'baileys/lib/Types/Label'; import { LabelAssociation } from 'baileys/lib/Types/LabelAssociation'; @@ -1979,6 +1980,13 @@ export class BaileysStartupService extends ChannelStartupService { } } + private async generateMessageID() { + + return { + id: generateMessageIDV2(this.client.user?.id) + }; + } + private async sendMessage( sender: string, message: any, @@ -2242,7 +2250,7 @@ export class BaileysStartupService extends ChannelStartupService { mentions, linkPreview, quoted, - null, + options.messageId, group?.ephemeralDuration, // group?.participants, ); @@ -2264,7 +2272,7 @@ export class BaileysStartupService extends ChannelStartupService { mentions, linkPreview, quoted, - null, + options.messageId, undefined, contextInfo, ); @@ -2490,6 +2498,7 @@ export class BaileysStartupService extends ChannelStartupService { linkPreview: data?.linkPreview, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, + messageId: data?.messageId, }, isIntegration, ); @@ -2506,6 +2515,7 @@ export class BaileysStartupService extends ChannelStartupService { linkPreview: data?.linkPreview, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, + messageId: data?.messageId, }, ); } @@ -2819,6 +2829,7 @@ export class BaileysStartupService extends ChannelStartupService { quoted: data?.quoted, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, + messageId: data?.messageId, }, ); @@ -2841,6 +2852,7 @@ export class BaileysStartupService extends ChannelStartupService { quoted: data?.quoted, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, + messageId: data?.messageId, }, isIntegration, ); @@ -2857,6 +2869,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 +2885,7 @@ export class BaileysStartupService extends ChannelStartupService { quoted: data?.quoted, mentionsEveryOne: data?.mentionsEveryOne, mentioned: data?.mentioned, + messageId: data?.messageId, }, isIntegration, ); From 04913a8a3e33f4973d74fead391af6e3f46376be Mon Sep 17 00:00:00 2001 From: Jeferson Ramos Date: Wed, 14 Jan 2026 11:35:01 -0300 Subject: [PATCH 2/6] Fix lint --- .../channel/whatsapp/whatsapp.baileys.service.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index a5435bcc6..5b5c1a51f 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, @@ -128,7 +129,6 @@ import makeWASocket, { WAMessageKey, WAPresence, WASocket, - generateMessageIDV2 } from 'baileys'; import { Label } from 'baileys/lib/Types/Label'; import { LabelAssociation } from 'baileys/lib/Types/LabelAssociation'; @@ -1981,9 +1981,8 @@ export class BaileysStartupService extends ChannelStartupService { } private async generateMessageID() { - return { - id: generateMessageIDV2(this.client.user?.id) + id: generateMessageIDV2(this.client.user?.id), }; } From ee83aaca3e53257a6cb31f56d205bbc4447e4347 Mon Sep 17 00:00:00 2001 From: Jeferson Ramos <36611481+JefersonRamos@users.noreply.github.com> Date: Wed, 14 Jan 2026 11:35:59 -0300 Subject: [PATCH 3/6] Update src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> --- .../channel/whatsapp/whatsapp.baileys.service.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index 5b5c1a51f..22b0f4694 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -1979,10 +1979,9 @@ export class BaileysStartupService extends ChannelStartupService { return error; } } - - private async generateMessageID() { + public generateMessageID() { return { - id: generateMessageIDV2(this.client.user?.id), + id: generateMessageIDV2(this.client.user?.id) }; } From 048f82590ca81de9689eaa96ad2865f69d1c9392 Mon Sep 17 00:00:00 2001 From: Jeferson Ramos <36611481+JefersonRamos@users.noreply.github.com> Date: Wed, 14 Jan 2026 11:36:20 -0300 Subject: [PATCH 4/6] Update src/api/integrations/channel/evolution/evolution.channel.service.ts Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> --- .../integrations/channel/evolution/evolution.channel.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/integrations/channel/evolution/evolution.channel.service.ts b/src/api/integrations/channel/evolution/evolution.channel.service.ts index 3d8e632e2..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 = options?.messageId || v4(); + const messageId = options?.messageId ?? v4(); let messageRaw: any; From e5fab3ef2b630804baefc9c161faf6612ccb8aed Mon Sep 17 00:00:00 2001 From: Jeferson Ramos <36611481+JefersonRamos@users.noreply.github.com> Date: Wed, 14 Jan 2026 13:14:03 -0300 Subject: [PATCH 5/6] Update whatsapp.baileys.service.ts --- .../integrations/channel/whatsapp/whatsapp.baileys.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index 22b0f4694..9a6763e16 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -2248,7 +2248,7 @@ export class BaileysStartupService extends ChannelStartupService { mentions, linkPreview, quoted, - options.messageId, + optionsoptions?.messageId ?? null, group?.ephemeralDuration, // group?.participants, ); @@ -2270,7 +2270,7 @@ export class BaileysStartupService extends ChannelStartupService { mentions, linkPreview, quoted, - options.messageId, + options?.messageId ?? null, undefined, contextInfo, ); From 13338df1bce328f9f02bc9906366dcd3f109cf03 Mon Sep 17 00:00:00 2001 From: Jeferson Ramos Date: Wed, 14 Jan 2026 13:47:14 -0300 Subject: [PATCH 6/6] fix: correct syntax in generateMessageID method --- .../integrations/channel/whatsapp/whatsapp.baileys.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index 9a6763e16..b2c291f01 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -1981,7 +1981,7 @@ export class BaileysStartupService extends ChannelStartupService { } public generateMessageID() { return { - id: generateMessageIDV2(this.client.user?.id) + id: generateMessageIDV2(this.client.user?.id), }; } @@ -2248,7 +2248,7 @@ export class BaileysStartupService extends ChannelStartupService { mentions, linkPreview, quoted, - optionsoptions?.messageId ?? null, + options?.messageId ?? null, group?.ephemeralDuration, // group?.participants, );