-
Notifications
You must be signed in to change notification settings - Fork 469
/
react.go
67 lines (53 loc) · 1.63 KB
/
react.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package telebot
import (
"encoding/json"
)
const (
ReactionTypeEmoji = "emoji"
ReactionTypeCustomEmoji = "custom_emoji"
)
// Reaction describes the type of reaction.
// Describes an instance of ReactionTypeCustomEmoji and ReactionTypeEmoji.
type Reaction struct {
// Type of the reaction, always “emoji”
Type string `json:"type"`
// Reaction emoji.
Emoji string `json:"emoji,omitempty"`
// Custom emoji identifier.
CustomEmojiID string `json:"custom_emoji_id,omitempty"`
}
// ReactionCount represents a reaction added to a message along
// with the number of times it was added.
type ReactionCount struct {
// Type of the reaction.
Type Reaction `json:"type"`
// Number of times the reaction was added.
Count int `json:"total_count"`
}
// Reactions represents an object of reaction options.
type Reactions struct {
// List of reaction types to set on the message.
Reactions []Reaction `json:"reaction"`
// 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, r Reactions) error {
if to == nil {
return ErrBadRecipient
}
msgID, _ := msg.MessageSig()
params := map[string]string{
"chat_id": to.Recipient(),
"message_id": msgID,
}
data, _ := json.Marshal(r.Reactions)
params["reaction"] = string(data)
if r.Big {
params["is_big"] = "true"
}
_, err := b.Raw("setMessageReaction", params)
return err
}