fix(chatwoot): fix grupos

This commit is contained in:
Deivison Lincoln 2024-05-08 16:47:21 -03:00
parent 09911c472d
commit 8446be7646

View File

@ -564,25 +564,29 @@ export class ChatwootService {
let contact = await this.findContact(instance, chatId); let contact = await this.findContact(instance, chatId);
if (contact) { if (contact) {
const waProfilePictureFile = picture_url.profilePictureUrl.split('#')[0].split('?')[0].split('/').pop(); if (!body.key.fromMe) {
const chatwootProfilePictureFile = contact?.thumbnail?.split('#')[0].split('?')[0].split('/').pop(); const waProfilePictureFile =
const pictureNeedsUpdate = waProfilePictureFile !== chatwootProfilePictureFile; picture_url?.profilePictureUrl?.split('#')[0].split('?')[0].split('/').pop() || '';
const nameNeedsUpdate = const chatwootProfilePictureFile = contact?.thumbnail?.split('#')[0].split('?')[0].split('/').pop() || '';
!contact.name || const pictureNeedsUpdate = waProfilePictureFile !== chatwootProfilePictureFile;
contact.name === chatId || const nameNeedsUpdate =
(`+${chatId}`.startsWith('+55') !contact.name ||
? this.getNumbers(`+${chatId}`).some( contact.name === chatId ||
(v) => contact.name === v || contact.name === v.substring(3) || contact.name === v.substring(1), (`+${chatId}`.startsWith('+55')
) ? this.getNumbers(`+${chatId}`).some(
: false); (v) => contact.name === v || contact.name === v.substring(3) || contact.name === v.substring(1),
)
: false);
const contactNeedsUpdate = pictureNeedsUpdate || nameNeedsUpdate; const contactNeedsUpdate = pictureNeedsUpdate || nameNeedsUpdate;
if (contactNeedsUpdate) { if (contactNeedsUpdate) {
this.logger.verbose('update contact in chatwoot'); this.logger.verbose('update contact in chatwoot');
contact = await this.updateContact(instance, contact.id, { contact = await this.updateContact(instance, contact.id, {
...(nameNeedsUpdate && { name: nameContact }), ...(nameNeedsUpdate && { name: nameContact }),
...(pictureNeedsUpdate && { avatar_url: picture_url.profilePictureUrl || null }), ...(waProfilePictureFile === '' && { avatar: null }),
}); ...(pictureNeedsUpdate && { avatar_url: picture_url?.profilePictureUrl }),
});
}
} }
} else { } else {
const jid = isGroup ? null : body.key.remoteJid; const jid = isGroup ? null : body.key.remoteJid;