From 2a2f49f13999014e95de2c49f74dc1587fe94690 Mon Sep 17 00:00:00 2001 From: shennawy Date: Mon, 23 Mar 2026 07:12:35 +0300 Subject: [PATCH 1/2] feat(chat): add fetchLid endpoint for PN to LID resolution --- src/api/controllers/chat.controller.ts | 4 ++++ .../channel/whatsapp/whatsapp.baileys.service.ts | 15 +++++++++++++++ src/api/routes/chat.router.ts | 11 +++++++++++ src/validate/chat.schema.ts | 9 +++++++++ 4 files changed, 39 insertions(+) diff --git a/src/api/controllers/chat.controller.ts b/src/api/controllers/chat.controller.ts index 22e90b9fa..6da0bf81f 100644 --- a/src/api/controllers/chat.controller.ts +++ b/src/api/controllers/chat.controller.ts @@ -50,6 +50,10 @@ export class ChatController { return await this.waMonitor.waInstances[instanceName].fetchProfile(instanceName, data.number); } + public async fetchLid({ instanceName }: InstanceDto, data: NumberDto) { + return await this.waMonitor.waInstances[instanceName].getLid(data.number); + } + public async fetchContacts({ instanceName }: InstanceDto, query: Query) { return await this.waMonitor.waInstances[instanceName].fetchContacts(query); } diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index 60e857fcc..d1ef7bd31 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -2054,6 +2054,21 @@ export class BaileysStartupService extends ChannelStartupService { } } + public async getLid(number: string) { + const jid = createJid(number); + + if (!this.client?.signalRepository) { + return { wuid: jid, lid: null }; + } + + try { + const lid = await this.client.signalRepository.lidMapping.getLIDForPN(jid); + return { wuid: jid, lid: lid || null }; + } catch { + return { wuid: jid, lid: null }; + } + } + public async getStatus(number: string) { const jid = createJid(number); diff --git a/src/api/routes/chat.router.ts b/src/api/routes/chat.router.ts index 158947ed2..5042ccfd0 100644 --- a/src/api/routes/chat.router.ts +++ b/src/api/routes/chat.router.ts @@ -24,6 +24,7 @@ import { blockUserSchema, contactValidateSchema, deleteMessageSchema, + fetchLidSchema, markChatUnreadSchema, messageUpSchema, messageValidateSchema, @@ -222,6 +223,16 @@ export class ChatRouter extends RouterBroker { return res.status(HttpStatus.OK).json(response); }) + .post(this.routerPath('fetchLid'), ...guards, async (req, res) => { + const response = await this.dataValidate({ + request: req, + schema: fetchLidSchema, + ClassRef: NumberDto, + execute: (instance, data) => chatController.fetchLid(instance, data), + }); + + return res.status(HttpStatus.OK).json(response); + }) .post(this.routerPath('updateProfileName'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, diff --git a/src/validate/chat.schema.ts b/src/validate/chat.schema.ts index 7dae44539..6b3b9506e 100644 --- a/src/validate/chat.schema.ts +++ b/src/validate/chat.schema.ts @@ -316,3 +316,12 @@ export const profileSchema: JSONSchema7 = { isBusiness: { type: 'boolean' }, }, }; + +export const fetchLidSchema: JSONSchema7 = { + $id: v4(), + type: 'object', + properties: { + number: { type: 'string' }, + }, + required: ['number'], +}; From e76dfa4d33c5f6ee86406289dad6ad5e235b0b62 Mon Sep 17 00:00:00 2001 From: shennawy Date: Mon, 23 Mar 2026 07:36:22 +0300 Subject: [PATCH 2/2] fix(pr-feedback): log error when failing to fetch LID for WUID --- .../integrations/channel/whatsapp/whatsapp.baileys.service.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index d1ef7bd31..8f44a12c3 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -2064,7 +2064,8 @@ export class BaileysStartupService extends ChannelStartupService { try { const lid = await this.client.signalRepository.lidMapping.getLIDForPN(jid); return { wuid: jid, lid: lid || null }; - } catch { + } catch (error) { + console.error(`Failed to fetch LID for ${jid}:`, error); return { wuid: jid, lid: null }; } }