fix(reply): resolve quoted context for replies to business-sent messages - #507
Open
bambinounos wants to merge 1 commit into
Open
fix(reply): resolve quoted context for replies to business-sent messages#507bambinounos wants to merge 1 commit into
bambinounos wants to merge 1 commit into
Conversation
WhatsApp encodes the peer phone number into the WAMID prefix, so the same message has a different WAMID from the sender's vs the recipient's perspective. When a customer replies to a message the business SENT, the inbound context.id is the recipient-perspective WAMID, which never matches the sender-perspective WAMID stored on the outbound row via an exact lookup. IsReply stayed false and the quoted preview never rendered (replies to the customer's own earlier inbound message matched exactly and did render). Extract the exact-then-FQIA-suffix fallback already used by the reaction handler into a shared resolveMessageByWAMID helper, and use it on the reply path in saveIncomingMessage. The reaction handler now shares the same resolver, removing the duplicated FQIA magic-constant logic. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Problem
When a customer replies to a message the business sent (WhatsApp reply/quote), the quoted context never renders — the reply shows up as a plain message with no quoted preview. Replies to the customer's own earlier inbound message do render correctly.
Root cause
WhatsApp encodes the peer's phone number into the WAMID prefix, so the same message has a different WAMID from the sender's vs the recipient's perspective.
idMeta returns from the send call).context.idis the recipient-perspective WAMID.saveIncomingMessageresolves the quoted message with an exact match only:The two WAMIDs never match, so it logs
"Reply-to message not found",IsReplystaysfalse, and the frontend has nothing to render.This is the same asymmetry that
handleIncomingReactionalready handles — it falls back to matching on the unique suffix after"FQIA"+ a 4-char type indicator, which is stable across perspectives. The reaction path had the fallback; the reply path never got it.Fix
FQIA-suffix lookup into a shared helperresolveMessageByWAMID(wamid) (*models.Message, bool).saveIncomingMessage.handleIncomingReactionto use the same helper, removing the duplicatedFQIAmagic-constant logic.No schema change —
IsReply/ReplyToMessageID/ the preloadedReplyToMessagerelation and the API/DTO already exist; this only fixes resolution.Tests
Added
TestSaveIncomingMessage_ReplyToBusinessSentMessage: seeds an outbound message with a sender-perspective WAMID, processes an inbound reply whosecontext.idis the recipient-perspective WAMID (different prefix + type indicator, same suffix), and asserts the reply resolves (IsReply == true,ReplyToMessageIDpoints at the outbound message). The existing exact-match reply test and the reaction tests continue to cover their paths.go build ./...,go vet ./...clean.