This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathupdating_messages.go
221 lines (170 loc) Β· 7.59 KB
/
updating_messages.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
package telegram
type (
// EditMessageTextParameters represents data for EditMessageText method.
EditMessageText struct {
ChatID ChatID `json:"chat_id,omitempty"`
// Required if inline_message_id is not specified. Identifier of the sent message
MessageID int64 `json:"message_id,omitempty"`
// Required if chat_id and message_id are not specified. Identifier of the inline message
InlineMessageID string `json:"inline_message_id,omitempty"`
// New text of the message
Text string `json:"text"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message.
ParseMode string `json:"parse_mode,omitempty"`
// List of special entities that appear in the caption, which can be specified instead of parse_mode
Entities []*MessageEntity `json:"entities,omitempty"`
// Disables link previews for links in this message
DisableWebPagePreview bool `json:"disable_web_page_preview,omitempty"`
// A JSON-serialized object for an inline keyboard.
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
}
// EditMessageCaptionParameters represents data for EditMessageCaption method.
EditMessageCaption struct {
ChatID ChatID `json:"chat_id,omitempty"`
// Required if inline_message_id is not specified. Identifier of the sent message
MessageID int64 `json:"message_id,omitempty"`
// Required if chat_id and message_id are not specified. Identifier of the inline message
InlineMessageID string `json:"inline_message_id,omitempty"`
// New caption of the message
Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"`
// List of special entities that appear in the caption, which can be specified instead of parse_mode
CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"`
// A JSON-serialized object for an inline keyboard.
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
}
// EditMessageMediaParameters represents data for EditMessageMedia method.
EditMessageMedia struct {
ChatID ChatID `json:"chat_id,omitempty"`
// Required if inline_message_id is not specified. Identifier of the sent message
MessageID int64 `json:"message_id,omitempty"`
// Required if chat_id and message_id are not specified. Identifier of the inline message
InlineMessageID string `json:"inline_message_id,omitempty"`
// A JSON-serialized object for a new media content of the message
Media InputMedia `json:"media"`
// A JSON-serialized object for a new inline keyboard.
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
}
// EditMessageReplyMarkupParameters represents data for EditMessageReplyMarkup method.
EditMessageReplyMarkup struct {
ChatID ChatID `json:"chat_id,omitempty"`
// Required if inline_message_id is not specified. Identifier of the sent message
MessageID int64 `json:"message_id,omitempty"`
// Required if chat_id and message_id are not specified. Identifier of the inline message
InlineMessageID string `json:"inline_message_id,omitempty"`
// A JSON-serialized object for an inline keyboard.
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
}
StopPoll struct {
ChatID ChatID `json:"chat_id"`
// Identifier of the original message with the poll
MessageID int64 `json:"message_id"`
// A JSON-serialized object for a new message inline keyboard.
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
}
// DeleteMessageParameters represents data for DeleteMessage method.
DeleteMessage struct {
ChatID ChatID `json:"chat_id"`
// Identifier of the message to delete
MessageID int64 `json:"message_id"`
}
)
func NewEditText(text string) EditMessageText {
return EditMessageText{Text: text}
}
// EditMessageText edit text and game messages sent by the bot or via the bot (for inline bots). On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
func (b Bot) EditMessageText(p EditMessageText) (*Message, error) {
src, err := b.Do(MethodEditMessageText, p)
if err != nil {
return nil, err
}
result := new(Message)
if err = parseResponseError(b.marshler, src, result); err != nil {
return nil, err
}
return result, nil
}
// EditMessageCaption edit captions of messages sent by the bot or via the bot (for inline bots). On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
func (b Bot) EditMessageCaption(p EditMessageCaption) (*Message, error) {
src, err := b.Do(MethodEditMessageCaption, p)
if err != nil {
return nil, err
}
result := new(Message)
if err = parseResponseError(b.marshler, src, result); err != nil {
return nil, err
}
return result, nil
}
func NewEditMedia(media InputMedia) EditMessageMedia {
return EditMessageMedia{
Media: media,
}
}
// EditMessageMedia edit audio, document, photo, or video messages. If a message is a part of a message album, then it can be edited only to a photo or a video. Otherwise, message type can be changed arbitrarily. When inline message is edited, new file can't be uploaded. Use previously uploaded file via its file_id or specify a URL. On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned.
func (b Bot) EditMessageMedia(p EditMessageMedia) (*Message, error) {
src, err := b.Do(MethodEditMessageMedia, p)
if err != nil {
return nil, err
}
result := new(Message)
if err = parseResponseError(b.marshler, src, result); err != nil {
return nil, err
}
return result, nil
}
// EditMessageReplyMarkup edit only the reply markup of messages sent by the bot or via the bot (for inline bots). On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
func (b Bot) EditMessageReplyMarkup(p EditMessageReplyMarkup) (*Message, error) {
src, err := b.Do(MethodEditMessageReplyMarkup, p)
if err != nil {
return nil, err
}
result := new(Message)
if err = parseResponseError(b.marshler, src, result); err != nil {
return nil, err
}
return result, nil
}
func NewStopPoll(chatID ChatID, messageID int64) StopPoll {
return StopPoll{
ChatID: chatID,
MessageID: messageID,
}
}
// StopPoll stop a poll which was sent by the bot. On success, the stopped Poll with the final results is returned.
func (b Bot) StopPoll(p StopPoll) (*Poll, error) {
src, err := b.Do(MethodStopPoll, p)
if err != nil {
return nil, err
}
result := new(Poll)
if err = parseResponseError(b.marshler, src, result); err != nil {
return nil, err
}
return result, nil
}
// DeleteMessage 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.
// - 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.
func (b Bot) DeleteMessage(p DeleteMessage) (ok bool, err error) {
src, err := b.Do(MethodDeleteMessage, p)
if err != nil {
return ok, err
}
resp := new(Response)
if err = b.marshler.Unmarshal(src, resp); err != nil {
return
}
if err = b.marshler.Unmarshal(resp.Result, &ok); err != nil {
return
}
return
}