From e04ebc1cdf71e24e4dcb9686d8a24f3275f6ec28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcolas=20Novis?= Date: Thu, 30 Jul 2026 03:49:46 -0300 Subject: [PATCH] feat(send): support view-once media on /send/media and /send/media/file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- pkg/sendMessage/service/send_service.go | 37 +++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/pkg/sendMessage/service/send_service.go b/pkg/sendMessage/service/send_service.go index b8850089..5fa33f41 100644 --- a/pkg/sendMessage/service/send_service.go +++ b/pkg/sendMessage/service/send_service.go @@ -117,6 +117,7 @@ type MediaStruct struct { FormatJid *bool `json:"formatJid,omitempty"` Quoted QuotedStruct `json:"quoted"` ForwardingScore *uint32 `json:"forwardingScore,omitempty"` + ViewOnce bool `json:"viewOnce"` } type PollStruct struct { @@ -1186,6 +1187,24 @@ func (s *sendService) sendMediaFileWithRetry(data *MediaStruct, fileData []byte, return nil, errors.New("invalid media type") } + // view-once: when requested, flag the media so it disappears after the recipient opens it + // once (image, video and voice/PTV support it; documents do not). Additive — without the + // flag the media is a normal message, exactly as before. + if data.ViewOnce { + if media.ImageMessage != nil { + media.ImageMessage.ViewOnce = proto.Bool(true) + } + if media.VideoMessage != nil { + media.VideoMessage.ViewOnce = proto.Bool(true) + } + if media.AudioMessage != nil { + media.AudioMessage.ViewOnce = proto.Bool(true) + } + if media.PtvMessage != nil { + media.PtvMessage.ViewOnce = proto.Bool(true) + } + } + message, err := s.SendMessage(instance, media, mediaType, &SendDataStruct{ Id: data.Id, Number: data.Number, @@ -1490,6 +1509,24 @@ func (s *sendService) sendMediaUrlWithRetry(data *MediaStruct, instance *instanc return nil, errors.New("invalid media type") } + // view-once: when requested, flag the media so it disappears after the recipient opens it + // once (image, video and voice/PTV support it; documents do not). Additive — without the + // flag the media is a normal message, exactly as before. + if data.ViewOnce { + if media.ImageMessage != nil { + media.ImageMessage.ViewOnce = proto.Bool(true) + } + if media.VideoMessage != nil { + media.VideoMessage.ViewOnce = proto.Bool(true) + } + if media.AudioMessage != nil { + media.AudioMessage.ViewOnce = proto.Bool(true) + } + if media.PtvMessage != nil { + media.PtvMessage.ViewOnce = proto.Bool(true) + } + } + messageStart := time.Now() message, err := s.SendMessage(instance, media, mediaType, &SendDataStruct{ Id: data.Id,