From 6003297bcf5dc9f22c96d57f3d769da35827c45d Mon Sep 17 00:00:00 2001 From: Lucas Batista Date: Thu, 5 Sep 2024 15:24:40 -0300 Subject: [PATCH] fix bailys naiming of contacts --- src/api/services/channels/whatsapp.baileys.service.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/api/services/channels/whatsapp.baileys.service.ts b/src/api/services/channels/whatsapp.baileys.service.ts index de4349c7..af6e097a 100644 --- a/src/api/services/channels/whatsapp.baileys.service.ts +++ b/src/api/services/channels/whatsapp.baileys.service.ts @@ -867,6 +867,7 @@ export class BaileysStartupService extends ChannelStartupService { 'contacts.update': async (contacts: Partial[], database: Database) => { this.logger.verbose('Event received: contacts.update'); + this.logger.info('THIS IS WHEN CONTACTS ARE UPDATED ON DATABASE' + JSON.stringify(contacts)) this.logger.verbose('Verifying if contacts exists in database to update'); const contactsRaw: ContactRaw[] = []; @@ -1024,10 +1025,10 @@ export class BaileysStartupService extends ChannelStartupService { await this.contactHandle['contacts.upsert']( contacts - .filter((c) => !!c.notify ?? !!c.name) + .filter((c) => !!c.name || !!c.verifiedName || !!c.notify) .map((c) => ({ id: c.id, - name: c.name ?? c.notify, + name: c.name || c.verifiedName || c.notify, })), database, ); @@ -1254,7 +1255,9 @@ export class BaileysStartupService extends ChannelStartupService { this.sendDataWebhook(Events.CONTACTS_UPSERT, contactRaw); this.logger.verbose('Inserting contact in database'); - this.repository.contact.insert([contactRaw], this.instance.name, database.SAVE_DATA.CONTACTS); + + if (received?.key?.fromMe === false) + this.repository.contact.insert([contactRaw], this.instance.name, database.SAVE_DATA.CONTACTS); } } catch (error) { this.logger.error(error);