forked from go-telegram-bot-api/telegram-bot-api
-
Notifications
You must be signed in to change notification settings - Fork 48
/
helper_structs.go
141 lines (117 loc) · 3.38 KB
/
helper_structs.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package tgbotapi
// ChatConfig is a base type for all chat identifiers
type ChatConfig struct {
ChatID int64
ChannelUsername string
SuperGroupUsername string
}
func (base ChatConfig) params() (Params, error) {
return base.paramsWithKey("chat_id")
}
func (base ChatConfig) paramsWithKey(key string) (Params, error) {
params := make(Params)
return params, params.AddFirstValid(key, base.ChatID, base.ChannelUsername, base.SuperGroupUsername)
}
// BaseChat is base type for all chat config types.
type BaseChat struct {
ChatConfig
BusinessConnectionID BusinessConnectionID
MessageThreadID int
ProtectContent bool
ReplyMarkup interface{}
DisableNotification bool
MessageEffectID string // for private chats only
ReplyParameters ReplyParameters
}
func (chat *BaseChat) params() (Params, error) {
params, err := chat.ChatConfig.params()
if err != nil {
return params, err
}
p1, err := chat.BusinessConnectionID.params()
if err != nil {
return params, err
}
params.Merge(p1)
params.AddNonZero("message_thread_id", chat.MessageThreadID)
params.AddBool("disable_notification", chat.DisableNotification)
params.AddBool("protect_content", chat.ProtectContent)
params.AddNonEmpty("message_effect_id", chat.MessageEffectID)
err = params.AddInterface("reply_markup", chat.ReplyMarkup)
if err != nil {
return params, err
}
err = params.AddInterface("reply_parameters", chat.ReplyParameters)
return params, err
}
// BaseFile is a base type for all file config types.
type BaseFile struct {
BaseChat
File RequestFileData
}
func (file BaseFile) params() (Params, error) {
return file.BaseChat.params()
}
// BaseEdit is base type of all chat edits.
type BaseEdit struct {
BaseChatMessage
InlineMessageID string
ReplyMarkup *InlineKeyboardMarkup
}
func (edit BaseEdit) params() (Params, error) {
params := make(Params)
if edit.InlineMessageID != "" {
params["inline_message_id"] = edit.InlineMessageID
} else {
p1, err := edit.BaseChatMessage.params()
if err != nil {
return params, err
}
params.Merge(p1)
}
err := params.AddInterface("reply_markup", edit.ReplyMarkup)
return params, err
}
// BaseSpoiler is base type of structures with spoilers.
type BaseSpoiler struct {
HasSpoiler bool
}
func (spoiler BaseSpoiler) params() (Params, error) {
params := make(Params)
if spoiler.HasSpoiler {
params.AddBool("has_spoiler", true)
}
return params, nil
}
// BaseChatMessage is a base type for all messages in chats.
type BaseChatMessage struct {
ChatConfig
MessageID int
BusinessConnectionID BusinessConnectionID
}
func (base BaseChatMessage) params() (Params, error) {
params, err := base.ChatConfig.params()
if err != nil {
return params, err
}
p1, err := base.BusinessConnectionID.params()
if err != nil {
return params, err
}
params.Merge(p1)
params.AddNonZero("message_id", base.MessageID)
return params, err
}
// BaseChatMessages is a base type for all messages in chats.
type BaseChatMessages struct {
ChatConfig
MessageIDs []int
}
func (base BaseChatMessages) params() (Params, error) {
params, err := base.ChatConfig.params()
if err != nil {
return params, err
}
err = params.AddInterface("message_ids", base.MessageIDs)
return params, err
}