Skip to content

Commit e22ff6c

Browse files
Merge pull request #1009 from yousseefspires/fix/chats-messages
fix: received messages but chat doesnt exists
2 parents 0fdc47e + 11d3112 commit e22ff6c

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/api/controllers/instance.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ export class InstanceController {
382382
return this.waMonitor.instanceInfoById(instanceId, number);
383383
}
384384

385-
return this.waMonitor.instanceInfo(instanceName);
385+
return this.waMonitor.instanceInfo([instanceName]);
386386
}
387387

388388
public async setPresence({ instanceName }: InstanceDto, data: SetPresenceDto) {

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,25 @@ export class BaileysStartupService extends ChannelStartupService {
10711071
if (settings?.groupsIgnore && received.key.remoteJid.includes('@g.us')) {
10721072
continue;
10731073
}
1074+
const existingChat = await this.prismaRepository.chat.findFirst({
1075+
where: { instanceId: this.instanceId, remoteJid: received.key.remoteJid },
1076+
});
1077+
1078+
if (!!existingChat) {
1079+
const chatToInsert = {
1080+
remoteJid: received.key.remoteJid,
1081+
instanceId: this.instanceId,
1082+
name: received.pushName || '',
1083+
unreadMessages: 0,
1084+
};
1085+
1086+
this.sendDataWebhook(Events.CHATS_UPSERT, [chatToInsert]);
1087+
if (this.configService.get<Database>('DATABASE').SAVE_DATA.CHATS) {
1088+
await this.prismaRepository.chat.create({
1089+
data: chatToInsert,
1090+
});
1091+
}
1092+
}
10741093

10751094
const messageRaw = this.prepareMessage(received);
10761095

@@ -1386,6 +1405,26 @@ export class BaileysStartupService extends ChannelStartupService {
13861405
await this.prismaRepository.messageUpdate.create({
13871406
data: message,
13881407
});
1408+
1409+
const existingChat = await this.prismaRepository.chat.findFirst({
1410+
where: { instanceId: this.instanceId, remoteJid: message.key.remoteJid },
1411+
});
1412+
1413+
if (!!existingChat) {
1414+
const chatToInsert = {
1415+
remoteJid: message.key.remoteJid,
1416+
instanceId: this.instanceId,
1417+
name: message.pushName || '',
1418+
unreadMessages: 0,
1419+
};
1420+
1421+
this.sendDataWebhook(Events.CHATS_UPSERT, [chatToInsert]);
1422+
if (this.configService.get<Database>('DATABASE').SAVE_DATA.CHATS) {
1423+
await this.prismaRepository.chat.create({
1424+
data: chatToInsert,
1425+
});
1426+
}
1427+
}
13891428
}
13901429
}
13911430

0 commit comments

Comments
 (0)