-
Notifications
You must be signed in to change notification settings - Fork 5.2k
refactor(chatwoot): Melhora e ajusta tratamento de números @lid #1594
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
refactor(chatwoot): Melhora e ajusta tratamento de números @lid #1594
Conversation
Reviewer's GuideThis PR simplifies and refactors contact handling in Chatwoot integration by unifying method signatures, removing special-case LID logic, consolidating identifier resolution, and enhancing the createConversation flow to correctly process and update @lid contacts. Sequence Diagram: Simplified findContact Call and LogicsequenceDiagram
participant Caller
participant ChatwootService
participant ChatwootAPI
Caller->>ChatwootService: findContact(instance, phoneNumberString)
Note right of ChatwootService: phoneNumberString is now a simple string (e.g., "12345...")
ChatwootService->>ChatwootService: isGroup = phoneNumberString.includes('@g.us')
alt if not isGroup
ChatwootService->>ChatwootService: query = "+" + phoneNumberString
else is group
ChatwootService->>ChatwootService: query = phoneNumberString
end
Note left of ChatwootService: Internal @lid specific query path removed.
ChatwootService->>ChatwootAPI: contacts.search({ q: query }) or contacts.filter(...)
Note right of ChatwootService: Fallback search logic removed.
ChatwootAPI-->>ChatwootService: contactList
ChatwootService-->>Caller: contact
Sequence Diagram: @lid Contact Identifier Update in createConversationsequenceDiagram
participant EventHandler
participant ChatwootService
participant ChatwootAPI
EventHandler->>ChatwootService: createConversation(instance, body)
Note right of ChatwootService: body.key.remoteJid contains '@lid',
Note right of ChatwootService: body.key.senderPn has correct ID
ChatwootService->>ChatwootService: Check if remoteJid is @lid and senderPn differs
opt if @lid contact needs identifier update
ChatwootService->>ChatwootService: findContact(instance, body.key.remoteJid.split('@')[0])
ChatwootService->>ChatwootAPI: Search for contact by old @lid value (via findContact)
ChatwootAPI-->>ChatwootService: contactToUpdate
alt if contactToUpdate AND contactToUpdate.identifier != body.key.senderPn
ChatwootService->>ChatwootAPI: updateContact(contactToUpdate.id, { identifier: body.key.senderPn, phone_number: ... })
ChatwootAPI-->>ChatwootService: (ack)
end
end
ChatwootService->>ChatwootService: Continue with conversation creation using senderPn as primary identifier for @lid
Updated Class Diagram for ChatwootServiceclassDiagram
class ChatwootService {
+createContact(instance: InstanceDto, phoneNumber: string, inboxId: number, isGroup: boolean, name?: string, avatar_url?: string, jid?: string)
+findContact(instance: InstanceDto, phoneNumber: string)
+createConversation(instance: InstanceDto, body: any)
+createChatwootBotContact(instance: InstanceDto, inboxId: number, organization?: string, logo?: string)
%% Method Removed: normalizeContactIdentifier(msg: any) %%
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Bom dia @KokeroO, tudo bem? Consegue descrever os passos para reproduzir este caso? Estou tendo esse erro, mas não consegui reproduzir de nenhuma forma. |
Descrição
Melhora e refatora parte dos commits anteriores que tens como objetivo solucionar a criação dos contatos
@lidno Chatwoot.@DavidsonGomes com todo o respeito, analisei e testei essas ultimas implementações suas. Mas em certos pontos os
@lidestão sendo tratados em condições junto com grupos, esses@lidsão diferente disso. Em alguns momentos funciona e em outros não.Desde 11/06 vim testando insistentemente e reproduzindo o erro com contatos que eu mesmo consegui simular. Estou com um cliente que teve 263 contatos criados com lid, cliente com fluxo atual de 40 mil a 50 mil msgs por dia.
A solução que empreguei é bem mais simples e totalmente funcional.
Nos meus teste, o script foi capaz:
@lidcom@s.whatsapp.netcorretamente.@lide atualizar o identificador para o número correto@s.whatsapp.net.Diferenças:
O evento é diferente que eventos de participantes de grupo:
Grupo:
lid:
Summary by Sourcery
Refactor Chatwoot integration to streamline contact lookup and creation by unifying method signatures, removing redundant lid-specific branches, and improving detection and updating of @lid contact identifiers during conversations.
Enhancements: