Skip to content

feat(send): support view-once media on /send/media - #147

Open
nicolasnovis wants to merge 1 commit into
evolution-foundation:mainfrom
nicolasnovis:feat/send-media-view-once
Open

feat(send): support view-once media on /send/media#147
nicolasnovis wants to merge 1 commit into
evolution-foundation:mainfrom
nicolasnovis:feat/send-media-view-once

Conversation

@nicolasnovis

@nicolasnovis nicolasnovis commented Jul 30, 2026

Copy link
Copy Markdown

What

Adds an optional viewOnce boolean to the media send body (MediaStruct), used by POST /send/media and POST /send/media/file. When true, the media is flagged as view-once (disappears after the recipient opens it once).

Why

The waE2E media protos (ImageMessage, VideoMessage, AudioMessage) already expose a ViewOnce field, 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

  • MediaStruct gains ViewOnce bool \json:"viewOnce"`(defaults tofalse` → existing callers unaffected).
  • In both media builders (sendMediaFileWithRetry and sendMediaUrlWithRetry), after the media message is built, a small additive block sets ViewOnce = 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

  • Purely additive; no behavior change when viewOnce is omitted/false.
  • Swagger request-body docs weren't regenerated locally (no Go toolchain on my side) — happy to run swag init or adjust if the CI expects it. The functional change is self-contained in send_service.go.

Summary by Sourcery

Add support for marking outbound media messages as view-once in the send media service.

New Features:

  • Allow clients to set a viewOnce flag on media send requests via the MediaStruct.
  • Enable view-once behavior for image, video, audio, and PTV messages sent through /send/media and /send/media/file.

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>
@sourcery-ai

sourcery-ai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Reviewer's Guide

Add 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 handling

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Add a view-once flag to media send requests and wire it into the media sending pipeline for supported media types.
  • Extend MediaStruct with a non-omitempty boolean ViewOnce field exposed as json:"viewOnce" so clients can request view-once behavior.
  • In sendMediaFileWithRetry, after building the media proto, conditionally set ViewOnce = proto.Bool(true) on ImageMessage, VideoMessage, AudioMessage, and PtvMessage when data.ViewOnce is true.
  • In sendMediaUrlWithRetry, mirror the same conditional ViewOnce = proto.Bool(true) assignments for ImageMessage, VideoMessage, AudioMessage, and PtvMessage when data.ViewOnce is true, leaving unsupported document messages unchanged.
pkg/sendMessage/service/send_service.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant