fix(sticker): send animated WebP stickers as-is (skip static re-encode) - #151
Open
nicolasnovis wants to merge 1 commit into
Open
fix(sticker): send animated WebP stickers as-is (skip static re-encode)#151nicolasnovis wants to merge 1 commit into
nicolasnovis wants to merge 1 commit into
Conversation
SendSticker always ran convertToWebP (image.Decode + static webp.Encode), which fails on animated WebP (webpDecodeRGBA: failed) and would flatten it to one frame anyway. Now: download the sticker, and if it's already WebP (RIFF/WEBP magic), upload it UNTOUCHED and set StickerMessage.IsAnimated when the VP8X animation flag (or ANIM chunk) is present; only re-encode non-WebP sources. Static WebP stickers also stop losing quality. No route/struct/JSON-contract change.
Reviewer's GuideRefactors sticker sending to avoid re-encoding existing WebP data, properly handle animated WebP stickers, and simplify the upload path, while explicitly setting WebP mimetype and animation flag. Sequence diagram for updated SendSticker WebP handlingsequenceDiagram
actor User
participant sendService
participant HTTPServer
participant WhatsAppClient as whatsmeowClient
participant waE2E as waE2EMessage
User->>sendService: SendSticker(data, instance)
sendService->>sendService: ensureClientConnected(instance.Id)
sendService->>HTTPServer: http.Get(data.Sticker)
HTTPServer-->>sendService: *resp.Body*
sendService->>sendService: io.ReadAll(resp.Body)
alt isWebP(raw)
sendService->>sendService: isWebP(raw)
sendService->>sendService: isAnimatedWebP(raw)
note over sendService: filedata = raw
else nonWebP
sendService->>sendService: convertBytesToWebP(raw)
note over sendService: filedata = converted WebP
end
sendService->>WhatsAppClient: Upload(context.Background(), filedata, whatsmeow.MediaImage)
WhatsAppClient-->>sendService: UploadResponse
sendService->>waE2E: new StickerMessage
note over waE2E: Mimetype = image/webp
alt isAnimated == true
note over waE2E: IsAnimated = true
end
sendService->>sendService: SendMessage(instance, Message, "StickerMessage", SendDataStruct)
sendService-->>User: MessageSendStruct
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:
- Consider using an HTTP client with timeouts and/or the existing request context instead of bare
http.Get, so sticker fetches can’t hang indefinitely and can be cancelled along with the send operation. - The WebP detection helpers currently convert header slices to strings; you could avoid unnecessary allocations and be more explicit by using byte comparisons (e.g.
bytes.Equal(data[0:4], []byte("RIFF"))) for magic and chunk IDs.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider using an HTTP client with timeouts and/or the existing request context instead of bare `http.Get`, so sticker fetches can’t hang indefinitely and can be cancelled along with the send operation.
- The WebP detection helpers currently convert header slices to strings; you could avoid unnecessary allocations and be more explicit by using byte comparisons (e.g. `bytes.Equal(data[0:4], []byte("RIFF"))`) for magic and chunk IDs.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.
SendStickeralways runsconvertToWebP, which decodes the image viawebpDecodeRGBAand fails on animated WebP (webpDecodeRGBA: failed), so sending an animated sticker errors out.This uploads the sticker untouched when it is already WebP (skipping the lossy re-encode), detects animation (VP8X animation flag /
ANIMchunk) and setsIsAnimatedaccordingly, and pins the mimetype toimage/webp. Static and animated WebP stickers both send correctly; non-WebP inputs still go throughconvertToWebPas before.Tested in production against WhatsApp with both static and animated
.webpstickers.Summary by Sourcery
Handle sending WebP stickers by uploading existing WebP data untouched, only re-encoding non-WebP sources to WebP, and correctly marking animated stickers.
Bug Fixes:
Enhancements: