Skip to content

Commit 5613dd4

Browse files
committed
feat: add generateMessageID method and support for messageId in sendMessage DTO
1 parent 13f96a3 commit 5613dd4

File tree

5 files changed

+39
-3
lines changed

5 files changed

+39
-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: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ import makeWASocket, {
128128
WAMessageKey,
129129
WAPresence,
130130
WASocket,
131+
generateMessageIDV2
131132
} from 'baileys';
132133
import { Label } from 'baileys/lib/Types/Label';
133134
import { LabelAssociation } from 'baileys/lib/Types/LabelAssociation';
@@ -1979,6 +1980,13 @@ export class BaileysStartupService extends ChannelStartupService {
19791980
}
19801981
}
19811982

1983+
private async generateMessageID() {
1984+
1985+
return {
1986+
id: generateMessageIDV2(this.client.user?.id)
1987+
};
1988+
}
1989+
19821990
private async sendMessage(
19831991
sender: string,
19841992
message: any,
@@ -2242,7 +2250,7 @@ export class BaileysStartupService extends ChannelStartupService {
22422250
mentions,
22432251
linkPreview,
22442252
quoted,
2245-
null,
2253+
options.messageId,
22462254
group?.ephemeralDuration,
22472255
// group?.participants,
22482256
);
@@ -2264,7 +2272,7 @@ export class BaileysStartupService extends ChannelStartupService {
22642272
mentions,
22652273
linkPreview,
22662274
quoted,
2267-
null,
2275+
options.messageId,
22682276
undefined,
22692277
contextInfo,
22702278
);
@@ -2490,6 +2498,7 @@ export class BaileysStartupService extends ChannelStartupService {
24902498
linkPreview: data?.linkPreview,
24912499
mentionsEveryOne: data?.mentionsEveryOne,
24922500
mentioned: data?.mentioned,
2501+
messageId: data?.messageId,
24932502
},
24942503
isIntegration,
24952504
);
@@ -2506,6 +2515,7 @@ export class BaileysStartupService extends ChannelStartupService {
25062515
linkPreview: data?.linkPreview,
25072516
mentionsEveryOne: data?.mentionsEveryOne,
25082517
mentioned: data?.mentioned,
2518+
messageId: data?.messageId,
25092519
},
25102520
);
25112521
}
@@ -2819,6 +2829,7 @@ export class BaileysStartupService extends ChannelStartupService {
28192829
quoted: data?.quoted,
28202830
mentionsEveryOne: data?.mentionsEveryOne,
28212831
mentioned: data?.mentioned,
2832+
messageId: data?.messageId,
28222833
},
28232834
);
28242835

@@ -2841,6 +2852,7 @@ export class BaileysStartupService extends ChannelStartupService {
28412852
quoted: data?.quoted,
28422853
mentionsEveryOne: data?.mentionsEveryOne,
28432854
mentioned: data?.mentioned,
2855+
messageId: data?.messageId,
28442856
},
28452857
isIntegration,
28462858
);
@@ -2857,6 +2869,7 @@ export class BaileysStartupService extends ChannelStartupService {
28572869
quoted: data?.quoted,
28582870
mentionsEveryOne: data?.mentionsEveryOne,
28592871
mentioned: data?.mentioned,
2872+
messageId: data?.messageId,
28602873
};
28612874

28622875
if (file) mediaData.media = file.buffer.toString('base64');
@@ -2872,6 +2885,7 @@ export class BaileysStartupService extends ChannelStartupService {
28722885
quoted: data?.quoted,
28732886
mentionsEveryOne: data?.mentionsEveryOne,
28742887
mentioned: data?.mentioned,
2888+
messageId: data?.messageId,
28752889
},
28762890
isIntegration,
28772891
);

0 commit comments

Comments
 (0)