/
messages.go
executable file
·347 lines (284 loc) · 16.8 KB
/
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
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
// AUTOGENERATED - DO NOT EDIT
package client
import (
"encoding/json"
"github.com/Arman92/go-tdlib/v2/tdlib"
)
// GetMessages Returns information about messages. If a message is not found, returns null on the corresponding position of the result
// @param chatID Identifier of the chat the messages belong to
// @param messageIDs Identifiers of the messages to get
func (client *Client) GetMessages(chatID int64, messageIDs []int64) (*tdlib.Messages, error) {
result, err := client.SendAndCatch(tdlib.UpdateData{
"@type": "getMessages",
"chat_id": chatID,
"message_ids": messageIDs,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, tdlib.RequestError{Code: int(result.Data["code"].(float64)), Message: result.Data["message"].(string)}
}
var messages tdlib.Messages
err = json.Unmarshal(result.Raw, &messages)
return &messages, err
}
// GetChatHistory Returns messages in a chat. The messages are returned in a reverse chronological order (i.e., in order of decreasing message_id). For optimal performance, the number of returned messages is chosen by TDLib. This is an offline request if only_local is true
// @param chatID Chat identifier
// @param fromMessageID Identifier of the message starting from which history must be fetched; use 0 to get results from the last message
// @param offset Specify 0 to get results from exactly the from_message_id or a negative offset up to 99 to get additionally some newer messages
// @param limit The maximum number of messages to be returned; must be positive and can't be greater than 100. If the offset is negative, the limit must be greater than or equal to -offset. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
// @param onlyLocal If true, returns only messages that are available locally without sending network requests
func (client *Client) GetChatHistory(chatID int64, fromMessageID int64, offset int32, limit int32, onlyLocal bool) (*tdlib.Messages, error) {
result, err := client.SendAndCatch(tdlib.UpdateData{
"@type": "getChatHistory",
"chat_id": chatID,
"from_message_id": fromMessageID,
"offset": offset,
"limit": limit,
"only_local": onlyLocal,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, tdlib.RequestError{Code: int(result.Data["code"].(float64)), Message: result.Data["message"].(string)}
}
var messages tdlib.Messages
err = json.Unmarshal(result.Raw, &messages)
return &messages, err
}
// GetMessageThreadHistory Returns messages in a message thread of a message. Can be used only if message.can_get_message_thread == true. Message thread of a channel message is in the channel's linked supergroup. The messages are returned in a reverse chronological order (i.e., in order of decreasing message_id). For optimal performance, the number of returned messages is chosen by TDLib
// @param chatID Chat identifier
// @param messageID Message identifier, which thread history needs to be returned
// @param fromMessageID Identifier of the message starting from which history must be fetched; use 0 to get results from the last message
// @param offset Specify 0 to get results from exactly the from_message_id or a negative offset up to 99 to get additionally some newer messages
// @param limit The maximum number of messages to be returned; must be positive and can't be greater than 100. If the offset is negative, the limit must be greater than or equal to -offset. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
func (client *Client) GetMessageThreadHistory(chatID int64, messageID int64, fromMessageID int64, offset int32, limit int32) (*tdlib.Messages, error) {
result, err := client.SendAndCatch(tdlib.UpdateData{
"@type": "getMessageThreadHistory",
"chat_id": chatID,
"message_id": messageID,
"from_message_id": fromMessageID,
"offset": offset,
"limit": limit,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, tdlib.RequestError{Code: int(result.Data["code"].(float64)), Message: result.Data["message"].(string)}
}
var messages tdlib.Messages
err = json.Unmarshal(result.Raw, &messages)
return &messages, err
}
// SearchChatMessages Searches for messages with given words in the chat. Returns the results in reverse chronological order, i.e. in order of decreasing message_id. Cannot be used in secret chats with a non-empty query (searchSecretMessages should be used instead), or without an enabled message database. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
// @param chatID Identifier of the chat in which to search messages
// @param query Query to search for
// @param sender If not null, only messages sent by the specified sender will be returned. Not supported in secret chats
// @param fromMessageID Identifier of the message starting from which history must be fetched; use 0 to get results from the last message
// @param offset Specify 0 to get results from exactly the from_message_id or a negative offset to get the specified message and some newer messages
// @param limit The maximum number of messages to be returned; must be positive and can't be greater than 100. If the offset is negative, the limit must be greater than -offset. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
// @param filter Filter for message content in the search results
// @param messageThreadID If not 0, only messages in the specified thread will be returned; supergroups only
func (client *Client) SearchChatMessages(chatID int64, query string, sender tdlib.MessageSender, fromMessageID int64, offset int32, limit int32, filter tdlib.SearchMessagesFilter, messageThreadID int64) (*tdlib.Messages, error) {
result, err := client.SendAndCatch(tdlib.UpdateData{
"@type": "searchChatMessages",
"chat_id": chatID,
"query": query,
"sender": sender,
"from_message_id": fromMessageID,
"offset": offset,
"limit": limit,
"filter": filter,
"message_thread_id": messageThreadID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, tdlib.RequestError{Code: int(result.Data["code"].(float64)), Message: result.Data["message"].(string)}
}
var messages tdlib.Messages
err = json.Unmarshal(result.Raw, &messages)
return &messages, err
}
// SearchMessages Searches for messages in all chats except secret chats. Returns the results in reverse chronological order (i.e., in order of decreasing (date, chat_id, message_id)). For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
// @param chatList Chat list in which to search messages; pass null to search in all chats regardless of their chat list. Only Main and Archive chat lists are supported
// @param query Query to search for
// @param offsetDate The date of the message starting from which the results should be fetched. Use 0 or any date in the future to get results from the last message
// @param offsetChatID The chat identifier of the last found message, or 0 for the first request
// @param offsetMessageID The message identifier of the last found message, or 0 for the first request
// @param limit The maximum number of messages to be returned; up to 100. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
// @param filter Filter for message content in the search results; searchMessagesFilterCall, searchMessagesFilterMissedCall, searchMessagesFilterMention, searchMessagesFilterUnreadMention, searchMessagesFilterFailedToSend and searchMessagesFilterPinned are unsupported in this function
// @param minDate If not 0, the minimum date of the messages to return
// @param maxDate If not 0, the maximum date of the messages to return
func (client *Client) SearchMessages(chatList tdlib.ChatList, query string, offsetDate int32, offsetChatID int64, offsetMessageID int64, limit int32, filter tdlib.SearchMessagesFilter, minDate int32, maxDate int32) (*tdlib.Messages, error) {
result, err := client.SendAndCatch(tdlib.UpdateData{
"@type": "searchMessages",
"chat_list": chatList,
"query": query,
"offset_date": offsetDate,
"offset_chat_id": offsetChatID,
"offset_message_id": offsetMessageID,
"limit": limit,
"filter": filter,
"min_date": minDate,
"max_date": maxDate,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, tdlib.RequestError{Code: int(result.Data["code"].(float64)), Message: result.Data["message"].(string)}
}
var messages tdlib.Messages
err = json.Unmarshal(result.Raw, &messages)
return &messages, err
}
// SearchCallMessages Searches for call messages. Returns the results in reverse chronological order (i. e., in order of decreasing message_id). For optimal performance, the number of returned messages is chosen by TDLib
// @param fromMessageID Identifier of the message from which to search; use 0 to get results from the last message
// @param limit The maximum number of messages to be returned; up to 100. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
// @param onlyMissed If true, returns only messages with missed calls
func (client *Client) SearchCallMessages(fromMessageID int64, limit int32, onlyMissed bool) (*tdlib.Messages, error) {
result, err := client.SendAndCatch(tdlib.UpdateData{
"@type": "searchCallMessages",
"from_message_id": fromMessageID,
"limit": limit,
"only_missed": onlyMissed,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, tdlib.RequestError{Code: int(result.Data["code"].(float64)), Message: result.Data["message"].(string)}
}
var messages tdlib.Messages
err = json.Unmarshal(result.Raw, &messages)
return &messages, err
}
// SearchChatRecentLocationMessages Returns information about the recent locations of chat members that were sent to the chat. Returns up to 1 location message per user
// @param chatID Chat identifier
// @param limit The maximum number of messages to be returned
func (client *Client) SearchChatRecentLocationMessages(chatID int64, limit int32) (*tdlib.Messages, error) {
result, err := client.SendAndCatch(tdlib.UpdateData{
"@type": "searchChatRecentLocationMessages",
"chat_id": chatID,
"limit": limit,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, tdlib.RequestError{Code: int(result.Data["code"].(float64)), Message: result.Data["message"].(string)}
}
var messages tdlib.Messages
err = json.Unmarshal(result.Raw, &messages)
return &messages, err
}
// GetActiveLiveLocationMessages Returns all active live locations that should be updated by the application. The list is persistent across application restarts only if the message database is used
func (client *Client) GetActiveLiveLocationMessages() (*tdlib.Messages, error) {
result, err := client.SendAndCatch(tdlib.UpdateData{
"@type": "getActiveLiveLocationMessages",
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, tdlib.RequestError{Code: int(result.Data["code"].(float64)), Message: result.Data["message"].(string)}
}
var messages tdlib.Messages
err = json.Unmarshal(result.Raw, &messages)
return &messages, err
}
// GetChatScheduledMessages Returns all scheduled messages in a chat. The messages are returned in a reverse chronological order (i.e., in order of decreasing message_id)
// @param chatID Chat identifier
func (client *Client) GetChatScheduledMessages(chatID int64) (*tdlib.Messages, error) {
result, err := client.SendAndCatch(tdlib.UpdateData{
"@type": "getChatScheduledMessages",
"chat_id": chatID,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, tdlib.RequestError{Code: int(result.Data["code"].(float64)), Message: result.Data["message"].(string)}
}
var messages tdlib.Messages
err = json.Unmarshal(result.Raw, &messages)
return &messages, err
}
// SendMessageAlbum Sends 2-10 messages grouped together into an album. Currently only audio, document, photo and video messages can be grouped into an album. Documents and audio files can be only grouped in an album with messages of the same type. Returns sent messages
// @param chatID Target chat
// @param messageThreadID If not 0, a message thread identifier in which the messages will be sent
// @param replyToMessageID Identifier of a message to reply to or 0
// @param options Options to be used to send the messages
// @param inputMessageContents Contents of messages to be sent. At most 10 messages can be added to an album
func (client *Client) SendMessageAlbum(chatID int64, messageThreadID int64, replyToMessageID int64, options *tdlib.MessageSendOptions, inputMessageContents []tdlib.InputMessageContent) (*tdlib.Messages, error) {
result, err := client.SendAndCatch(tdlib.UpdateData{
"@type": "sendMessageAlbum",
"chat_id": chatID,
"message_thread_id": messageThreadID,
"reply_to_message_id": replyToMessageID,
"options": options,
"input_message_contents": inputMessageContents,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, tdlib.RequestError{Code: int(result.Data["code"].(float64)), Message: result.Data["message"].(string)}
}
var messages tdlib.Messages
err = json.Unmarshal(result.Raw, &messages)
return &messages, err
}
// ForwardMessages Forwards previously sent messages. Returns the forwarded messages in the same order as the message identifiers passed in message_ids. If a message can't be forwarded, null will be returned instead of the message
// @param chatID Identifier of the chat to which to forward messages
// @param fromChatID Identifier of the chat from which to forward messages
// @param messageIDs Identifiers of the messages to forward. Message identifiers must be in a strictly increasing order. At most 100 messages can be forwarded simultaneously
// @param options Options to be used to send the messages
// @param sendCopy If true, content of the messages will be copied without links to the original messages. Always true if the messages are forwarded to a secret chat
// @param removeCaption If true, media caption of message copies will be removed. Ignored if send_copy is false
// @param onlyPreview If true, messages will not be forwarded and instead fake messages will be returned
func (client *Client) ForwardMessages(chatID int64, fromChatID int64, messageIDs []int64, options *tdlib.MessageSendOptions, sendCopy bool, removeCaption bool, onlyPreview bool) (*tdlib.Messages, error) {
result, err := client.SendAndCatch(tdlib.UpdateData{
"@type": "forwardMessages",
"chat_id": chatID,
"from_chat_id": fromChatID,
"message_ids": messageIDs,
"options": options,
"send_copy": sendCopy,
"remove_caption": removeCaption,
"only_preview": onlyPreview,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, tdlib.RequestError{Code: int(result.Data["code"].(float64)), Message: result.Data["message"].(string)}
}
var messages tdlib.Messages
err = json.Unmarshal(result.Raw, &messages)
return &messages, err
}
// ResendMessages Resends messages which failed to send. Can be called only for messages for which messageSendingStateFailed.can_retry is true and after specified in messageSendingStateFailed.retry_after time passed. If a message is re-sent, the corresponding failed to send message is deleted. Returns the sent messages in the same order as the message identifiers passed in message_ids. If a message can't be re-sent, null will be returned instead of the message
// @param chatID Identifier of the chat to send messages
// @param messageIDs Identifiers of the messages to resend. Message identifiers must be in a strictly increasing order
func (client *Client) ResendMessages(chatID int64, messageIDs []int64) (*tdlib.Messages, error) {
result, err := client.SendAndCatch(tdlib.UpdateData{
"@type": "resendMessages",
"chat_id": chatID,
"message_ids": messageIDs,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, tdlib.RequestError{Code: int(result.Data["code"].(float64)), Message: result.Data["message"].(string)}
}
var messages tdlib.Messages
err = json.Unmarshal(result.Raw, &messages)
return &messages, err
}