Skip to content

Commit 550d35a

Browse files
Merge pull request #2361 from JefersonRamos/feat/send-message-with-key-id
feat: add generateMessageID method and support for messageId in sendM…
2 parents c74ba9f + 13338df commit 550d35a

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed

src/api/dto/sendMessage.dto.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export class Options {
1414
mentionsEveryOne?: boolean;
1515
mentioned?: string[];
1616
webhookUrl?: string;
17+
messageId?: string;
1718
}
1819

1920
export class MediaMessage {
@@ -45,6 +46,7 @@ export class Metadata {
4546
mentioned?: string[];
4647
encoding?: boolean;
4748
notConvertSticker?: boolean;
49+
messageId?: string;
4850
}
4951

5052
export class SendTextDto extends Metadata {

src/api/integrations/channel/evolution/evolution.channel.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ export class EvolutionStartupService extends ChannelStartupService {
318318

319319
let audioFile;
320320

321-
const messageId = v4();
321+
const messageId = options?.messageId ?? v4();
322322

323323
let messageRaw: any;
324324

@@ -548,6 +548,7 @@ export class EvolutionStartupService extends ChannelStartupService {
548548
linkPreview: data?.linkPreview,
549549
mentionsEveryOne: data?.mentionsEveryOne,
550550
mentioned: data?.mentioned,
551+
messageId: data?.messageId,
551552
},
552553
null,
553554
isIntegration,
@@ -613,6 +614,7 @@ export class EvolutionStartupService extends ChannelStartupService {
613614
linkPreview: data?.linkPreview,
614615
mentionsEveryOne: data?.mentionsEveryOne,
615616
mentioned: data?.mentioned,
617+
messageId: data?.messageId,
616618
},
617619
file,
618620
isIntegration,
@@ -711,6 +713,7 @@ export class EvolutionStartupService extends ChannelStartupService {
711713
linkPreview: data?.linkPreview,
712714
mentionsEveryOne: data?.mentionsEveryOne,
713715
mentioned: data?.mentioned,
716+
messageId: data?.messageId,
714717
},
715718
file,
716719
isIntegration,
@@ -736,6 +739,7 @@ export class EvolutionStartupService extends ChannelStartupService {
736739
quoted: data?.quoted,
737740
mentionsEveryOne: data?.mentionsEveryOne,
738741
mentioned: data?.mentioned,
742+
messageId: data?.messageId,
739743
},
740744
null,
741745
isIntegration,

src/api/integrations/channel/whatsapp/baileys.controller.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ export class BaileysController {
1010
return instance.baileysOnWhatsapp(body?.jid);
1111
}
1212

13+
public async generateMessageID({ instanceName }: InstanceDto) {
14+
const instance = this.waMonitor.waInstances[instanceName];
15+
16+
return instance.generateMessageID();
17+
}
18+
1319
public async profilePictureUrl({ instanceName }: InstanceDto, body: any) {
1420
const instance = this.waMonitor.waInstances[instanceName];
1521

src/api/integrations/channel/whatsapp/baileys.router.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ export class BaileysRouter extends RouterBroker {
1919

2020
res.status(HttpStatus.OK).json(response);
2121
})
22+
.get(this.routerPath('generateMessageID'), ...guards, async (req, res) => {
23+
const response = await this.dataValidate<InstanceDto>({
24+
request: req,
25+
schema: instanceSchema,
26+
ClassRef: InstanceDto,
27+
execute: (instance) => baileysController.generateMessageID(instance),
28+
});
29+
30+
res.status(HttpStatus.OK).json(response);
31+
})
2232
.post(this.routerPath('profilePictureUrl'), ...guards, async (req, res) => {
2333
const response = await this.dataValidate<InstanceDto>({
2434
request: req,

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ import makeWASocket, {
104104
DisconnectReason,
105105
downloadContentFromMessage,
106106
downloadMediaMessage,
107+
generateMessageIDV2,
107108
generateWAMessageFromContent,
108109
getAggregateVotesInPollMessage,
109110
GetCatalogOptions,
@@ -2225,6 +2226,11 @@ export class BaileysStartupService extends ChannelStartupService {
22252226
return error;
22262227
}
22272228
}
2229+
public generateMessageID() {
2230+
return {
2231+
id: generateMessageIDV2(this.client.user?.id),
2232+
};
2233+
}
22282234

22292235
private async generateLinkPreview(text: string) {
22302236
try {
@@ -2534,7 +2540,7 @@ export class BaileysStartupService extends ChannelStartupService {
25342540
mentions,
25352541
linkPreview,
25362542
quoted,
2537-
null,
2543+
options?.messageId ?? null,
25382544
group?.ephemeralDuration,
25392545
previewContext,
25402546
// group?.participants,
@@ -2558,7 +2564,7 @@ export class BaileysStartupService extends ChannelStartupService {
25582564
mentions,
25592565
linkPreview,
25602566
quoted,
2561-
null,
2567+
options?.messageId ?? null,
25622568
undefined,
25632569
contextInfo,
25642570
);
@@ -2790,6 +2796,7 @@ export class BaileysStartupService extends ChannelStartupService {
27902796
linkPreview: data?.linkPreview,
27912797
mentionsEveryOne: data?.mentionsEveryOne,
27922798
mentioned: data?.mentioned,
2799+
messageId: data?.messageId,
27932800
},
27942801
isIntegration,
27952802
);
@@ -2806,6 +2813,7 @@ export class BaileysStartupService extends ChannelStartupService {
28062813
linkPreview: data?.linkPreview,
28072814
mentionsEveryOne: data?.mentionsEveryOne,
28082815
mentioned: data?.mentioned,
2816+
messageId: data?.messageId,
28092817
},
28102818
);
28112819
}
@@ -3119,6 +3127,7 @@ export class BaileysStartupService extends ChannelStartupService {
31193127
quoted: data?.quoted,
31203128
mentionsEveryOne: data?.mentionsEveryOne,
31213129
mentioned: data?.mentioned,
3130+
messageId: data?.messageId,
31223131
},
31233132
);
31243133

@@ -3141,6 +3150,7 @@ export class BaileysStartupService extends ChannelStartupService {
31413150
quoted: data?.quoted,
31423151
mentionsEveryOne: data?.mentionsEveryOne,
31433152
mentioned: data?.mentioned,
3153+
messageId: data?.messageId,
31443154
},
31453155
isIntegration,
31463156
);
@@ -3157,6 +3167,7 @@ export class BaileysStartupService extends ChannelStartupService {
31573167
quoted: data?.quoted,
31583168
mentionsEveryOne: data?.mentionsEveryOne,
31593169
mentioned: data?.mentioned,
3170+
messageId: data?.messageId,
31603171
};
31613172

31623173
if (file) mediaData.media = file.buffer.toString('base64');
@@ -3172,6 +3183,7 @@ export class BaileysStartupService extends ChannelStartupService {
31723183
quoted: data?.quoted,
31733184
mentionsEveryOne: data?.mentionsEveryOne,
31743185
mentioned: data?.mentioned,
3186+
messageId: data?.messageId,
31753187
},
31763188
isIntegration,
31773189
);

0 commit comments

Comments
 (0)