Skip to content

Commit e9c639a

Browse files
possebonclaude
andcommitted
feat(chat): add fetchLid endpoint for PN to LID resolution (EvolutionAPI#2483)
Adds POST /fetchLid endpoint that resolves a phone number (PN) to its Linked Identity Device (LID) using Baileys signalRepository. Upstream PR: EvolutionAPI#2483 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 668ba4a commit e9c639a

4 files changed

Lines changed: 40 additions & 0 deletions

File tree

src/api/controllers/chat.controller.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ export class ChatController {
5050
return await this.waMonitor.waInstances[instanceName].fetchProfile(instanceName, data.number);
5151
}
5252

53+
public async fetchLid({ instanceName }: InstanceDto, data: NumberDto) {
54+
return await this.waMonitor.waInstances[instanceName].getLid(data.number);
55+
}
56+
5357
public async fetchContacts({ instanceName }: InstanceDto, query: Query<Contact>) {
5458
return await this.waMonitor.waInstances[instanceName].fetchContacts(query);
5559
}

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,6 +2054,22 @@ export class BaileysStartupService extends ChannelStartupService {
20542054
}
20552055
}
20562056

2057+
public async getLid(number: string) {
2058+
const jid = createJid(number);
2059+
2060+
if (!this.client?.signalRepository) {
2061+
return { wuid: jid, lid: null };
2062+
}
2063+
2064+
try {
2065+
const lid = await this.client.signalRepository.lidMapping.getLIDForPN(jid);
2066+
return { wuid: jid, lid: lid || null };
2067+
} catch (error) {
2068+
console.error(`Failed to fetch LID for ${jid}:`, error);
2069+
return { wuid: jid, lid: null };
2070+
}
2071+
}
2072+
20572073
public async getStatus(number: string) {
20582074
const jid = createJid(number);
20592075

src/api/routes/chat.router.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
blockUserSchema,
2525
contactValidateSchema,
2626
deleteMessageSchema,
27+
fetchLidSchema,
2728
markChatUnreadSchema,
2829
messageUpSchema,
2930
messageValidateSchema,
@@ -222,6 +223,16 @@ export class ChatRouter extends RouterBroker {
222223

223224
return res.status(HttpStatus.OK).json(response);
224225
})
226+
.post(this.routerPath('fetchLid'), ...guards, async (req, res) => {
227+
const response = await this.dataValidate<NumberDto>({
228+
request: req,
229+
schema: fetchLidSchema,
230+
ClassRef: NumberDto,
231+
execute: (instance, data) => chatController.fetchLid(instance, data),
232+
});
233+
234+
return res.status(HttpStatus.OK).json(response);
235+
})
225236
.post(this.routerPath('updateProfileName'), ...guards, async (req, res) => {
226237
const response = await this.dataValidate<ProfileNameDto>({
227238
request: req,

src/validate/chat.schema.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,12 @@ export const profileSchema: JSONSchema7 = {
316316
isBusiness: { type: 'boolean' },
317317
},
318318
};
319+
320+
export const fetchLidSchema: JSONSchema7 = {
321+
$id: v4(),
322+
type: 'object',
323+
properties: {
324+
number: { type: 'string' },
325+
},
326+
required: ['number'],
327+
};

0 commit comments

Comments
 (0)