Skip to content

Commit 8272da8

Browse files
matheusmartinsInspermatheusmartinsInsper
authored andcommitted
Implement message update handling in BaileysStartupService
1 parent 6a30377 commit 8272da8

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

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

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,27 @@ export class BaileysStartupService extends ChannelStartupService {
920920
if (received.message?.protocolMessage?.editedMessage || received.message?.editedMessage?.message) {
921921
if (editedMessage) {
922922
await this.sendDataWebhook(Events.MESSAGES_EDITED, editedMessage);
923+
const oldMessage = await this.getMessage(editedMessage.key, true);
924+
if ((oldMessage as any)?.id) {
925+
await this.prismaRepository.message.update({
926+
where: { id: (oldMessage as any).id },
927+
data: {
928+
message: editedMessage.editedMessage as any,
929+
messageTimestamp: (editedMessage.timestampMs as Long.Long).toNumber(),
930+
status: 'EDITED',
931+
},
932+
});
933+
await this.prismaRepository.messageUpdate.create({
934+
data: {
935+
fromMe: editedMessage.key.fromMe,
936+
keyId: editedMessage.key.id,
937+
remoteJid: editedMessage.key.remoteJid,
938+
status: 'EDITED',
939+
instanceId: this.instanceId,
940+
messageId: (oldMessage as any).id,
941+
},
942+
});
943+
}
923944
}
924945
}
925946

@@ -3342,15 +3363,15 @@ export class BaileysStartupService extends ChannelStartupService {
33423363

33433364
try {
33443365
const oldMessage: any = await this.getMessage(data.key, true);
3345-
if (!oldMessage) throw new NotFoundException('Message not found');
3346-
if (oldMessage?.key?.remoteJid !== jid) {
3347-
throw new BadRequestException('RemoteJid does not match');
3348-
}
3349-
if (oldMessage?.messageTimestamp > Date.now() + 900000) {
3350-
// 15 minutes in milliseconds
3351-
throw new BadRequestException('Message is older than 15 minutes');
3352-
}
3353-
3366+
if (!oldMessage) throw new NotFoundException('Message not found');
3367+
if (oldMessage?.key?.remoteJid !== jid) {
3368+
throw new BadRequestException('RemoteJid does not match');
3369+
}
3370+
if (oldMessage?.messageTimestamp > Date.now() + 900000) {
3371+
// 15 minutes in milliseconds
3372+
throw new BadRequestException('Message is older than 15 minutes');
3373+
}
3374+
33543375
const response = await this.client.sendMessage(jid, {
33553376
...(options as any),
33563377
edit: data.key,

0 commit comments

Comments
 (0)