Skip to content

Commit 2a2f49f

Browse files
committed
feat(chat): add fetchLid endpoint for PN to LID resolution
1 parent cd800f2 commit 2a2f49f

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,6 +2054,21 @@ 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 {
2068+
return { wuid: jid, lid: null };
2069+
}
2070+
}
2071+
20572072
public async getStatus(number: string) {
20582073
const jid = createJid(number);
20592074

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)