Skip to content

Commit

Permalink
fix(chatwoot): fix grupos
Browse files Browse the repository at this point in the history
  • Loading branch information
deivisonrpg committed May 8, 2024
1 parent 09911c4 commit 8446be7
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions src/api/integrations/chatwoot/services/chatwoot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,25 +564,29 @@ export class ChatwootService {
let contact = await this.findContact(instance, chatId);

if (contact) {
const waProfilePictureFile = picture_url.profilePictureUrl.split('#')[0].split('?')[0].split('/').pop();
const chatwootProfilePictureFile = contact?.thumbnail?.split('#')[0].split('?')[0].split('/').pop();
const pictureNeedsUpdate = waProfilePictureFile !== chatwootProfilePictureFile;
const nameNeedsUpdate =
!contact.name ||
contact.name === chatId ||
(`+${chatId}`.startsWith('+55')
? this.getNumbers(`+${chatId}`).some(
(v) => contact.name === v || contact.name === v.substring(3) || contact.name === v.substring(1),
)
: false);

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

const contactNeedsUpdate = pictureNeedsUpdate || nameNeedsUpdate;
if (contactNeedsUpdate) {
this.logger.verbose('update contact in chatwoot');
contact = await this.updateContact(instance, contact.id, {
...(nameNeedsUpdate && { name: nameContact }),
...(waProfilePictureFile === '' && { avatar: null }),
...(pictureNeedsUpdate && { avatar_url: picture_url?.profilePictureUrl }),
});
}
}
} else {
const jid = isGroup ? null : body.key.remoteJid;
Expand Down

0 comments on commit 8446be7

Please sign in to comment.