mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-26 10:28:38 -06:00
feature: add endpoint to retrieve chat data by phone number
This commit is contained in:
parent
1ca829c00b
commit
68e847d10e
@ -70,6 +70,10 @@ export class ChatController {
|
|||||||
return await this.waMonitor.waInstances[instanceName].fetchChats(query);
|
return await this.waMonitor.waInstances[instanceName].fetchChats(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async findChatByRemoteJid({ instanceName }: InstanceDto, remoteJid: string) {
|
||||||
|
return await this.waMonitor.waInstances[instanceName].findChatByRemoteJid(remoteJid);
|
||||||
|
}
|
||||||
|
|
||||||
public async sendPresence({ instanceName }: InstanceDto, data: SendPresenceDto) {
|
public async sendPresence({ instanceName }: InstanceDto, data: SendPresenceDto) {
|
||||||
return await this.waMonitor.waInstances[instanceName].sendPresence(data);
|
return await this.waMonitor.waInstances[instanceName].sendPresence(data);
|
||||||
}
|
}
|
||||||
|
@ -191,6 +191,16 @@ export class ChatRouter extends RouterBroker {
|
|||||||
|
|
||||||
return res.status(HttpStatus.OK).json(response);
|
return res.status(HttpStatus.OK).json(response);
|
||||||
})
|
})
|
||||||
|
.get(this.routerPath('findChatByRemoteJid'), ...guards, async (req, res) => {
|
||||||
|
const instance = req.params as unknown as InstanceDto;
|
||||||
|
const { remoteJid } = req.query as unknown as { remoteJid: string };
|
||||||
|
if (!remoteJid) {
|
||||||
|
return res.status(HttpStatus.BAD_REQUEST).json({ error: "remoteJid is a required query parameter" });
|
||||||
|
}
|
||||||
|
const response = await chatController.findChatByRemoteJid(instance, remoteJid);
|
||||||
|
|
||||||
|
return res.status(HttpStatus.OK).json(response);
|
||||||
|
})
|
||||||
// Profile routes
|
// Profile routes
|
||||||
.post(this.routerPath('fetchBusinessProfile'), ...guards, async (req, res) => {
|
.post(this.routerPath('fetchBusinessProfile'), ...guards, async (req, res) => {
|
||||||
const response = await this.dataValidate<ProfilePictureDto>({
|
const response = await this.dataValidate<ProfilePictureDto>({
|
||||||
|
@ -696,6 +696,16 @@ export class ChannelStartupService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async findChatByRemoteJid(remoteJid: string) {
|
||||||
|
if (!remoteJid) return null;
|
||||||
|
return await this.prismaRepository.chat.findFirst({
|
||||||
|
where: {
|
||||||
|
instanceId: this.instanceId,
|
||||||
|
remoteJid: remoteJid,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public async fetchChats(query: any) {
|
public async fetchChats(query: any) {
|
||||||
const remoteJid = query?.where?.remoteJid
|
const remoteJid = query?.where?.remoteJid
|
||||||
? query?.where?.remoteJid.includes('@')
|
? query?.where?.remoteJid.includes('@')
|
||||||
|
Loading…
Reference in New Issue
Block a user