Skip to content

Commit 68e847d

Browse files
committed
feature: add endpoint to retrieve chat data by phone number
1 parent 1ca829c commit 68e847d

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/api/controllers/chat.controller.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ export class ChatController {
7070
return await this.waMonitor.waInstances[instanceName].fetchChats(query);
7171
}
7272

73+
public async findChatByRemoteJid({ instanceName }: InstanceDto, remoteJid: string) {
74+
return await this.waMonitor.waInstances[instanceName].findChatByRemoteJid(remoteJid);
75+
}
76+
7377
public async sendPresence({ instanceName }: InstanceDto, data: SendPresenceDto) {
7478
return await this.waMonitor.waInstances[instanceName].sendPresence(data);
7579
}

src/api/routes/chat.router.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,16 @@ export class ChatRouter extends RouterBroker {
191191

192192
return res.status(HttpStatus.OK).json(response);
193193
})
194+
.get(this.routerPath('findChatByRemoteJid'), ...guards, async (req, res) => {
195+
const instance = req.params as unknown as InstanceDto;
196+
const { remoteJid } = req.query as unknown as { remoteJid: string };
197+
if (!remoteJid) {
198+
return res.status(HttpStatus.BAD_REQUEST).json({ error: "remoteJid is a required query parameter" });
199+
}
200+
const response = await chatController.findChatByRemoteJid(instance, remoteJid);
201+
202+
return res.status(HttpStatus.OK).json(response);
203+
})
194204
// Profile routes
195205
.post(this.routerPath('fetchBusinessProfile'), ...guards, async (req, res) => {
196206
const response = await this.dataValidate<ProfilePictureDto>({

src/api/services/channel.service.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,16 @@ export class ChannelStartupService {
696696
});
697697
}
698698

699+
public async findChatByRemoteJid(remoteJid: string) {
700+
if (!remoteJid) return null;
701+
return await this.prismaRepository.chat.findFirst({
702+
where: {
703+
instanceId: this.instanceId,
704+
remoteJid: remoteJid,
705+
},
706+
});
707+
}
708+
699709
public async fetchChats(query: any) {
700710
const remoteJid = query?.where?.remoteJid
701711
? query?.where?.remoteJid.includes('@')

0 commit comments

Comments
 (0)