Merge pull request #1484 from oriondesign2015/develop

fix: melhora consistência e formatação dos chatbots (N8N e Evolution Bot)
This commit is contained in:
Davidson Gomes 2025-05-22 06:58:21 -03:00 committed by GitHub
commit edde059fa1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 12 additions and 16 deletions

View File

@ -876,7 +876,7 @@ export abstract class BaseChatbotController<BotType = any, BotData extends BaseC
}
// Skip if session exists but not awaiting user input
if (session && !session.awaitUser) {
if (session && session.status === 'closed') {
return;
}

View File

@ -126,11 +126,16 @@ export abstract class BaseChatbotService<BotType = any, SettingsType = any> {
): Promise<void> {
try {
// For new sessions or sessions awaiting initialization
if (!session || session.status === 'paused') {
if (!session) {
await this.initNewSession(instance, remoteJid, bot, settings, session, content, pushName, msg);
return;
}
// If session is paused, ignore the message
if (session.status === 'paused') {
return;
}
// For existing sessions, keywords might indicate the conversation should end
const keywordFinish = (settings as any)?.keywordFinish || '';
const normalizedContent = content.toLowerCase().trim();

View File

@ -179,7 +179,7 @@ export class ChatbotController {
if (session) {
if (session.status !== 'closed' && !session.botId) {
this.logger.warn('Session is already opened in another integration');
return;
return null;
} else if (!session.botId) {
session = null;
}

View File

@ -89,7 +89,8 @@ export class EvolutionBotController extends BaseChatbotController<EvolutionBot,
settings: any,
content: string,
pushName?: string,
msg?: any,
) {
await this.evolutionBotService.process(instance, remoteJid, bot, session, settings, content, pushName);
await this.evolutionBotService.process(instance, remoteJid, bot, session, settings, content, pushName, msg);
}
}

View File

@ -186,7 +186,7 @@ export class N8nService extends BaseChatbotService<N8n, N8nSetting> {
while ((match = linkRegex.exec(message)) !== null) {
const [fullMatch, exclamation, altText, url] = match;
const mediaType = this.getMediaType(url);
const beforeText = message.slice(lastIndex, match.index);
const beforeText = message.slice(lastIndex, match.index).trim();
if (beforeText) {
textBuffer += beforeText;
@ -298,7 +298,7 @@ export class N8nService extends BaseChatbotService<N8n, N8nSetting> {
lastIndex = match.index + fullMatch.length;
}
const remainingText = message.slice(lastIndex);
const remainingText = message.slice(lastIndex).trim();
if (remainingText) {
textBuffer += remainingText;
}
@ -439,16 +439,6 @@ export class N8nService extends BaseChatbotService<N8n, N8nSetting> {
// If session exists but is paused
if (session.status === 'paused') {
await this.prismaRepository.integrationSession.update({
where: {
id: session.id,
},
data: {
status: 'opened',
awaitUser: true,
},
});
return;
}