Skip to content

Commit 70f7c8c

Browse files
committed
feat: Save picture url groups in chatwoot
1 parent f33a6ab commit 70f7c8c

File tree

1 file changed

+44
-10
lines changed

1 file changed

+44
-10
lines changed

src/whatsapp/services/chatwoot.service.ts

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ export class ChatwootService {
258258
inboxId: number,
259259
isGroup: boolean,
260260
name?: string,
261+
avatar_url?: string,
261262
) {
262263
this.logger.verbose('create contact to instance: ' + instance.instanceName);
263264

@@ -275,13 +276,15 @@ export class ChatwootService {
275276
inbox_id: inboxId,
276277
name: name || phoneNumber,
277278
phone_number: `+${phoneNumber}`,
279+
avatar_url: avatar_url,
278280
};
279281
} else {
280282
this.logger.verbose('create contact group in chatwoot');
281283
data = {
282284
inbox_id: inboxId,
283285
name: name || phoneNumber,
284286
identifier: phoneNumber,
287+
avatar_url: avatar_url,
285288
};
286289
}
287290

@@ -404,27 +407,58 @@ export class ChatwootService {
404407
nameContact = `${group.subject} (GROUP)`;
405408

406409
this.logger.verbose('find or create participant in chatwoot');
407-
const participant =
408-
(await this.findContact(instance, body.key.participant.split('@')[0])) ||
409-
((await this.createContact(
410+
411+
const picture_url = await this.waMonitor.waInstances[
412+
instance.instanceName
413+
].profilePicture(body.key.participant.split('@')[0]);
414+
415+
const findParticipant = await this.findContact(
416+
instance,
417+
body.key.participant.split('@')[0],
418+
);
419+
420+
if (findParticipant) {
421+
await this.updateContact(instance, findParticipant.id, {
422+
name: nameContact,
423+
avatar_url: picture_url.profilePictureUrl || null,
424+
});
425+
} else {
426+
await this.createContact(
410427
instance,
411428
body.key.participant.split('@')[0],
412429
filterInbox.id,
413-
false,
414-
body.pushName || body.key.participant.split('@')[0],
415-
)) as any);
430+
isGroup,
431+
nameContact,
432+
picture_url.profilePictureUrl || null,
433+
);
434+
}
416435
}
417436

418437
this.logger.verbose('find or create contact in chatwoot');
419-
const contact =
420-
(await this.findContact(instance, chatId)) ||
421-
((await this.createContact(
438+
439+
const picture_url = await this.waMonitor.waInstances[
440+
instance.instanceName
441+
].profilePicture(chatId);
442+
443+
const findContact = await this.findContact(instance, chatId);
444+
445+
let contact: any;
446+
447+
if (findContact) {
448+
contact = await this.updateContact(instance, findContact.id, {
449+
name: nameContact,
450+
avatar_url: picture_url.profilePictureUrl || null,
451+
});
452+
} else {
453+
contact = await this.createContact(
422454
instance,
423455
chatId,
424456
filterInbox.id,
425457
isGroup,
426458
nameContact,
427-
)) as any);
459+
picture_url.profilePictureUrl || null,
460+
);
461+
}
428462

429463
if (!contact) {
430464
this.logger.warn('contact not found');

0 commit comments

Comments
 (0)