mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-13 15:14:49 -06:00
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:
commit
edde059fa1
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user