Skip to content

Commit

Permalink
stickers: implement custom emoji support
Browse files Browse the repository at this point in the history
  • Loading branch information
demget committed Oct 5, 2022
1 parent e40eb70 commit 8042463
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 12 deletions.
3 changes: 3 additions & 0 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ type MessageEntity struct {

// (Optional) For EntityCodeBlock entity type only.
Language string `json:"language,omitempty"`

// (Optional) For EntityCustomEmoji entity type only.
CustomEmoji string `json:"custom_emoji_id"`
}

// Entities is used to set message's text entities as a send option.
Expand Down
57 changes: 45 additions & 12 deletions stickers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,30 @@ import (
"strconv"
)

type StickerSetType = string

// StickerSet types.
const (
StickerRegular = "regular"
StickerMask = "mask"
StickerCustomEmoji = "custom_emoji"
)

// StickerSet represents a sticker set.
type StickerSet struct {
Name string `json:"name"`
Title string `json:"title"`
Animated bool `json:"is_animated"`
Video bool `json:"is_video"`
Stickers []Sticker `json:"stickers"`
Thumbnail *Photo `json:"thumb"`
PNG *File `json:"png_sticker"`
TGS *File `json:"tgs_sticker"`
WebM *File `json:"webm_sticker"`
Emojis string `json:"emojis"`
ContainsMasks bool `json:"contains_masks"`
MaskPosition *MaskPosition `json:"mask_position"`
Type StickerSetType `json:"sticker_type"`
Name string `json:"name"`
Title string `json:"title"`
Animated bool `json:"is_animated"`
Video bool `json:"is_video"`
Stickers []Sticker `json:"stickers"`
Thumbnail *Photo `json:"thumb"`
PNG *File `json:"png_sticker"`
TGS *File `json:"tgs_sticker"`
WebM *File `json:"webm_sticker"`
Emojis string `json:"emojis"`
ContainsMasks bool `json:"contains_masks"` // FIXME: can be removed
MaskPosition *MaskPosition `json:"mask_position"`
}

// MaskPosition describes the position on faces where
Expand Down Expand Up @@ -84,6 +94,7 @@ func (b *Bot) CreateStickerSet(to Recipient, s StickerSet) error {

params := map[string]string{
"user_id": to.Recipient(),
"sticker_type": s.Type,
"name": s.Name,
"title": s.Title,
"emojis": s.Emojis,
Expand Down Expand Up @@ -168,3 +179,25 @@ func (b *Bot) SetStickerSetThumb(to Recipient, s StickerSet) error {
_, err := b.sendFiles("setStickerSetThumb", files, params)
return err
}

// CustomEmojiStickers returns the information about custom emoji stickers by their ids.
func (b *Bot) CustomEmojiStickers(ids []string) ([]Sticker, error) {
data, _ := json.Marshal(ids)

params := map[string]string{
"custom_emoji_ids": string(data),
}

data, err := b.Raw("getCustomEmojiStickers", params)
if err != nil {
return nil, err
}

var resp struct {
Result []Sticker
}
if err := json.Unmarshal(data, &resp); err != nil {
return nil, wrapError(err)
}
return resp.Result, nil
}
1 change: 1 addition & 0 deletions telebot.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ const (
EntityCodeBlock EntityType = "pre"
EntityTextLink EntityType = "text_link"
EntitySpoiler EntityType = "spoiler"
EntityCustomEmoji EntityType = "custom_emoji"
)

// ChatType represents one of the possible chat types.
Expand Down

0 comments on commit 8042463

Please sign in to comment.