-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fix: melhora consistência e formatação dos chatbots (N8N e Evolution Bot) #1484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Corrige o problema de formatação nas mensagens do N8n onde quebras de linha extras estavam sendo adicionadas antes e depois das mídias (imagens, vídeos, etc). Agora o texto é enviado mantendo apenas as quebras de linha intencionais.
Corrige o problema onde o Evolution Bot não processava mensagens subsequentes após a primeira resposta. A correção permite que o bot continue respondendo a todas as mensagens enquanto a sessão estiver ativa, melhorando a continuidade da conversa.
Corrige o problema onde o Evolution Bot reativava automaticamente por qualquer mensagem do usuario quando a sessão estava pausada. Agora, quando uma sessão está pausada, o bot ignora completamente as mensagens recebidas até que a sessão seja explicitamente reativada.
Corrige o problema onde o N8N reativava automaticamente a sessão após receber uma mensagem quando estava pausado. Agora, quando uma sessão está pausada, o bot ignora completamente as mensagens recebidas até que a sessão seja explicitamente reativada através do endpoint de mudança de status.
Reviewer's GuideThis PR applies whitespace trimming to chatbot messages in N8n, overhauls session pause handling (disabling auto-reopen and ignoring messages during pause) across the BaseChatbotService, and harmonizes controller behaviors—standardizing skip logic, return values, and forwarding the raw message in the EvolutionBotController. Sequence Diagram: Message Processing with Paused Session in BaseChatbotServicesequenceDiagram
participant ClientCode as Specific Chatbot Logic
participant BaseChatbotService
ClientCode->>BaseChatbotService: processMessage(..., session, content, ...)
BaseChatbotService->>BaseChatbotService: Check if session object exists
alt session is null (new conversation)
BaseChatbotService->>BaseChatbotService: initNewSession(...)
end
BaseChatbotService->>BaseChatbotService: Get session.status
alt session.status is "paused"
BaseChatbotService-->>ClientCode: Return immediately (message ignored)
else session.status is not "paused" (e.g., "opened", "awaitingInput")
BaseChatbotService->>BaseChatbotService: Proceed with normal message processing (e.g., check keywords, interact with bot logic)
BaseChatbotService-->>ClientCode: Return (processing complete / potential response)
end
Class Diagram: Updates to Chatbot System ClassesclassDiagram
class BaseChatbotService~BotType, SettingsType~ {
#processMessage(instance, remoteJid, bot, settings, session, content, pushName, msg): Promise~void~
}
class N8nService {
% Method where message formatting (e.g., .trim()) was updated %
-_parseMessageContent(message: string): string
% Method handling incoming N8N webhooks, session logic updated for paused state %
+handleWebhook(payload: any): void
}
N8nService --|> BaseChatbotService
class BaseChatbotController~BotType, BotData~ {
% Method handling incoming messages, logic for skipping already closed sessions updated %
#_onMessageReceived(event: any, session: Session, ...): void
}
class EvolutionBotController {
% Method signature updated to include 'msg' parameter %
#processMessage(instance, remoteJid, bot, session, settings, content: string, pushName?: string, msg?: any): void
}
EvolutionBotController --|> BaseChatbotController
class EvolutionBotService {
% Method signature updated to include 'msg' parameter, called by EvolutionBotController %
#process(instance, remoteJid, bot, session, settings, content: string, pushName?: string, msg?: any): void
}
EvolutionBotService --|> BaseChatbotService
class ChatbotController {
% Method for assigning bot to session, return behavior changed for specific conditions %
#_ensureBotAssignedToSession(integrationId: string, remoteJid: string, botId?: string, session?: Session, ...): Session | null
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Descrição
Esta PR implementa várias correções para melhorar a consistência e formatação dos chatbots, padronizando comportamentos e melhorando a experiência do usuário.
Mudanças
N8n
Formatação de Mensagens
.trim()
nas variáveisbeforeText
eremainingText
Gerenciamento de Sessão
Evolution Bot
Processamento de Mensagens
Comportamento de Sessão
Observação
Devido à refatoração em andamento do sistema de chatbots, é possível que outras integrações (como OpenAI, Dify, Flowise, EvoAI, etc) apresentem problemas semelhantes de gerenciamento de sessão que podem ser corrigidas em PRs subsequentes.
Summary by Sourcery
Improve consistency and formatting for N8N and Evolution Bot chatbots by trimming message whitespace, removing unintended newlines, and standardizing session pause behavior across integrations.
Bug Fixes:
Enhancements: