Skip to content

Commit

Permalink
msgconv/from-whatsapp: extract lottie stickers when bridging
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Sep 17, 2024
1 parent a47ed7f commit 6e98f25
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/msgconv/from-whatsapp.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package msgconv

import (
"archive/zip"
"bytes"
"context"
"fmt"
Expand Down Expand Up @@ -43,6 +44,7 @@ type MediaInfo struct {
FileName string
Waveform []int
IsGif bool
IsSticker bool
Caption string
MsgType event.MessageType
ContextInfo *waE2E.ContextInfo
Expand Down Expand Up @@ -73,6 +75,7 @@ func getMediaMessageFileInfo(msg *waE2E.Message) (message MediaMessage, info Med

info.Width = int(msg.StickerMessage.GetWidth())
info.Height = int(msg.StickerMessage.GetHeight())
info.IsSticker = true
} else if msg.VideoMessage != nil {
info.MsgType = event.MsgVideo
message = msg.VideoMessage
Expand Down Expand Up @@ -206,6 +209,23 @@ func (mc *MessageConverter) reuploadWhatsAppAttachment(
if err != nil {
return nil, fmt.Errorf("%w: %w", bridgev2.ErrMediaDownloadFailed, err)
}
if fileInfo.IsSticker && fileInfo.MimeType == "application/was" {
zipReader, err := zip.NewReader(bytes.NewReader(data), int64(len(data)))
if err != nil {
return nil, fmt.Errorf("failed to read sticker zip: %w", err)
}
animationFile, err := zipReader.Open("animation/animation.json")
if err != nil {
return nil, fmt.Errorf("failed to open animation.json: %w", err)
}
data, err = io.ReadAll(animationFile)
_ = animationFile.Close()
if err != nil {
return nil, fmt.Errorf("failed to read animation.json: %w", err)
}
fileInfo.MimeType = "image/lottie+json"
fileInfo.FileName = "sticker.json"
}
if fileInfo.MimeType == "" {
fileInfo.MimeType = http.DetectContentType(data)
}
Expand Down

0 comments on commit 6e98f25

Please sign in to comment.