From e19aa84de9c42a5aca2256f05c8d8dbe51d3e389 Mon Sep 17 00:00:00 2001 From: Eduardo Milani Date: Thu, 19 Feb 2026 16:52:08 -0300 Subject: [PATCH] fix: prevent media processing failures from aborting webhook delivery When skipMedia is false, each media processing block (image, audio, document, video, sticker) contains multiple return statements that abort the entire event handler if any step fails (e.g., directory creation, media download, file write, base64 conversion). This means that if media processing fails for any reason, the webhook is never sent to the consumer, causing the message to silently disappear. The consumer never knows the message existed. This is a critical issue because many consumers handle media downloads independently via the /chat/downloadimage (and similar) API endpoints using the encryption keys provided in the message payload. They do not depend on the pre-processed media from the webhook, so aborting the webhook is unnecessary and harmful. The fix wraps each media processing block in an anonymous function (closure) so that return statements only exit the closure, not the parent event handler. This ensures the webhook is always delivered regardless of media processing outcome. Affected media types: image, audio, document, video, sticker. --- wmiau.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/wmiau.go b/wmiau.go index f34012ac..3c05bb4e 100644 --- a/wmiau.go +++ b/wmiau.go @@ -839,6 +839,7 @@ func (mycli *MyClient) myEventHandler(rawEvt interface{}) { // try to get Image if any img := evt.Message.GetImageMessage() if img != nil { + func() { // Create a temporary directory in /tmp tmpDirectory := filepath.Join("/tmp", "user_"+txtid) errDir := os.MkdirAll(tmpDirectory, 0751) @@ -916,11 +917,13 @@ func (mycli *MyClient) myEventHandler(rawEvt interface{}) { } else { log.Info().Str("path", tmpPath).Msg("Temporary file deleted") } + }() } // try to get Audio if any audio := evt.Message.GetAudioMessage() if audio != nil { + func() { // Create a temporary directory in /tmp tmpDirectory := filepath.Join("/tmp", "user_"+txtid) errDir := os.MkdirAll(tmpDirectory, 0751) @@ -1004,11 +1007,13 @@ func (mycli *MyClient) myEventHandler(rawEvt interface{}) { } else { log.Info().Str("path", tmpPath).Msg("Temporary file deleted") } + }() } // try to get Document if any document := evt.Message.GetDocumentMessage() if document != nil { + func() { // Create a temporary directory in /tmp tmpDirectory := filepath.Join("/tmp", "user_"+txtid) errDir := os.MkdirAll(tmpDirectory, 0751) @@ -1097,11 +1102,13 @@ func (mycli *MyClient) myEventHandler(rawEvt interface{}) { } else { log.Info().Str("path", tmpPath).Msg("Temporary file deleted") } + }() } // try to get Video if any video := evt.Message.GetVideoMessage() if video != nil { + func() { // Create a temporary directory in /tmp tmpDirectory := filepath.Join("/tmp", "user_"+txtid) errDir := os.MkdirAll(tmpDirectory, 0751) @@ -1179,10 +1186,12 @@ func (mycli *MyClient) myEventHandler(rawEvt interface{}) { } else { log.Info().Str("path", tmpPath).Msg("Temporary file deleted") } + }() } sticker := evt.Message.GetStickerMessage() if sticker != nil { + func() { tmpDirectory := filepath.Join("/tmp", "user_"+txtid) errDir := os.MkdirAll(tmpDirectory, 0751) if errDir != nil { @@ -1253,6 +1262,7 @@ func (mycli *MyClient) myEventHandler(rawEvt interface{}) { if err := os.Remove(tmpPath); err != nil { log.Error().Err(err).Msg("Failed to delete temporary file") } + }() } }