diff --git a/src/api/integrations/chatbot/typebot/controllers/typebot.controller.ts b/src/api/integrations/chatbot/typebot/controllers/typebot.controller.ts index b933341e..f5729257 100644 --- a/src/api/integrations/chatbot/typebot/controllers/typebot.controller.ts +++ b/src/api/integrations/chatbot/typebot/controllers/typebot.controller.ts @@ -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'); diff --git a/src/api/integrations/chatbot/typebot/routes/typebot.router.ts b/src/api/integrations/chatbot/typebot/routes/typebot.router.ts index f556f94f..3a39e96e 100644 --- a/src/api/integrations/chatbot/typebot/routes/typebot.router.ts +++ b/src/api/integrations/chatbot/typebot/routes/typebot.router.ts @@ -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);