mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-14 09:51:24 -06:00
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:
parent
bda0f6a198
commit
c3bb632a1a
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
* Equations and adjustments for the new manager
|
* Equations and adjustments for the new manager
|
||||||
* Adjust TriggerType for OpenAI and Typebot integrations
|
* Adjust TriggerType for OpenAI and Typebot integrations
|
||||||
|
* Fixed Typebot start call with active session
|
||||||
|
|
||||||
# 2.0.2-beta (2024-07-18 21:33)
|
# 2.0.2-beta (2024-07-18 21:33)
|
||||||
|
|
||||||
|
@ -619,6 +619,14 @@ export class TypebotService {
|
|||||||
public async startTypebot(instance: InstanceDto, data: any) {
|
public async startTypebot(instance: InstanceDto, data: any) {
|
||||||
if (data.remoteJid === 'status@broadcast') return;
|
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 remoteJid = data.remoteJid;
|
||||||
const url = data.url;
|
const url = data.url;
|
||||||
const typebot = data.typebot;
|
const typebot = data.typebot;
|
||||||
@ -634,7 +642,7 @@ export class TypebotService {
|
|||||||
|
|
||||||
const defaultSettingCheck = await this.prismaRepository.typebotSetting.findFirst({
|
const defaultSettingCheck = await this.prismaRepository.typebotSetting.findFirst({
|
||||||
where: {
|
where: {
|
||||||
instanceId: instance.instanceId,
|
instanceId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -712,14 +720,17 @@ export class TypebotService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (startSession) {
|
if (startSession) {
|
||||||
|
console.log('startSession', startSession);
|
||||||
let findTypebot: any = await this.prismaRepository.typebot.findFirst({
|
let findTypebot: any = await this.prismaRepository.typebot.findFirst({
|
||||||
where: {
|
where: {
|
||||||
url: url,
|
url: url,
|
||||||
typebot: typebot,
|
typebot: typebot,
|
||||||
instanceId: instance.instanceId,
|
instanceId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log('findTypebot', findTypebot);
|
||||||
|
|
||||||
if (!findTypebot) {
|
if (!findTypebot) {
|
||||||
findTypebot = await this.prismaRepository.typebot.create({
|
findTypebot = await this.prismaRepository.typebot.create({
|
||||||
data: {
|
data: {
|
||||||
@ -727,39 +738,48 @@ export class TypebotService {
|
|||||||
url: url,
|
url: url,
|
||||||
typebot: typebot,
|
typebot: typebot,
|
||||||
expire: expire,
|
expire: expire,
|
||||||
|
triggerType: 'none',
|
||||||
keywordFinish: keywordFinish,
|
keywordFinish: keywordFinish,
|
||||||
delayMessage: delayMessage,
|
delayMessage: delayMessage,
|
||||||
unknownMessage: unknownMessage,
|
unknownMessage: unknownMessage,
|
||||||
listeningFromMe: listeningFromMe,
|
listeningFromMe: listeningFromMe,
|
||||||
stopBotFromMe: stopBotFromMe,
|
stopBotFromMe: stopBotFromMe,
|
||||||
keepOpen: keepOpen,
|
keepOpen: keepOpen,
|
||||||
instanceId: instance.instanceId,
|
instanceId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('findTypebot2', findTypebot);
|
||||||
|
|
||||||
await this.prismaRepository.typebotSession.deleteMany({
|
await this.prismaRepository.typebotSession.deleteMany({
|
||||||
where: {
|
where: {
|
||||||
remoteJid: remoteJid,
|
remoteJid: remoteJid,
|
||||||
instanceId: instance.instanceId,
|
instanceId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await this.createNewSession(instance, {
|
const response = await this.createNewSession(
|
||||||
enabled: true,
|
{
|
||||||
url: url,
|
instanceName: instance.instanceName,
|
||||||
typebot: typebot,
|
instanceId: instanceId,
|
||||||
remoteJid: remoteJid,
|
},
|
||||||
expire: expire,
|
{
|
||||||
keywordFinish: keywordFinish,
|
enabled: true,
|
||||||
delayMessage: delayMessage,
|
url: url,
|
||||||
unknownMessage: unknownMessage,
|
typebot: typebot,
|
||||||
listeningFromMe: listeningFromMe,
|
remoteJid: remoteJid,
|
||||||
stopBotFromMe: stopBotFromMe,
|
expire: expire,
|
||||||
keepOpen: keepOpen,
|
keywordFinish: keywordFinish,
|
||||||
prefilledVariables: prefilledVariables,
|
delayMessage: delayMessage,
|
||||||
typebotId: findTypebot.id,
|
unknownMessage: unknownMessage,
|
||||||
});
|
listeningFromMe: listeningFromMe,
|
||||||
|
stopBotFromMe: stopBotFromMe,
|
||||||
|
keepOpen: keepOpen,
|
||||||
|
prefilledVariables: prefilledVariables,
|
||||||
|
typebotId: findTypebot.id,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
if (response.sessionId) {
|
if (response.sessionId) {
|
||||||
await this.sendWAMessage(
|
await this.sendWAMessage(
|
||||||
|
Loading…
Reference in New Issue
Block a user