Fix(chat) enviar history sync request como peer para o próprio jid, não para o chat do contato - #150
Open
iagocotta wants to merge 3 commits into
Hidden character warning
The head ref may contain hidden characters: "fix(chat)--enviar-HistorySyncRequest-como-peer-para-o-pr\u00f3prio-JID,-n\u00e3o-para-o-chat-do-contato"
Conversation
There was a problem hiding this comment.
Sorry @iagocotta, your pull request is larger than the review limit of 150000 diff characters
Reviewer's GuideFixes history sync peer routing, adds a complete message sending service layer (including a new /message/forward endpoint and many interactive/Status helpers), adjusts QR/instance behavior when already logged in, and wires new send routes + docs updates. Sequence diagram for fixed history sync peer routingsequenceDiagram
actor User
participant API as EvolutionAPI
participant ChatSvc as chatService
participant WClient as whatsmeow.Client
participant WA as WhatsApp
participant WHLoop as handleHistorySyncNotificationLoop
participant Webhook
User->>API: POST /chat/history-sync
API->>ChatSvc: HistorySyncRequest(data, instance)
ChatSvc->>WClient: BuildHistorySyncRequest(messageInfo, count)
ChatSvc->>WClient: SendPeerMessage(ctx, histRequest)
WClient->>WA: HISTORY_SYNC_ON_DEMAND (peer to own JID)
WA-->>WClient: HistorySyncNotification
WClient->>WHLoop: enqueue notification
WHLoop->>WClient: DownloadHistorySync(handle)
WHLoop-->>Webhook: events.HistorySync{Data: blob}
Sequence diagram for the new /message/forward flowsequenceDiagram
actor Client
participant API as EvolutionAPI
participant Handler as SendHandler
participant Service as SendService
participant WClient as whatsmeow.Client
Client->>API: POST /message/forward
API->>Handler: SendForward(ctx)
Handler->>Handler: validate Number, Message
Handler->>Service: SendForward(data, instance)
Service->>Service: normalizeForwardMessage(message)
Service->>Service: forwardMessageType(message)
Service->>Service: SendMessage(instance, message, messageType, sendData)
Service->>WClient: SendMessage(ctx, recipient, msg, SendRequestExtra)
WClient-->>Service: SendResponse
Service-->>Handler: MessageSendStruct
Handler-->>Client: 200 OK + forwarded message info
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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
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.
Problema
chatService.HistorySyncRequestenvia a requisição de history sync sob demanda (peer data operation do tipoHISTORY_SYNC_ON_DEMAND) para o JID do chat do contato em vez do próprio JID do cliente. Consequência: o WhatsApp descarta a requisição silenciosamente e nenhumHistorySyncNotificationchega — o caller recebe200 OK, o cliente whatsmeow loga oSendMessagecomo enviado, mas nenhum webhook de history sync é disparado.Important
O history sync do pareamento inicial (bootstrap) funciona porque o próprio whatsmeow usa o roteamento correto internamente. Só o endpoint sob demanda
POST /chat/history-syncestá quebrado.Causa raiz
pkg/chat/service/chat_service.go:237Peer messages que carregam
PeerDataOperationRequestMessage(ex: history sync sob demanda) precisam ser roteadas para o próprio device do cliente (own JID), não para um contato. É exatamente isso que o helper upstream faz:Enviar uma peer message de protocolo para um JID de contato não é uma operação válida: o roteamento do WhatsApp descarta a mensagem e, como não há resposta, nenhum
HistorySyncNotificationé gerado. Sem a notificação, nenhumevents.HistorySyncé despachado para o event handler, então nenhum webhook é emitido.Reprodução
POST /chat/history-synccom qualquermessageInfoválido — o endpoint retorna 200HISTORY_SYNCna lista de subscriptionsHistorySyncé entregue, nuncaDEBUGdo whatsmeow, vê-se a mensagem sendo enviada como peer para o JID do contato e sendo ackada, mas sem notificação de follow-upCorreção
Usar
client.SendPeerMessage(ctx, histRequest)— o helper upstream que garante que a requisição vai para o próprio JID como peer message:Fluxo após o fix
HistorySyncNotificationreferenciando o media handlehandleHistorySyncNotificationLoopdo whatsmeow baixa o blob viaDownloadHistorySynce despachaevents.HistorySync{Data: blob}case *events.HistorySync:já existente no Evolution-Go (empkg/whatsmeow/service/whatsmeow.go) emite o webhookHistorySynccom o payload das conversationsImpacto
POST /chat/history-syncpassam a receber webhooksHistorySync(é preciso terHISTORY_SYNCna lista de subscribe)messageInfo.Chatdo input continua sendo usado — ele é passado dentro deHistorySyncOnDemandRequest.ChatJIDpeloBuildHistorySyncRequest, que é o lugar correto para ele. Ele apenas não deve ser o destino de roteamento da mensagem externaTestado
POST /chat/history-synccommessageInfoválido numa sessão que tinha mensagens mais antigas que a âncoraHistorySyncchegouHistorySyncNotificationchegou em 2–5 s e o webhookHistorySyncfoi entregue com as conversations reconstruídasSummary by Sourcery
Fix on-demand history sync routing and introduce unified send/forward message service with new forwarding API and docs.
New Features:
Bug Fixes:
Enhancements:
Documentation: