mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-26 10:28:38 -06:00
Suggests another Typebot fetchSessions solution instead of upsert
This commit is contained in:
parent
586b703872
commit
78abb796e5
@ -633,18 +633,8 @@ export class TypebotController extends ChatbotController implements ChatbotContr
|
||||
});
|
||||
|
||||
if (!findBot) {
|
||||
findBot = await this.botRepository.upsert({
|
||||
where: {
|
||||
url_typebot_instanceId: {
|
||||
url: url,
|
||||
typebot: typebot,
|
||||
instanceId: instanceData.id,
|
||||
},
|
||||
},
|
||||
update: {
|
||||
enabled: true,
|
||||
},
|
||||
create: {
|
||||
findBot = await this.botRepository.create({
|
||||
data: {
|
||||
enabled: true,
|
||||
url: url,
|
||||
typebot: typebot,
|
||||
@ -657,7 +647,12 @@ export class TypebotController extends ChatbotController implements ChatbotContr
|
||||
stopBotFromMe: stopBotFromMe,
|
||||
keepOpen: keepOpen,
|
||||
instanceId: instanceData.id,
|
||||
},
|
||||
}
|
||||
});
|
||||
} else {
|
||||
findBot = await this.botRepository.update({
|
||||
where: { id: findBot.id },
|
||||
data: { enabled: true }
|
||||
});
|
||||
}
|
||||
|
||||
@ -682,7 +677,7 @@ export class TypebotController extends ChatbotController implements ChatbotContr
|
||||
stopBotFromMe: stopBotFromMe,
|
||||
keepOpen: keepOpen,
|
||||
prefilledVariables: prefilledVariables,
|
||||
typebotId: findBot.id,
|
||||
botId: findBot.id
|
||||
});
|
||||
|
||||
if (response.sessionId) {
|
||||
@ -889,7 +884,7 @@ export class TypebotController extends ChatbotController implements ChatbotContr
|
||||
throw new Error('Typebot not found');
|
||||
}
|
||||
|
||||
return await this.sessionRepository.findMany({
|
||||
const sessions = await this.sessionRepository.findMany({
|
||||
where: {
|
||||
instanceId: instanceId,
|
||||
remoteJid,
|
||||
@ -897,6 +892,8 @@ export class TypebotController extends ChatbotController implements ChatbotContr
|
||||
type: 'typebot',
|
||||
},
|
||||
});
|
||||
|
||||
return sessions;
|
||||
} catch (error) {
|
||||
this.logger.error(error);
|
||||
throw new Error('Error fetching sessions');
|
||||
|
@ -113,7 +113,7 @@ export class TypebotRouter extends RouterBroker {
|
||||
request: req,
|
||||
schema: instanceSchema,
|
||||
ClassRef: InstanceDto,
|
||||
execute: (instance) => typebotController.fetchSessions(instance, req.params.typebotId),
|
||||
execute: (instance) => typebotController.fetchSessions(instance, req.params.typebotId, req.query.remoteJid as string | undefined),
|
||||
});
|
||||
|
||||
res.status(HttpStatus.OK).json(response);
|
||||
|
Loading…
Reference in New Issue
Block a user