-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fix: Melhora o método createConversation (evita conversas criadas duplicadas Chatwoot) #1504
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
Conversation
Reviewer's GuideIntroduz um mecanismo de cache e bloqueio em createConversation para evitar conversas duplicadas, reorganiza o fluxo de obtenção e atualização de contatos e grupos, refatora a busca/criação de conversas incluindo lógica de reopenConversation e conversationPending, e remove trechos redundantes de código, com logs mais claros. Sequence Diagram: Concurrent
|
Change | Details | Files |
---|---|---|
Prevent duplicate conversation creation using cache locks |
|
src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts |
Streamline contact and group metadata processing |
|
src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts |
Refactor conversation lookup and creation flow |
|
src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts |
Clean up redundant code and improve logging |
|
src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts |
Possibly linked issues
- #0: The PR prevents duplicate conversations in Chatwoot by adding a lock to the creation method, addressing the issue.
Tips and commands
Interacting with Sourcery
- Trigger a new review: Comment
@sourcery-ai review
on the pull request. - Continue discussions: Reply directly to Sourcery's review comments.
- Generate a GitHub issue from a review comment: Ask Sourcery to create an
issue from a review comment by replying to it. You can also reply to a
review comment with@sourcery-ai issue
to create an issue from it. - Generate a pull request title: Write
@sourcery-ai
anywhere in the pull
request title to generate a title at any time. You can also comment
@sourcery-ai title
on the pull request to (re-)generate the title at any time. - Generate a pull request summary: Write
@sourcery-ai summary
anywhere in
the pull request body to generate a PR summary at any time exactly where you
want it. You can also comment@sourcery-ai summary
on the pull request to
(re-)generate the summary at any time. - Generate reviewer's guide: Comment
@sourcery-ai guide
on the pull
request to (re-)generate the reviewer's guide at any time. - Resolve all Sourcery comments: Comment
@sourcery-ai resolve
on the
pull request to resolve all Sourcery comments. Useful if you've already
addressed all the comments and don't want to see them anymore. - Dismiss all Sourcery reviews: Comment
@sourcery-ai dismiss
on the pull
request to dismiss all existing Sourcery reviews. Especially useful if you
want to start fresh with a new review - don't forget to comment
@sourcery-ai review
to trigger a new review!
Customizing Your Experience
Access your dashboard to:
- Enable or disable review features such as the Sourcery-generated pull request
summary, the reviewer's guide, and others. - Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.
Getting Help
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
@sourcery-ai resolve |
Essa correção de duplicidade de conversas vai ajudar muito! |
Descrição
Atualmente o método createConversation recebe acionamentos devido aos eventos recebido d service Baileys.
O método verifica se o contato existe e se a conversa já existe, senão cria-os respectivamente.
O método em si não verifica se outra conversa esta em criação por outro evento do mesmo contato gerando alguns problemas.
Problemas
Principalmente ocorre de mensagens encaminhadas de uma só vez do mesmo contato, o que dispara o método de criação múltiplas vezes de forma instantânea em algumas situações. Cada mensagem recebida cria uma nova conversa no Chatwoot.
Independentemente do recurso disponível ou fluxo de mensagens, múltiplas conversas eram abertas na seguinte situação:
Solução
Criar um bloqueio na execução antes do try/catch de criação da conversa se outro evento ainda esteja criando uma conversa para o mesmo número.
Criei através do uso do cache atual. A solução através de um
map
parecia ser melhor, mas isso implicaria futuramente na EvolutionApi em trabalhar com replicas de conteiners.Testes
Testei em 2 clientes, um dele principal, com 15 instancias e mais de 30 mil mensagens todos os dias. Anteriormente tinha de 50 a 100 conversas criadas em duplicidade no Chatwoot, em alguns casos mais de duas conversas.
Atualmente os clientes não tiveram nenhuma conversa criada em duplicidade mais desde a implementação.
Nenhum problema foi relatado alterando parâmetros dentro do Chatwoot ou na integração através do manager.
Summary by Sourcery
Prevent multiple duplicate conversations in Chatwoot by serializing and caching conversation creation per contact
Bug Fixes:
Enhancements: