feat: added general session button in typebot, dify and openai in manager

This commit is contained in:
Davidson Gomes
2024-08-08 23:14:51 -03:00
parent 9329330297
commit 56a165db54
8 changed files with 421 additions and 376 deletions

View File

@@ -551,11 +551,7 @@ export class DifyService {
},
});
if (!dify) {
throw new Error('Dify not found');
}
if (dify.instanceId !== instanceId) {
if (dify && dify.instanceId !== instanceId) {
throw new Error('Dify not found');
}
@@ -564,6 +560,9 @@ export class DifyService {
where: {
difyId: difyId,
},
include: {
Dify: true,
},
});
}
@@ -573,8 +572,20 @@ export class DifyService {
remoteJid: remoteJid,
difyId: difyId,
},
include: {
Dify: true,
},
});
}
return await this.prismaRepository.difySession.findMany({
where: {
instanceId: instanceId,
},
include: {
Dify: true,
},
});
} catch (error) {
this.logger.error(error);
throw new Error('Error fetching sessions');
@@ -1199,7 +1210,7 @@ export class DifyService {
});
let completeMessage = '';
let conversationId
let conversationId;
const stream = response.data;
const reader = new Readable().wrap(stream);
@@ -1211,7 +1222,7 @@ export class DifyService {
const event = JSON.parse(data);
if (event.event === 'agent_message') {
completeMessage += event.answer;
conversationId = conversationId ?? event?.conversation_id
conversationId = conversationId ?? event?.conversation_id;
console.log('completeMessage:', completeMessage);
}
@@ -1241,8 +1252,8 @@ export class DifyService {
data: {
status: 'opened',
awaitUser: true,
sessionId: conversationId
}
sessionId: conversationId,
},
});
sendTelemetry('/message/sendText');
@@ -1556,7 +1567,7 @@ export class DifyService {
});
let completeMessage = '';
let conversationId
let conversationId;
const stream = response.data;
const reader = new Readable().wrap(stream);
@@ -1572,7 +1583,7 @@ export class DifyService {
const event = JSON.parse(jsonString);
if (event.event === 'agent_message') {
completeMessage += event.answer;
conversationId = conversationId ?? event?.conversation_id
conversationId = conversationId ?? event?.conversation_id;
}
} catch (error) {
console.error('Error parsing stream data:', error);
@@ -1600,8 +1611,8 @@ export class DifyService {
data: {
status: 'opened',
awaitUser: true,
sessionId: conversationId
}
sessionId: conversationId,
},
});
sendTelemetry('/message/sendText');

View File

@@ -750,11 +750,7 @@ export class OpenaiService {
},
});
if (!openaiBot) {
throw new Error('Openai Bot not found');
}
if (openaiBot.instanceId !== instanceId) {
if (openaiBot && openaiBot.instanceId !== instanceId) {
throw new Error('Openai Bot not found');
}
@@ -763,6 +759,9 @@ export class OpenaiService {
where: {
openaiBotId: openaiBotId,
},
include: {
OpenaiBot: true,
},
});
}
@@ -772,8 +771,20 @@ export class OpenaiService {
remoteJid: remoteJid,
openaiBotId: openaiBotId,
},
include: {
OpenaiBot: true,
},
});
}
return await this.prismaRepository.openaiSession.findMany({
where: {
instanceId: instanceId,
},
include: {
OpenaiBot: true,
},
});
} catch (error) {
this.logger.error(error);
throw new Error('Error fetching sessions');

View File

@@ -548,11 +548,7 @@ export class TypebotService {
},
});
if (!typebot) {
throw new Error('Typebot not found');
}
if (typebot.instanceId !== instanceId) {
if (typebot && typebot.instanceId !== instanceId) {
throw new Error('Typebot not found');
}
@@ -561,6 +557,9 @@ export class TypebotService {
where: {
typebotId: typebotId,
},
include: {
Typebot: true,
},
});
}
@@ -570,8 +569,20 @@ export class TypebotService {
remoteJid: remoteJid,
instanceId: instanceId,
},
include: {
Typebot: true,
},
});
}
return await this.prismaRepository.typebotSession.findMany({
where: {
instanceId: instanceId,
},
include: {
Typebot: true,
},
});
} catch (error) {
this.logger.error(error);
throw new Error('Error fetching sessions');