feat(send): support view-once media on /send/media - #147
Open
nicolasnovis wants to merge 1 commit into
Open
Conversation
Add an optional `viewOnce` boolean to MediaStruct. When true, the built media message is flagged as view-once so it disappears after the recipient opens it once — supported for image, video and voice/PTV (documents don't support it). The flag is additive and defaults to false, so existing callers are unaffected; the underlying waE2E.*Message.ViewOnce fields already exist, this just wires them from the request body. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Reviewer's GuideAdd view-once support to media sending endpoints by extending MediaStruct with a viewOnce flag and, when set, marking the underlying WhatsApp media protos as view-once for supported types in both file-based and URL-based media send flows. Sequence diagram for /send/media view-once handlingsequenceDiagram
actor Client
participant SendService
participant MediaProto
Client->>SendService: POST /send/media (MediaStruct with viewOnce)
SendService->>SendService: sendMediaUrlWithRetry(data, instance)
SendService->>SendService: build media ImageMessage/VideoMessage/AudioMessage/PtvMessage
alt [data.ViewOnce is true]
SendService->>MediaProto: set ImageMessage.ViewOnce = proto.Bool(true)
SendService->>MediaProto: set VideoMessage.ViewOnce = proto.Bool(true)
SendService->>MediaProto: set AudioMessage.ViewOnce = proto.Bool(true)
SendService->>MediaProto: set PtvMessage.ViewOnce = proto.Bool(true)
else [data.ViewOnce is false]
Note over SendService,MediaProto: Media message remains normal (non-view-once)
end
SendService->>SendService: SendMessage(instance, media, mediaType, SendDataStruct)
SendService-->>Client: message response
File-Level Changes
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:
- The view-once flagging logic is duplicated in both sendMediaFileWithRetry and sendMediaUrlWithRetry; consider extracting this into a small helper to keep the behavior consistent and easier to maintain.
- MediaStruct.ViewOnce is described as optional but lacks
omitemptyand uses a plain bool, so clients cannot distinguish between an omitted and explicitly false value; if that distinction matters, consider switching to*boolwithomitempty.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The view-once flagging logic is duplicated in both sendMediaFileWithRetry and sendMediaUrlWithRetry; consider extracting this into a small helper to keep the behavior consistent and easier to maintain.
- MediaStruct.ViewOnce is described as optional but lacks `omitempty` and uses a plain bool, so clients cannot distinguish between an omitted and explicitly false value; if that distinction matters, consider switching to `*bool` with `omitempty`.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
What
Adds an optional
viewOnceboolean to the media send body (MediaStruct), used byPOST /send/mediaandPOST /send/media/file. Whentrue, the media is flagged as view-once (disappears after the recipient opens it once).Why
The
waE2Emedia protos (ImageMessage,VideoMessage,AudioMessage) already expose aViewOncefield, but the send endpoints don't let callers set it — so it's currently impossible to send a view-once photo/video/voice through Evolution Go, even though the Baileys-based Evolution API supports it. This closes that parity gap.Change
MediaStructgainsViewOnce bool \json:"viewOnce"`(defaults tofalse` → existing callers unaffected).sendMediaFileWithRetryandsendMediaUrlWithRetry), after the media message is built, a small additive block setsViewOnce = proto.Bool(true)on the image / video / audio / PTV proto when requested. Documents are intentionally left out (WhatsApp doesn't support view-once documents).POST /send/media { "number": "5521...", "type": "image", "url": "https://...", "caption": "hi", "viewOnce": true }Notes
viewOnceis omitted/false.swag initor adjust if the CI expects it. The functional change is self-contained insend_service.go.Summary by Sourcery
Add support for marking outbound media messages as view-once in the send media service.
New Features: