Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/api/controllers/chat.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Contact>) {
return await this.waMonitor.waInstances[instanceName].fetchContacts(query);
}
Expand Down
16 changes: 16 additions & 0 deletions src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2054,6 +2054,22 @@ 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 (error) {
console.error(`Failed to fetch LID for ${jid}:`, error);
return { wuid: jid, lid: null };
}
}

public async getStatus(number: string) {
const jid = createJid(number);

Expand Down
11 changes: 11 additions & 0 deletions src/api/routes/chat.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
blockUserSchema,
contactValidateSchema,
deleteMessageSchema,
fetchLidSchema,
markChatUnreadSchema,
messageUpSchema,
messageValidateSchema,
Expand Down Expand Up @@ -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<NumberDto>({
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<ProfileNameDto>({
request: req,
Expand Down
9 changes: 9 additions & 0 deletions src/validate/chat.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
};