Skip to content

Commit edde059

Browse files
Merge pull request #1484 from oriondesign2015/develop
fix: melhora consistência e formatação dos chatbots (N8N e Evolution Bot)
2 parents 5b81702 + dcb09b8 commit edde059

File tree

5 files changed

+12
-16
lines changed

5 files changed

+12
-16
lines changed

src/api/integrations/chatbot/base-chatbot.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ export abstract class BaseChatbotController<BotType = any, BotData extends BaseC
876876
}
877877

878878
// Skip if session exists but not awaiting user input
879-
if (session && !session.awaitUser) {
879+
if (session && session.status === 'closed') {
880880
return;
881881
}
882882

src/api/integrations/chatbot/base-chatbot.service.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,16 @@ export abstract class BaseChatbotService<BotType = any, SettingsType = any> {
126126
): Promise<void> {
127127
try {
128128
// For new sessions or sessions awaiting initialization
129-
if (!session || session.status === 'paused') {
129+
if (!session) {
130130
await this.initNewSession(instance, remoteJid, bot, settings, session, content, pushName, msg);
131131
return;
132132
}
133133

134+
// If session is paused, ignore the message
135+
if (session.status === 'paused') {
136+
return;
137+
}
138+
134139
// For existing sessions, keywords might indicate the conversation should end
135140
const keywordFinish = (settings as any)?.keywordFinish || '';
136141
const normalizedContent = content.toLowerCase().trim();

src/api/integrations/chatbot/chatbot.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export class ChatbotController {
179179
if (session) {
180180
if (session.status !== 'closed' && !session.botId) {
181181
this.logger.warn('Session is already opened in another integration');
182-
return;
182+
return null;
183183
} else if (!session.botId) {
184184
session = null;
185185
}

src/api/integrations/chatbot/evolutionBot/controllers/evolutionBot.controller.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ export class EvolutionBotController extends BaseChatbotController<EvolutionBot,
8989
settings: any,
9090
content: string,
9191
pushName?: string,
92+
msg?: any,
9293
) {
93-
await this.evolutionBotService.process(instance, remoteJid, bot, session, settings, content, pushName);
94+
await this.evolutionBotService.process(instance, remoteJid, bot, session, settings, content, pushName, msg);
9495
}
9596
}

src/api/integrations/chatbot/n8n/services/n8n.service.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export class N8nService extends BaseChatbotService<N8n, N8nSetting> {
186186
while ((match = linkRegex.exec(message)) !== null) {
187187
const [fullMatch, exclamation, altText, url] = match;
188188
const mediaType = this.getMediaType(url);
189-
const beforeText = message.slice(lastIndex, match.index);
189+
const beforeText = message.slice(lastIndex, match.index).trim();
190190

191191
if (beforeText) {
192192
textBuffer += beforeText;
@@ -298,7 +298,7 @@ export class N8nService extends BaseChatbotService<N8n, N8nSetting> {
298298
lastIndex = match.index + fullMatch.length;
299299
}
300300

301-
const remainingText = message.slice(lastIndex);
301+
const remainingText = message.slice(lastIndex).trim();
302302
if (remainingText) {
303303
textBuffer += remainingText;
304304
}
@@ -439,16 +439,6 @@ export class N8nService extends BaseChatbotService<N8n, N8nSetting> {
439439

440440
// If session exists but is paused
441441
if (session.status === 'paused') {
442-
await this.prismaRepository.integrationSession.update({
443-
where: {
444-
id: session.id,
445-
},
446-
data: {
447-
status: 'opened',
448-
awaitUser: true,
449-
},
450-
});
451-
452442
return;
453443
}
454444

0 commit comments

Comments
 (0)