fix: decrypt inbound message edits and clarify revoke webhooks - #122
Open
cesar-carlos wants to merge 4 commits into
Open
fix: decrypt inbound message edits and clarify revoke webhooks#122cesar-carlos wants to merge 4 commits into
cesar-carlos wants to merge 4 commits into
Conversation
Newer WhatsApp clients send edits as SecretEncryptedMessage; without decrypting, Message webhooks arrived without the new text. Decrypt MESSAGE_EDIT before marshal, set IsEdit, and document the contract. Closes evolution-foundation#92 Co-authored-by: Cursor <cursoragent@cursor.com>
Expose IsRevoke, messageType, and protocolMessage.typeName so consumers can detect deletes without relying on opaque Info.Edit or numeric type 0. Part of evolution-foundation#92 Co-authored-by: Cursor <cursoragent@cursor.com>
Keep IsEdit/messageType when decrypt fails, unwrap EditedMessage after decrypt without resetting RawMessage, prefer clientPointer like polls, and document key.ID plus the failure-path contract. Co-authored-by: Cursor <cursoragent@cursor.com>
DecryptSecretEncryptedMessage derives keys from wire Sender/Chat; swapping LID to PN first caused MAC failures despite a stored message secret. Also expose decryptFailed when plaintext cannot be recovered. Co-authored-by: Cursor <cursoragent@cursor.com>
Reviewer's GuideThis PR fixes inbound WhatsApp message edit/revoke webhook usability by decrypting MESSAGE_EDIT secrets before JID normalization, unwrapping EditedMessage correctly, and setting explicit edit/revoke flags and protocolMessage.typeName, along with documenting the webhook contract. Sequence diagram for inbound MESSAGE_EDIT decryption and webhook flagssequenceDiagram
participant WhatsAppServer
participant MyClient
participant WAClient
participant WebhookConsumer
WhatsAppServer ->> MyClient: myEventHandler(rawEvt)
MyClient ->> MyClient: detect SecretEncryptedMessage_MESSAGE_EDIT
MyClient ->> WAClient: DecryptSecretEncryptedMessage(ctx, evt)
alt [decrypt ok]
WAClient -->> MyClient: decrypted Message
MyClient ->> MyClient: evt.Message = decrypted
MyClient ->> MyClient: unwrap EditedMessage
MyClient ->> MyClient: parsedMessageType = "edit"
MyClient ->> MyClient: setProtocolMessageTypeName(dataMap, MESSAGE_EDIT)
MyClient ->> WebhookConsumer: POST Message webhook
Note right of WebhookConsumer: data.IsEdit = true\ndata.messageType = edit\nMessage.protocolMessage.typeName = MESSAGE_EDIT
else [decrypt failed]
WAClient -->> MyClient: error
MyClient ->> MyClient: decryptFailed = true
MyClient ->> MyClient: IsEdit = true, messageType = edit
MyClient ->> WebhookConsumer: POST Message webhook
Note right of WebhookConsumer: data.IsEdit = true\ndata.messageType = edit\ndata.decryptFailed = true\nno plaintext editedMessage
end
Note over MyClient: LID→PN JID swap happens after decrypt
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider reusing a local logger variable in the MESSAGE_EDIT decrypt block instead of calling
loggerWrapper.GetLogger(mycli.userID)multiple times to reduce repetition and potential overhead. - The decrypt call uses
context.Background(); if possible, pass through a request- or event-scoped context (with timeout/cancellation) to avoid potential hangs on slow or blocked decrypt operations. - The successful decrypt log is currently at info level and may become noisy under high edit volume; consider lowering it to debug or gating it behind a verbosity flag.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider reusing a local logger variable in the MESSAGE_EDIT decrypt block instead of calling `loggerWrapper.GetLogger(mycli.userID)` multiple times to reduce repetition and potential overhead.
- The decrypt call uses `context.Background()`; if possible, pass through a request- or event-scoped context (with timeout/cancellation) to avoid potential hangs on slow or blocked decrypt operations.
- The successful decrypt log is currently at info level and may become noisy under high edit volume; consider lowering it to debug or gating it behind a verbosity flag.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
cesar-carlos
added a commit
to cesar-carlos/evolution-go
that referenced
this pull request
Jul 17, 2026
Inbound message edit decrypt + revoke webhook flags (PR evolution-foundation#122).
Author
|
Closing from the author side: these changes are already merged into our fork The commits remain available on the PR branch if maintainers still want to review/merge into |
Author
|
Reopened — keeping this PR available for upstream review/merge. |
1 task
ecosb2b
pushed a commit
to ecosb2b/evo-go-v2
that referenced
this pull request
Aug 5, 2026
Merges the Athene fork, which sits 11 commits ahead of the same upstream base and had already solved — in production — the three problems this fork was working through, plus a batch of upstream PRs we had not picked up. Only pkg/whatsmeow/service/whatsmeow.go conflicted (6 hunks); the other 63 files merged cleanly. Every conflict was resolved in favour of the incoming version, because each one was a place where both forks fixed the same bug and theirs is the one we chose to keep: - Connection leak: their getAuthContainer/sharedAuthContainer replaces our storeContainer/storeContainerHolder. Same fix, but theirs is a backport of upstream PR evolution-foundation#117, so it will converge with upstream instead of conflicting when that PR merges. It also caps SQLite at MaxOpenConns(1), which ours did not. - Reconnection: their runtime supervisor replaces our EnableAutoReconnect=true. Ours stopped the automatic disconnect loop but left ReconnectClient reachable from the API endpoint and the send retry, so those paths could still spawn a second client. Their runtime token refuses to start a second runtime for an instance from any path, waits for the previous goroutine to exit, deduplicates concurrent reconnects, backs off exponentially with jitter, and probes to confirm the reconnect actually connected. - Shared maps: ClientMapsMu closes the "fatal error: concurrent map writes" hole, which was still open on our side and kills the whole process rather than panicking a single request. Also arriving with the merge: upstream PRs evolution-foundation#149, evolution-foundation#135, evolution-foundation#34, evolution-foundation#100, evolution-foundation#143, evolution-foundation#137, evolution-foundation#120, evolution-foundation#130, evolution-foundation#151 and evolution-foundation#122; multi-webhook fan-out; POST /send/product; POST /user/savecontact; GET /server/stats and the dashboard; the whatsmeow update to 20260721; and removal of the 61 MB compiled binary that was tracked in git. Our GHCR workflow did not conflict and is preserved. store_container_test.go was adapted to the incoming implementation: it now exercises getAuthContainer, asserts against their MaxOpenConns of 20, and resets sharedAuthContainer between tests, since that container is a package-level global and would otherwise carry between tests and invalidate the pg_stat_activity measurements. It is kept alongside their auth_container_retry_test.go because it measures something theirs does not: the connection count the server actually sees. Co-Authored-By: Claude Opus 5 (1M context) <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.
Description
Incoming WhatsApp message edits from contacts were delivered as
Messagewebhooks with onlysecretEncryptedMessage(no plaintext). Consumers (e.g. Chatwoot) could detect the edit and original message ID, but could not apply the new text.This PR:
SecretEncryptedMessagewithsecretEncType = MESSAGE_EDITvia whatsmeowDecryptSecretEncryptedMessagebefore building the webhook payload.cipher: message authentication failedeven when the message secret existed inwhatsmeow_message_secrets(LID-keyed store).EditedMessagewrapper after decrypt (without callingUnwrapRaw, which would reset fromRawMessage).IsEdit,messageType: "edit", andprotocolMessage.typeName: "MESSAGE_EDIT".IsEdit/messageType: "edit"and addsdecryptFailed: true(still no plaintext — documented).IsRevoke,messageType: "revoke", andprotocolMessage.typeName: "REVOKE"so consumers do not rely only on opaqueInfo.Edit: "7"/ numerictype: 0.docs/wiki/recursos-avancados/events-system.md.Outbound
POST /message/editwas already working; this PR only fixes inbound edit/revoke webhook usability.Related Issue
Closes #92
Related: #108 (same inbound edit plaintext gap; closed without a fix)
Type of Change
Examples (after fix)
Inbound edit (contact edits on WhatsApp)
{ "event": "Message", "data": { "Info": { "IsFromMe": false, "ID": "<edit-event-id>", "Edit": "1", "Type": "text" }, "IsEdit": true, "messageType": "edit", "Message": { "protocolMessage": { "type": 14, "typeName": "MESSAGE_EDIT", "key": { "ID": "<ORIGINAL_MESSAGE_ID>" }, "editedMessage": { "conversation": "Texto editado pelo cliente" } } } } }editedMessage.extendedTextMessage.textis also valid.Consumer rules:
Message.protocolMessage.key.ID(notInfo.ID)editedMessage.conversationoreditedMessage.extendedTextMessage.textIsEdit/messageType: "edit"/Info.Edit: "1"If decrypt fails:
decryptFailed: truemay be present with the encrypted envelope still in place.Inbound revoke (delete for everyone)
{ "event": "Message", "data": { "IsRevoke": true, "messageType": "revoke", "Message": { "protocolMessage": { "type": 0, "typeName": "REVOKE", "key": { "ID": "<ORIGINAL_MESSAGE_ID>" } } } } }Outbound edit via API (unchanged, still works)
POST /message/edit+ webhook echo withIsFromMe: trueand plaintext ineditedMessage— no regression expected.Testing
Manual validation in production-like Docker:
protocolMessage.editedMessageplaintext (not onlysecretEncryptedMessage).IsRevoke/typeName: "REVOKE".Checklist
Additional Notes
pkg/whatsmeow/service/whatsmeow.go,docs/wiki/recursos-avancados/events-system.md.MESSAGE_EDIT); edits/revokes remain underMESSAGE→ eventMessage.Made with Cursor
Summary by Sourcery
Improve inbound WhatsApp message edit and revoke webhook payloads for better consumer handling of edits and deletions.
Bug Fixes:
Enhancements:
Documentation: