fix: Fixed Typebot start call with active session by updating instanceId references in TypebotService

In this commit, I fixed an issue with the start call of Typebot when there is an active session. I noticed that there were inconsistencies in the way the instanceId was being referenced in the TypebotService.

To resolve this, I modified the TypebotService to update the instanceId references to the correct format. Specifically, I changed the following files:
- CHANGELOG.md: added a note about the fix for the Typebot start call with active session
- src/api/integrations/typebot/services/typebot.service.ts: updated the instanceId references in the startTypebot, createNewSession, and other related methods.

This change ensures that the Typebot start call with active session works as intended, improving the overall functionality of the Typebot integration.
This commit is contained in:
Davidson Gomes 2024-07-29 09:02:51 -03:00
parent bda0f6a198
commit c3bb632a1a
2 changed files with 40 additions and 19 deletions

View File

@ -9,6 +9,7 @@
* Equations and adjustments for the new manager
* Adjust TriggerType for OpenAI and Typebot integrations
* Fixed Typebot start call with active session
# 2.0.2-beta (2024-07-18 21:33)

View File

@ -619,6 +619,14 @@ export class TypebotService {
public async startTypebot(instance: InstanceDto, data: any) {
if (data.remoteJid === 'status@broadcast') return;
const instanceId = await this.prismaRepository.instance
.findFirst({
where: {
name: instance.instanceName,
},
})
.then((instance) => instance.id);
const remoteJid = data.remoteJid;
const url = data.url;
const typebot = data.typebot;
@ -634,7 +642,7 @@ export class TypebotService {
const defaultSettingCheck = await this.prismaRepository.typebotSetting.findFirst({
where: {
instanceId: instance.instanceId,
instanceId,
},
});
@ -712,14 +720,17 @@ export class TypebotService {
}
if (startSession) {
console.log('startSession', startSession);
let findTypebot: any = await this.prismaRepository.typebot.findFirst({
where: {
url: url,
typebot: typebot,
instanceId: instance.instanceId,
instanceId,
},
});
console.log('findTypebot', findTypebot);
if (!findTypebot) {
findTypebot = await this.prismaRepository.typebot.create({
data: {
@ -727,39 +738,48 @@ export class TypebotService {
url: url,
typebot: typebot,
expire: expire,
triggerType: 'none',
keywordFinish: keywordFinish,
delayMessage: delayMessage,
unknownMessage: unknownMessage,
listeningFromMe: listeningFromMe,
stopBotFromMe: stopBotFromMe,
keepOpen: keepOpen,
instanceId: instance.instanceId,
instanceId,
},
});
}
console.log('findTypebot2', findTypebot);
await this.prismaRepository.typebotSession.deleteMany({
where: {
remoteJid: remoteJid,
instanceId: instance.instanceId,
instanceId,
},
});
const response = await this.createNewSession(instance, {
enabled: true,
url: url,
typebot: typebot,
remoteJid: remoteJid,
expire: expire,
keywordFinish: keywordFinish,
delayMessage: delayMessage,
unknownMessage: unknownMessage,
listeningFromMe: listeningFromMe,
stopBotFromMe: stopBotFromMe,
keepOpen: keepOpen,
prefilledVariables: prefilledVariables,
typebotId: findTypebot.id,
});
const response = await this.createNewSession(
{
instanceName: instance.instanceName,
instanceId: instanceId,
},
{
enabled: true,
url: url,
typebot: typebot,
remoteJid: remoteJid,
expire: expire,
keywordFinish: keywordFinish,
delayMessage: delayMessage,
unknownMessage: unknownMessage,
listeningFromMe: listeningFromMe,
stopBotFromMe: stopBotFromMe,
keepOpen: keepOpen,
prefilledVariables: prefilledVariables,
typebotId: findTypebot.id,
},
);
if (response.sessionId) {
await this.sendWAMessage(