mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-14 01:41:24 -06:00
Merge pull request #746 from judsonjuniorr/v2-save-chat-name
V2 save chat name
This commit is contained in:
commit
367d44a4d3
@ -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
|
||||
|
@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Chat" ADD COLUMN "name" VARCHAR(100);
|
@ -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
|
||||
|
@ -1267,6 +1267,7 @@ export class ChannelStartupService {
|
||||
SELECT
|
||||
"Chat"."id",
|
||||
"Chat"."remoteJid",
|
||||
"Chat"."name",
|
||||
"Chat"."labels",
|
||||
"Chat"."createdAt",
|
||||
"Chat"."updatedAt",
|
||||
@ -1283,6 +1284,7 @@ export class ChannelStartupService {
|
||||
SELECT
|
||||
"Chat"."id",
|
||||
"Chat"."remoteJid",
|
||||
"Chat"."name",
|
||||
"Chat"."labels",
|
||||
"Chat"."createdAt",
|
||||
"Chat"."updatedAt",
|
||||
|
@ -227,11 +227,16 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
|
||||
this.client?.ws?.close();
|
||||
|
||||
await this.prismaRepository.session.delete({
|
||||
where: {
|
||||
sessionId: this.instanceId,
|
||||
},
|
||||
const sessionExists = await this.prismaRepository.session.findFirst({
|
||||
where: { sessionId: this.instanceId },
|
||||
});
|
||||
if (sessionExists) {
|
||||
await this.prismaRepository.session.delete({
|
||||
where: {
|
||||
sessionId: this.instanceId,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public async getProfileName() {
|
||||
@ -717,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);
|
||||
|
||||
@ -749,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 },
|
||||
});
|
||||
}
|
||||
},
|
||||
@ -895,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({
|
||||
@ -912,18 +916,17 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
chatsRaw.push({
|
||||
remoteJid: chat.id,
|
||||
instanceId: this.instanceId,
|
||||
name: chat.name,
|
||||
});
|
||||
}
|
||||
|
||||
this.sendDataWebhook(Events.CHATS_SET, chatsRaw);
|
||||
|
||||
if (this.configService.get<Database>('DATABASE').SAVE_DATA.HISTORIC) {
|
||||
const chatsSaved = await this.prismaRepository.chat.createMany({
|
||||
await this.prismaRepository.chat.createMany({
|
||||
data: chatsRaw,
|
||||
skipDuplicates: true,
|
||||
});
|
||||
|
||||
console.log('chatsSaved', chatsSaved);
|
||||
}
|
||||
|
||||
const messagesRaw: any[] = [];
|
||||
@ -982,12 +985,10 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
this.sendDataWebhook(Events.MESSAGES_SET, [...messagesRaw]);
|
||||
|
||||
if (this.configService.get<Database>('DATABASE').SAVE_DATA.HISTORIC) {
|
||||
const messagesSaved = await this.prismaRepository.message.createMany({
|
||||
await this.prismaRepository.message.createMany({
|
||||
data: messagesRaw,
|
||||
skipDuplicates: true,
|
||||
});
|
||||
|
||||
console.log('messagesSaved', messagesSaved);
|
||||
}
|
||||
|
||||
if (
|
||||
|
@ -300,7 +300,6 @@ export class BusinessStartupService extends ChannelStartupService {
|
||||
|
||||
protected async messageHandle(received: any, database: Database, settings: any) {
|
||||
try {
|
||||
console.log(received);
|
||||
let messageRaw: any;
|
||||
let pushName: any;
|
||||
|
||||
@ -983,7 +982,6 @@ export class BusinessStartupService extends ChannelStartupService {
|
||||
|
||||
return messageRaw;
|
||||
} catch (error) {
|
||||
console.log(error.response.data);
|
||||
this.logger.error(error);
|
||||
throw new BadRequestException(error.toString());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user