mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-16 04:02:54 -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
|
// Skip if session exists but not awaiting user input
|
||||||
if (session && !session.awaitUser) {
|
if (session && session.status === 'closed') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,11 +126,16 @@ export abstract class BaseChatbotService<BotType = any, SettingsType = any> {
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
// For new sessions or sessions awaiting initialization
|
// 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);
|
await this.initNewSession(instance, remoteJid, bot, settings, session, content, pushName, msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If session is paused, ignore the message
|
||||||
|
if (session.status === 'paused') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// For existing sessions, keywords might indicate the conversation should end
|
// For existing sessions, keywords might indicate the conversation should end
|
||||||
const keywordFinish = (settings as any)?.keywordFinish || '';
|
const keywordFinish = (settings as any)?.keywordFinish || '';
|
||||||
const normalizedContent = content.toLowerCase().trim();
|
const normalizedContent = content.toLowerCase().trim();
|
||||||
|
@ -179,7 +179,7 @@ export class ChatbotController {
|
|||||||
if (session) {
|
if (session) {
|
||||||
if (session.status !== 'closed' && !session.botId) {
|
if (session.status !== 'closed' && !session.botId) {
|
||||||
this.logger.warn('Session is already opened in another integration');
|
this.logger.warn('Session is already opened in another integration');
|
||||||
return;
|
return null;
|
||||||
} else if (!session.botId) {
|
} else if (!session.botId) {
|
||||||
session = null;
|
session = null;
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,8 @@ export class EvolutionBotController extends BaseChatbotController<EvolutionBot,
|
|||||||
settings: any,
|
settings: any,
|
||||||
content: string,
|
content: string,
|
||||||
pushName?: 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) {
|
while ((match = linkRegex.exec(message)) !== null) {
|
||||||
const [fullMatch, exclamation, altText, url] = match;
|
const [fullMatch, exclamation, altText, url] = match;
|
||||||
const mediaType = this.getMediaType(url);
|
const mediaType = this.getMediaType(url);
|
||||||
const beforeText = message.slice(lastIndex, match.index);
|
const beforeText = message.slice(lastIndex, match.index).trim();
|
||||||
|
|
||||||
if (beforeText) {
|
if (beforeText) {
|
||||||
textBuffer += beforeText;
|
textBuffer += beforeText;
|
||||||
@ -298,7 +298,7 @@ export class N8nService extends BaseChatbotService<N8n, N8nSetting> {
|
|||||||
lastIndex = match.index + fullMatch.length;
|
lastIndex = match.index + fullMatch.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
const remainingText = message.slice(lastIndex);
|
const remainingText = message.slice(lastIndex).trim();
|
||||||
if (remainingText) {
|
if (remainingText) {
|
||||||
textBuffer += remainingText;
|
textBuffer += remainingText;
|
||||||
}
|
}
|
||||||
@ -439,16 +439,6 @@ export class N8nService extends BaseChatbotService<N8n, N8nSetting> {
|
|||||||
|
|
||||||
// If session exists but is paused
|
// If session exists but is paused
|
||||||
if (session.status === 'paused') {
|
if (session.status === 'paused') {
|
||||||
await this.prismaRepository.integrationSession.update({
|
|
||||||
where: {
|
|
||||||
id: session.id,
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
status: 'opened',
|
|
||||||
awaitUser: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user