mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2026-03-21 20:18:40 -06:00
fix(whatsapp): enhance contact and chat handling with improved JID mapping and debug logging
This commit is contained in:
@@ -939,6 +939,14 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
progress?: number;
|
progress?: number;
|
||||||
syncType?: proto.HistorySync.HistorySyncType;
|
syncType?: proto.HistorySync.HistorySyncType;
|
||||||
}) => {
|
}) => {
|
||||||
|
//These logs are crucial; when something changes in Baileys/WhatsApp, we can more easily understand what changed!
|
||||||
|
this.logger.debug('Messages abaixo');
|
||||||
|
this.logger.debug(messages);
|
||||||
|
this.logger.debug('Chats abaixo');
|
||||||
|
this.logger.debug(chats);
|
||||||
|
this.logger.debug('Contatos abaixo');
|
||||||
|
this.logger.debug(contacts);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (syncType === proto.HistorySync.HistorySyncType.ON_DEMAND) {
|
if (syncType === proto.HistorySync.HistorySyncType.ON_DEMAND) {
|
||||||
console.log('received on-demand history sync, messages=', messages);
|
console.log('received on-demand history sync, messages=', messages);
|
||||||
@@ -967,14 +975,30 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const contactsMap = new Map();
|
const contactsMap = new Map();
|
||||||
|
const contactsMapLidJid = new Map();
|
||||||
|
|
||||||
for (const contact of contacts) {
|
for (const contact of contacts) {
|
||||||
if (contact.id && (contact.notify || contact.name)) {
|
|
||||||
contactsMap.set(contact.id, { name: contact.name ?? contact.notify, jid: contact.id });
|
let jid = null;
|
||||||
|
|
||||||
|
if (contact?.id?.search('@lid') !== -1) {
|
||||||
|
if (contact.phoneNumber) {
|
||||||
|
jid = contact.phoneNumber;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!jid) {
|
||||||
|
jid = contact?.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (contact.id && (contact.notify || contact.name)) {
|
||||||
|
contactsMap.set(contact.id, { name: contact.name ?? contact.notify, jid });
|
||||||
|
}
|
||||||
|
|
||||||
|
contactsMapLidJid.set(contact.id, { jid });
|
||||||
}
|
}
|
||||||
|
|
||||||
const chatsRaw: { remoteJid: string; instanceId: string; name?: string }[] = [];
|
const chatsRaw: { remoteJid: string; remoteLid: string; instanceId: string; name?: string }[] = [];
|
||||||
const chatsRepository = new Set(
|
const chatsRepository = new Set(
|
||||||
(await this.prismaRepository.chat.findMany({ where: { instanceId: this.instanceId } })).map(
|
(await this.prismaRepository.chat.findMany({ where: { instanceId: this.instanceId } })).map(
|
||||||
(chat) => chat.remoteJid,
|
(chat) => chat.remoteJid,
|
||||||
@@ -986,7 +1010,24 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
chatsRaw.push({ remoteJid: chat.id, instanceId: this.instanceId, name: chat.name });
|
let remoteJid = null;
|
||||||
|
let remoteLid = null;
|
||||||
|
|
||||||
|
if (chat.id.search('@lid') !== -1) {
|
||||||
|
const contact = contactsMapLidJid.get(chat.id);
|
||||||
|
|
||||||
|
remoteLid = chat.id;
|
||||||
|
|
||||||
|
if (contact && contact.jid) {
|
||||||
|
remoteJid = contact.jid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!remoteJid) {
|
||||||
|
remoteJid = chat.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
chatsRaw.push({ remoteJid, remoteLid, instanceId: this.instanceId, name: chat.name });
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sendDataWebhook(Events.CHATS_SET, chatsRaw);
|
this.sendDataWebhook(Events.CHATS_SET, chatsRaw);
|
||||||
|
|||||||
Reference in New Issue
Block a user