diff --git a/message.go b/message.go index f2fc413..d7d239b 100644 --- a/message.go +++ b/message.go @@ -1,7 +1,6 @@ package telebot import ( - "encoding/json" "strconv" "time" "unicode/utf16" @@ -720,33 +719,3 @@ type ReplyParams struct { // (Optional) Position of the quote in the original message in UTF-16 code units. QuotePosition int `json:"quote_position"` } - -// React changes the chosen reactions on a message. Service messages can't be -// reacted to. Automatically forwarded messages from a channel to its discussion group have -// the same available reactions as messages in the channel. -func (b *Bot) React(to Recipient, msg Editable, opts ...ReactionOptions) error { - if to == nil { - return ErrBadRecipient - } - msgID, _ := msg.MessageSig() - - params := map[string]string{ - "chat_id": to.Recipient(), - "message_id": msgID, - } - - if len(opts) > 0 { - opt := opts[0] - - if len(opt.Reactions) > 0 { - data, _ := json.Marshal(opt.Reactions) - params["reaction"] = string(data) - } - if opt.Big { - params["is_big"] = "true" - } - } - - _, err := b.Raw("setMessageReaction", params) - return err -} diff --git a/react.go b/react.go index 86f2431..7b01ca7 100644 --- a/react.go +++ b/react.go @@ -1,7 +1,8 @@ package telebot -// EmojiType defines emoji types. -type EmojiType = string +import ( + "encoding/json" +) // Reaction describes the type of reaction. // Describes an instance of ReactionTypeCustomEmoji and ReactionTypeEmoji. @@ -10,7 +11,7 @@ type Reaction struct { Type string `json:"type"` // Reaction emoji. - Emoji EmojiType `json:"emoji,omitempty"` + Emoji string `json:"emoji,omitempty"` // Custom emoji identifier. CustomEmoji string `json:"custom_emoji_id,omitempty"` @@ -34,3 +35,33 @@ type ReactionOptions struct { // Pass True to set the reaction with a big animation. Big bool `json:"is_big"` } + +// React changes the chosen reactions on a message. Service messages can't be +// reacted to. Automatically forwarded messages from a channel to its discussion group have +// the same available reactions as messages in the channel. +func (b *Bot) React(to Recipient, msg Editable, opts ...ReactionOptions) error { + if to == nil { + return ErrBadRecipient + } + msgID, _ := msg.MessageSig() + + params := map[string]string{ + "chat_id": to.Recipient(), + "message_id": msgID, + } + + if len(opts) > 0 { + opt := opts[0] + + if len(opt.Reactions) > 0 { + data, _ := json.Marshal(opt.Reactions) + params["reaction"] = string(data) + } + if opt.Big { + params["is_big"] = "true" + } + } + + _, err := b.Raw("setMessageReaction", params) + return err +} diff --git a/react/reaction.go b/react/react.go similarity index 95% rename from react/reaction.go rename to react/react.go index 07f1034..bfd4735 100644 --- a/react/reaction.go +++ b/react/react.go @@ -1,8 +1,14 @@ package react -import "gopkg.in/telebot.v3" +import ( + tele "gopkg.in/telebot.v3" +) + +type Reaction = tele.Reaction -type Reaction = telebot.Reaction +func React(r ...Reaction) tele.ReactionOptions { + return tele.ReactionOptions{Reactions: r} +} // Currently available emojis. var (