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. |
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: