Skip to content

Commit 17bd108

Browse files
committed
treating errors gracefully
1 parent f695e8b commit 17bd108

File tree

2 files changed

+53
-45
lines changed

2 files changed

+53
-45
lines changed

docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
services:
22
api:
33
container_name: evolution_api
4-
image: evoapicloud/evolution-api:latest
4+
build: .
55
restart: always
66
depends_on:
77
- redis

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

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3980,53 +3980,61 @@ export class BaileysStartupService extends ChannelStartupService {
39803980
edit: data.key,
39813981
});
39823982
if (messageSent) {
3983-
const messageId = messageSent.message?.protocolMessage?.key?.id;
3984-
if (messageId) {
3985-
let message = await this.prismaRepository.message.findFirst({
3986-
where: {
3987-
key: {
3988-
path: ['id'],
3989-
equals: messageId,
3990-
},
3991-
},
3992-
});
3993-
if (!message) throw new NotFoundException('Message not found');
3983+
const editedMessage = messageSent?.message?.protocolMessage || messageSent?.message?.editedMessage?.message?.protocolMessage;
39943984

3995-
if (!(message.key.valueOf() as any).fromMe) {
3996-
new BadRequestException('You cannot edit others messages');
3997-
}
3998-
if ((message.key.valueOf() as any)?.deleted) {
3999-
new BadRequestException('You cannot edit deleted messages');
4000-
}
4001-
if (oldMessage.messageType === 'conversation' || oldMessage.messageType === 'extendedTextMessage') {
4002-
oldMessage.message.conversation = data.text;
4003-
} else {
4004-
oldMessage.message[oldMessage.messageType].caption = data.text;
4005-
}
4006-
message = await this.prismaRepository.message.update({
4007-
where: { id: message.id },
4008-
data: {
4009-
message: oldMessage.message,
4010-
status: 'EDITED',
4011-
messageTimestamp: Math.floor(Date.now() / 1000), // Convert to int32 by dividing by 1000 to get seconds
4012-
},
4013-
});
4014-
const messageUpdate: any = {
4015-
messageId: message.id,
4016-
keyId: messageId,
4017-
remoteJid: messageSent.key.remoteJid,
4018-
fromMe: messageSent.key.fromMe,
4019-
participant: messageSent.key?.remoteJid,
4020-
status: 'EDITED',
4021-
instanceId: this.instanceId,
4022-
};
4023-
await this.prismaRepository.messageUpdate.create({
4024-
data: messageUpdate,
4025-
});
3985+
if (editedMessage) {
3986+
this.sendDataWebhook(Events.SEND_MESSAGE_UPDATE, editedMessage);
3987+
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled)
3988+
this.chatwootService.eventWhatsapp(
3989+
'send.message.update',
3990+
{ instanceName: this.instance.name, instanceId: this.instance.id },
3991+
editedMessage,
3992+
);
40263993

4027-
const editedMessage = messageSent?.message?.protocolMessage || messageSent?.message?.editedMessage?.message?.protocolMessage;
3994+
const messageId = messageSent.message?.protocolMessage?.key?.id;
3995+
if (messageId) {
3996+
let message = await this.prismaRepository.message.findFirst({
3997+
where: {
3998+
key: {
3999+
path: ['id'],
4000+
equals: messageId,
4001+
},
4002+
},
4003+
});
4004+
if (!message) throw new NotFoundException('Message not found');
40284005

4029-
this.sendDataWebhook(Events.SEND_MESSAGE_UPDATE, editedMessage);
4006+
if (!(message.key.valueOf() as any).fromMe) {
4007+
new BadRequestException('You cannot edit others messages');
4008+
}
4009+
if ((message.key.valueOf() as any)?.deleted) {
4010+
new BadRequestException('You cannot edit deleted messages');
4011+
}
4012+
if (oldMessage.messageType === 'conversation' || oldMessage.messageType === 'extendedTextMessage') {
4013+
oldMessage.message.conversation = data.text;
4014+
} else {
4015+
oldMessage.message[oldMessage.messageType].caption = data.text;
4016+
}
4017+
message = await this.prismaRepository.message.update({
4018+
where: { id: message.id },
4019+
data: {
4020+
message: oldMessage.message,
4021+
status: 'EDITED',
4022+
messageTimestamp: Math.floor(Date.now() / 1000), // Convert to int32 by dividing by 1000 to get seconds
4023+
},
4024+
});
4025+
const messageUpdate: any = {
4026+
messageId: message.id,
4027+
keyId: messageId,
4028+
remoteJid: messageSent.key.remoteJid,
4029+
fromMe: messageSent.key.fromMe,
4030+
participant: messageSent.key?.remoteJid,
4031+
status: 'EDITED',
4032+
instanceId: this.instanceId,
4033+
};
4034+
await this.prismaRepository.messageUpdate.create({
4035+
data: messageUpdate,
4036+
});
4037+
}
40304038
}
40314039
}
40324040

0 commit comments

Comments
 (0)