Save chat names for groups identification

This commit is contained in:
Judson Cairo 2024-08-10 23:15:20 -03:00
parent 668f477218
commit 926197b1ba
3 changed files with 7 additions and 5 deletions

View File

@ -114,6 +114,7 @@ model Session {
model Chat {
id String @id @default(cuid())
remoteJid String @db.VarChar(100)
name String? @db.VarChar(100)
labels Json? @db.Json
createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp
updatedAt DateTime? @updatedAt @db.Timestamp

View File

@ -114,6 +114,7 @@ model Session {
model Chat {
id String @id @default(cuid())
remoteJid String @db.VarChar(100)
name String? @db.VarChar(100)
labels Json? @db.JsonB
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime? @updatedAt @db.Timestamp

View File

@ -722,7 +722,7 @@ export class BaileysStartupService extends ChannelStartupService {
const chatsToInsert = chats
.filter((chat) => !existingChatIdSet.has(chat.id))
.map((chat) => ({ remoteJid: chat.id, instanceId: this.instanceId }));
.map((chat) => ({ remoteJid: chat.id, instanceId: this.instanceId, name: chat.name }));
this.sendDataWebhook(Events.CHATS_UPSERT, chatsToInsert);
@ -754,10 +754,9 @@ export class BaileysStartupService extends ChannelStartupService {
where: {
instanceId: this.instanceId,
remoteJid: chat.id,
name: chat.name,
},
data: {
remoteJid: chat.id,
},
data: { remoteJid: chat.id },
});
}
},
@ -900,7 +899,7 @@ export class BaileysStartupService extends ChannelStartupService {
}
}
const chatsRaw: any[] = [];
const chatsRaw: { remoteJid: string; instanceId: string; name?: string }[] = [];
const chatsRepository = new Set(
(
await this.prismaRepository.chat.findMany({
@ -917,6 +916,7 @@ export class BaileysStartupService extends ChannelStartupService {
chatsRaw.push({
remoteJid: chat.id,
instanceId: this.instanceId,
name: chat.name,
});
}