-
Notifications
You must be signed in to change notification settings - Fork 4
/
updatingMessages.go
280 lines (251 loc) · 10.8 KB
/
updatingMessages.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
package telegrambot
// https://core.telegram.org/bots/api#updating-messages
import "fmt"
type EditMessageTextParams struct {
// Optional. Required if inline_message_id is not specified. Unique
// identifier for the target chat or username of the target channel (in the
// format @channelusername)
ChatID ChatIDOrUsername `json:"chat_id,omitempty"`
// Optional. Required if inline_message_id is not specified. Identifier of
// the message to edit
MessageID MessageID `json:"message_id,omitempty"`
// Optional. Required if chat_id and message_id are not specified.
// Identifier of the inline message
InlineMessageID InlineMessageID `json:"inline_message_id,omitempty"`
// New text of the message, 1-4096 characters after entities parsing
Text string `json:"text"`
// Optional. Mode for parsing entities in the message text. See formatting
// options for more details.
ParseMode ParseMode `json:"parse_mode,omitempty"`
// Optional. A JSON-serialized list of special entities that appear in
// message text, which can be specified instead of parse_mode
Entities []*MessageEntity `json:"entities,omitempty"`
// Optional. Disables link previews for links in this message
DisableWebPagePreview bool `json:"disable_web_page_preview,omitempty"`
// Optional. A JSON-serialized object for an inline keyboard.
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
}
// Use this method to edit text and game messages. On success, if the edited
// message is not an inline message, the edited Message is returned, otherwise
// True is returned. https://core.telegram.org/bots/api#games
// https://core.telegram.org/bots/api#message
//
// https://core.telegram.org/bots/api#editmessagetext
func (api *API) EditMessageText(params *EditMessageTextParams) (*Message, error) {
var msg *Message
if params.InlineMessageID != "" {
msg = &Message{}
}
migrateToChatID, err := api.makeAPICall("editMessageText", params, nil, msg)
if err != nil {
if migrateToChatID != 0 {
params.ChatID = migrateToChatID
_, err = api.makeAPICall("editMessageText", params, nil, msg)
if err != nil {
return nil, fmt.Errorf("EditMessageText: %w", err)
}
} else {
return nil, fmt.Errorf("EditMessageText: %w", err)
}
}
return msg, nil
}
type EditMessageCaptionParams struct {
// Optional. Required if inline_message_id is not specified. Unique
// identifier for the target chat or username of the target channel (in the
// format @channelusername)
ChatID ChatIDOrUsername `json:"chat_id,omitempty"`
// Optional. Required if inline_message_id is not specified. Identifier of
// the message to edit
MessageID MessageID `json:"message_id,omitempty"`
// Optional. Required if chat_id and message_id are not specified.
// Identifier of the inline message
InlineMessageID InlineMessageID `json:"inline_message_id,omitempty"`
// Optional. New caption of the message, 0-1024 characters after entities
// parsing
Caption string `json:"caption,omitempty"`
// Optional. Mode for parsing entities in the message caption. See
// formatting options for more details.
// https://core.telegram.org/bots/api#formatting-options
ParseMode ParseMode `json:"parse_mode,omitempty"`
// Optional. A JSON-serialized list of special entities that appear in the
// caption, which can be specified instead of parse_mode
CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"`
// Optional. A JSON-serialized object for an inline keyboard.
// https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
}
// Use this method to edit captions of messages. On success, if the edited
// message is not an inline message, the edited Message is returned, otherwise
// True is returned. https://core.telegram.org/bots/api#message
//
// https://core.telegram.org/bots/api#editmessagecaption
func (api *API) EditMessageCaption(params *EditMessageCaptionParams) (*Message, error) {
var msg *Message
if params.InlineMessageID != "" {
msg = &Message{}
}
migrateToChatID, err := api.makeAPICall("editMessageCaption", params, nil, msg)
if err != nil {
if migrateToChatID != 0 {
params.ChatID = migrateToChatID
_, err = api.makeAPICall("editMessageCaption", params, nil, msg)
if err != nil {
return nil, fmt.Errorf("EditMessageCaption: %w", err)
}
} else {
return nil, fmt.Errorf("EditMessageCaption: %w", err)
}
}
return msg, nil
}
type EditMessageMediaParams struct {
// Optional. Required if inline_message_id is not specified. Unique
// identifier for the target chat or username of the target channel (in the
// format @channelusername)
ChatID ChatIDOrUsername `json:"chat_id,omitempty"`
// Optional. Required if inline_message_id is not specified. Identifier of
// the message to edit
MessageID MessageID `json:"message_id,omitempty"`
// Optional. Required if chat_id and message_id are not specified.
// Identifier of the inline message
InlineMessageID InlineMessageID `json:"inline_message_id,omitempty"`
// A JSON-serialized object for a new media content of the message
Media *InputMedia `json:"media"`
// Optional. A JSON-serialized object for a new inline keyboard.
// https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
}
// Use this method to edit animation, audio, document, photo, or video messages.
// If a message is part of a message album, then it can be edited only to an
// audio for audio albums, only to a document for document albums and to a photo
// or a video otherwise. When an inline message is edited, a new file can't be
// uploaded; use a previously uploaded file via its file_id or specify a URL. On
// success, if the edited message is not an inline message, the edited Message
// is returned, otherwise True is returned.
// https://core.telegram.org/bots/api#message
//
// https://core.telegram.org/bots/api#editmessagemedia
func (api *API) EditMessageMedia(params *EditMessageMediaParams) (*Message, error) {
var msg *Message
if params.InlineMessageID != "" {
msg = &Message{}
}
migrateToChatID, err := api.makeAPICall("editMessageMedia", params, []InputFile{params.Media.Media, params.Media.Thumb}, msg)
if err != nil {
if migrateToChatID != 0 {
params.ChatID = migrateToChatID
_, err = api.makeAPICall("editMessageMedia", params, []InputFile{params.Media.Media, params.Media.Thumb}, msg)
if err != nil {
return nil, fmt.Errorf("EditMessageMedia: %w", err)
}
} else {
return nil, fmt.Errorf("EditMessageMedia: %w", err)
}
}
return msg, nil
}
type EditMessageReplyMarkupParams struct {
// Optional. Required if inline_message_id is not specified. Unique
// identifier for the target chat or username of the target channel (in the
// format @channelusername)
ChatID ChatIDOrUsername `json:"chat_id,omitempty"`
// Optional. Required if inline_message_id is not specified. Identifier of
// the message to edit
MessageID MessageID `json:"message_id,omitempty"`
// Optional. Required if chat_id and message_id are not specified.
// Identifier of the inline message
InlineMessageID InlineMessageID `json:"inline_message_id,omitempty"`
// Optional. A JSON-serialized object for an inline keyboard.
// https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
}
// Use this method to edit only the reply markup of messages. On success, if the
// edited message is not an inline message, the edited Message is returned,
// otherwise True is returned. https://core.telegram.org/bots/api#message
//
// https://core.telegram.org/bots/api#editmessagereplymarkup
func (api *API) EditMessageReplyMarkup(params *EditMessageReplyMarkupParams) (*Message, error) {
var msg *Message
if params.InlineMessageID != "" {
msg = &Message{}
}
migrateToChatID, err := api.makeAPICall("editMessageReplyMarkup", params, nil, msg)
if err != nil {
if migrateToChatID != 0 {
params.ChatID = migrateToChatID
_, err = api.makeAPICall("editMessageReplyMarkup", params, nil, msg)
if err != nil {
return nil, fmt.Errorf("EditMessageReplyMarkup: %w", err)
}
} else {
return nil, fmt.Errorf("EditMessageReplyMarkup: %w", err)
}
}
return msg, nil
}
type StopPollParams struct {
// Unique identifier for the target chat or username of the target channel
// (in the format @channelusername)
ChatID ChatIDOrUsername `json:"chat_id"`
// Identifier of the original message with the poll
MessageID MessageID `json:"message_id"`
// Optional. A JSON-serialized object for a new message inline keyboard.
// https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
}
// Use this method to stop a poll which was sent by the bot. On success, the
// stopped Poll is returned. https://core.telegram.org/bots/api#poll
//
// https://core.telegram.org/bots/api#stoppoll
func (api *API) StopPoll(params *StopPollParams) (*Poll, error) {
poll := &Poll{}
migrateToChatID, err := api.makeAPICall("stopPoll", params, nil, poll)
if err != nil {
if migrateToChatID != 0 {
params.ChatID = migrateToChatID
_, err = api.makeAPICall("stopPoll", params, nil, poll)
if err != nil {
return nil, fmt.Errorf("StopPoll: %w", err)
}
} else {
return nil, fmt.Errorf("StopPoll: %w", err)
}
}
return poll, nil
}
type DeleteMessageParams struct {
// Unique identifier for the target chat or username of the target channel
// (in the format @channelusername)
ChatID ChatIDOrUsername `json:"chat_id"`
// Identifier of the message to delete
MessageID MessageID `json:"message_id"`
}
// Use this method to delete a message, including service messages, with the
// following limitations:
// - A message can only be deleted if it was sent less than 48 hours ago.
// - A dice message in a private chat can only be deleted if it was sent more than 24 hours ago.
// - Bots can delete outgoing messages in private chats, groups, and supergroups.
// - Bots can delete incoming messages in private chats.
// - Bots granted can_post_messages permissions can delete outgoing messages in channels.
// - If the bot is an administrator of a group, it can delete any message there.
// - If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there.
//
// Returns True on success.
//
// https://core.telegram.org/bots/api#deletemessage
func (api *API) DeleteMessage(params *DeleteMessageParams) error {
migrateToChatID, err := api.makeAPICall("deleteMessage", params, nil, nil)
if err != nil {
if migrateToChatID != 0 {
params.ChatID = migrateToChatID
_, err = api.makeAPICall("deleteMessage", params, nil, nil)
if err != nil {
return fmt.Errorf("DeleteMessage: %w", err)
}
} else {
return fmt.Errorf("DeleteMessage: %w", err)
}
}
return nil
}