Skip to content

Commit 8446be7

Browse files
committed
fix(chatwoot): fix grupos
1 parent 09911c4 commit 8446be7

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

src/api/integrations/chatwoot/services/chatwoot.service.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -564,25 +564,29 @@ export class ChatwootService {
564564
let contact = await this.findContact(instance, chatId);
565565

566566
if (contact) {
567-
const waProfilePictureFile = picture_url.profilePictureUrl.split('#')[0].split('?')[0].split('/').pop();
568-
const chatwootProfilePictureFile = contact?.thumbnail?.split('#')[0].split('?')[0].split('/').pop();
569-
const pictureNeedsUpdate = waProfilePictureFile !== chatwootProfilePictureFile;
570-
const nameNeedsUpdate =
571-
!contact.name ||
572-
contact.name === chatId ||
573-
(`+${chatId}`.startsWith('+55')
574-
? this.getNumbers(`+${chatId}`).some(
575-
(v) => contact.name === v || contact.name === v.substring(3) || contact.name === v.substring(1),
576-
)
577-
: false);
578-
579-
const contactNeedsUpdate = pictureNeedsUpdate || nameNeedsUpdate;
580-
if (contactNeedsUpdate) {
581-
this.logger.verbose('update contact in chatwoot');
582-
contact = await this.updateContact(instance, contact.id, {
583-
...(nameNeedsUpdate && { name: nameContact }),
584-
...(pictureNeedsUpdate && { avatar_url: picture_url.profilePictureUrl || null }),
585-
});
567+
if (!body.key.fromMe) {
568+
const waProfilePictureFile =
569+
picture_url?.profilePictureUrl?.split('#')[0].split('?')[0].split('/').pop() || '';
570+
const chatwootProfilePictureFile = contact?.thumbnail?.split('#')[0].split('?')[0].split('/').pop() || '';
571+
const pictureNeedsUpdate = waProfilePictureFile !== chatwootProfilePictureFile;
572+
const nameNeedsUpdate =
573+
!contact.name ||
574+
contact.name === chatId ||
575+
(`+${chatId}`.startsWith('+55')
576+
? this.getNumbers(`+${chatId}`).some(
577+
(v) => contact.name === v || contact.name === v.substring(3) || contact.name === v.substring(1),
578+
)
579+
: false);
580+
581+
const contactNeedsUpdate = pictureNeedsUpdate || nameNeedsUpdate;
582+
if (contactNeedsUpdate) {
583+
this.logger.verbose('update contact in chatwoot');
584+
contact = await this.updateContact(instance, contact.id, {
585+
...(nameNeedsUpdate && { name: nameContact }),
586+
...(waProfilePictureFile === '' && { avatar: null }),
587+
...(pictureNeedsUpdate && { avatar_url: picture_url?.profilePictureUrl }),
588+
});
589+
}
586590
}
587591
} else {
588592
const jid = isGroup ? null : body.key.remoteJid;

0 commit comments

Comments
 (0)