mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-15 19:52:54 -06:00
Merge pull request #1009 from yousseefspires/fix/chats-messages
fix: received messages but chat doesnt exists
This commit is contained in:
commit
e22ff6c0d9
@ -382,7 +382,7 @@ export class InstanceController {
|
||||
return this.waMonitor.instanceInfoById(instanceId, number);
|
||||
}
|
||||
|
||||
return this.waMonitor.instanceInfo(instanceName);
|
||||
return this.waMonitor.instanceInfo([instanceName]);
|
||||
}
|
||||
|
||||
public async setPresence({ instanceName }: InstanceDto, data: SetPresenceDto) {
|
||||
|
@ -1071,6 +1071,25 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
if (settings?.groupsIgnore && received.key.remoteJid.includes('@g.us')) {
|
||||
continue;
|
||||
}
|
||||
const existingChat = await this.prismaRepository.chat.findFirst({
|
||||
where: { instanceId: this.instanceId, remoteJid: received.key.remoteJid },
|
||||
});
|
||||
|
||||
if (!!existingChat) {
|
||||
const chatToInsert = {
|
||||
remoteJid: received.key.remoteJid,
|
||||
instanceId: this.instanceId,
|
||||
name: received.pushName || '',
|
||||
unreadMessages: 0,
|
||||
};
|
||||
|
||||
this.sendDataWebhook(Events.CHATS_UPSERT, [chatToInsert]);
|
||||
if (this.configService.get<Database>('DATABASE').SAVE_DATA.CHATS) {
|
||||
await this.prismaRepository.chat.create({
|
||||
data: chatToInsert,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const messageRaw = this.prepareMessage(received);
|
||||
|
||||
@ -1386,6 +1405,26 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
await this.prismaRepository.messageUpdate.create({
|
||||
data: message,
|
||||
});
|
||||
|
||||
const existingChat = await this.prismaRepository.chat.findFirst({
|
||||
where: { instanceId: this.instanceId, remoteJid: message.key.remoteJid },
|
||||
});
|
||||
|
||||
if (!!existingChat) {
|
||||
const chatToInsert = {
|
||||
remoteJid: message.key.remoteJid,
|
||||
instanceId: this.instanceId,
|
||||
name: message.pushName || '',
|
||||
unreadMessages: 0,
|
||||
};
|
||||
|
||||
this.sendDataWebhook(Events.CHATS_UPSERT, [chatToInsert]);
|
||||
if (this.configService.get<Database>('DATABASE').SAVE_DATA.CHATS) {
|
||||
await this.prismaRepository.chat.create({
|
||||
data: chatToInsert,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user