Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/api/integrations/chatbot/base-chatbot.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
7 changes: 6 additions & 1 deletion src/api/integrations/chatbot/base-chatbot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/api/integrations/chatbot/chatbot.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
14 changes: 2 additions & 12 deletions src/api/integrations/chatbot/n8n/services/n8n.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down