@@ -11,6 +11,7 @@ import (
1111 "crypto/hmac"
1212 "crypto/sha256"
1313 "encoding/base64"
14+ "encoding/json"
1415 "errors"
1516 "fmt"
1617 "io"
@@ -28,6 +29,7 @@ import (
2829 "go.mau.fi/whatsmeow/proto/waMediaTransport"
2930 "go.mau.fi/whatsmeow/proto/waServerSync"
3031 "go.mau.fi/whatsmeow/socket"
32+ "go.mau.fi/whatsmeow/types"
3133 "go.mau.fi/whatsmeow/util/cbcutil"
3234 "go.mau.fi/whatsmeow/util/hkdfutil"
3335)
8789 _ DownloadableMessage = (* waE2E .HistorySyncNotification )(nil )
8890 _ DownloadableMessage = (* waServerSync .ExternalBlobReference )(nil )
8991 _ DownloadableThumbnail = (* waE2E .ExtendedTextMessage )(nil )
92+ _ DownloadableMessage = (* types .StickerPackItem )(nil )
9093)
9194
9295type downloadableMessageWithLength interface {
@@ -191,15 +194,33 @@ func (cli *Client) DownloadThumbnail(ctx context.Context, msg DownloadableThumbn
191194
192195// GetMediaType returns the MediaType value corresponding to the given protobuf message.
193196func GetMediaType (msg DownloadableMessage ) MediaType {
194- protoReflecter , ok := msg .(proto.Message )
195- if ! ok {
196- mediaTypeable , ok := msg .(MediaTypeable )
197- if ! ok {
198- return ""
199- }
200- return mediaTypeable .GetMediaType ()
197+ switch typedMsg := msg .(type ) {
198+ case * types.StickerPackItem :
199+ return MediaImage
200+ case proto.Message :
201+ return classToMediaType [typedMsg .ProtoReflect ().Descriptor ().Name ()]
202+ case MediaTypeable :
203+ return typedMsg .GetMediaType ()
204+ default :
205+ return ""
206+ }
207+ }
208+
209+ func (cli * Client ) FetchStickerPack (ctx context.Context , packID string ) (* types.StickerPack , error ) {
210+ url := fmt .Sprintf ("https://static.whatsapp.net/sticker?lottie=1&cat=sticker_pack_data&id=%s&lg=en" , packID )
211+ resp , err := cli .doMediaDownloadRequest (ctx , url )
212+ if err != nil {
213+ return nil , err
214+ }
215+ var packs []types.StickerPack
216+ err = json .NewDecoder (resp .Body ).Decode (& packs )
217+ _ = resp .Body .Close ()
218+ if err != nil {
219+ return nil , fmt .Errorf ("failed to decode response: %w" , err )
220+ } else if len (packs ) == 0 {
221+ return nil , fmt .Errorf ("no sticker pack found in response" )
201222 }
202- return classToMediaType [ protoReflecter . ProtoReflect (). Descriptor (). Name ()]
223+ return & packs [ 0 ], nil
203224}
204225
205226// Download downloads the attachment from the given protobuf message.
0 commit comments