tgbot 0.47.0

A Telegram Bot library
Documentation
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
use serde::{Deserialize, Serialize};

use crate::{
    api::{Method, Payload, PayloadError},
    types::{ChatId, ForumTopicIconColor, Integer, Sticker},
};

/// Represents a forum topic.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct ForumTopic {
    /// Color of the icon.
    pub icon_color: ForumTopicIconColor,
    /// Unique identifier.
    pub message_thread_id: Integer,
    /// Name.
    pub name: String,
    /// Unique identifier of the custom emoji shown as the topic icon.
    pub icon_custom_emoji_id: Option<String>,
    /// Whether the name of the topic wasn't specified explicitly by its creator
    /// and likely needs to be changed by the bot.
    pub is_name_implicit: Option<bool>,
}

/// Closes an open topic in a forum supergroup chat.
///
/// The bot must be an administrator in the chat for this to work
/// and must have the `can_manage_topics` administrator rights,
/// unless it is the creator of the topic.
#[derive(Clone, Debug, Serialize)]
pub struct CloseForumTopic {
    chat_id: ChatId,
    message_thread_id: Integer,
}

impl CloseForumTopic {
    /// Creates a new `CloseForumTopic`.
    ///
    /// # Arguments
    ///
    /// * `chat_id` - Unique identifier of the target chat.
    /// * `message_thread_id` - Unique identifier of the target message thread of the forum topic.
    pub fn new<T>(chat_id: T, message_thread_id: Integer) -> Self
    where
        T: Into<ChatId>,
    {
        Self {
            chat_id: chat_id.into(),
            message_thread_id,
        }
    }
}

impl Method for CloseForumTopic {
    type Response = bool;

    fn into_payload(self) -> Result<Payload, PayloadError> {
        Payload::json("closeForumTopic", self)
    }
}

/// Creates a topic in a forum supergroup chat.
///
/// The bot must be an administrator in the chat for this to work
/// and must have the can_manage_topics administrator rights.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Serialize)]
pub struct CreateForumTopic {
    chat_id: ChatId,
    name: String,
    icon_color: Option<ForumTopicIconColor>,
    icon_custom_emoji_id: Option<String>,
}

impl CreateForumTopic {
    /// Creates a new `CreateForumTopic`.
    ///
    /// # Arguments
    ///
    /// * `chat_id` - Unique identifier of the target chat.
    /// * `name` - Topic name; 1 - 128 characters.
    pub fn new<A, B>(chat_id: A, name: B) -> Self
    where
        A: Into<ChatId>,
        B: Into<String>,
    {
        Self {
            chat_id: chat_id.into(),
            name: name.into(),
            icon_color: None,
            icon_custom_emoji_id: None,
        }
    }

    /// Sets a new color of the topic icon.
    ///
    /// # Arguments
    ///
    /// * `value` - Color of the topic icon.
    pub fn with_icon_color(mut self, value: ForumTopicIconColor) -> Self {
        self.icon_color = Some(value);
        self
    }

    /// Sets a new icon custom emoji ID.
    ///
    /// # Arguments
    ///
    /// * `value` - Unique identifier of the custom emoji shown as the topic icon.
    ///
    /// Use [`GetForumTopicIconStickers`] to get all allowed custom emoji identifiers.
    pub fn with_icon_custom_emoji_id<T>(mut self, value: T) -> Self
    where
        T: Into<String>,
    {
        self.icon_custom_emoji_id = Some(value.into());
        self
    }
}

impl Method for CreateForumTopic {
    type Response = ForumTopic;

    fn into_payload(self) -> Result<Payload, PayloadError> {
        Payload::json("createForumTopic", self)
    }
}

/// Closes an opened 'General' topic in a forum supergroup chat.
///
/// The bot must be an administrator in the chat for this to work
/// and must have the can_manage_topics administrator rights.
#[derive(Clone, Debug, Serialize)]
pub struct CloseGeneralForumTopic {
    chat_id: ChatId,
}

impl CloseGeneralForumTopic {
    /// Creates a new `CloseGeneralForumTopic`.
    ///
    /// # Arguments
    ///
    /// * `chat_id` - Unique identifier of the target chat.
    pub fn new<T>(chat_id: T) -> Self
    where
        T: Into<ChatId>,
    {
        Self {
            chat_id: chat_id.into(),
        }
    }
}

impl Method for CloseGeneralForumTopic {
    type Response = bool;

    fn into_payload(self) -> Result<Payload, PayloadError> {
        Payload::json("closeGeneralForumTopic", self)
    }
}

/// Deletes a forum topic along with all its messages in a forum supergroup chat.
///
/// The bot must be an administrator in the chat for this to work
/// and must have the can_delete_messages administrator rights.
#[derive(Clone, Debug, Serialize)]
pub struct DeleteForumTopic {
    chat_id: ChatId,
    message_thread_id: Integer,
}

impl DeleteForumTopic {
    /// Creates a new `DeleteForumTopic`.
    ///
    /// # Arguments
    ///
    /// * `chat_id` - Unique identifier of the target chat.
    /// * `message_thread_id` - Unique identifier of the target message thread of the forum topic.
    pub fn new<T>(chat_id: T, message_thread_id: Integer) -> Self
    where
        T: Into<ChatId>,
    {
        Self {
            chat_id: chat_id.into(),
            message_thread_id,
        }
    }
}

impl Method for DeleteForumTopic {
    type Response = bool;

    fn into_payload(self) -> Result<Payload, PayloadError> {
        Payload::json("deleteForumTopic", self)
    }
}

/// Changes name and icon of a topic in a forum supergroup chat.
///
/// The bot must be an administrator in the chat for this to work
/// and must have can_manage_topics administrator rights,
/// unless it is the creator of the topic.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Serialize)]
pub struct EditForumTopic {
    chat_id: ChatId,
    message_thread_id: Integer,
    icon_custom_emoji_id: Option<String>,
    name: Option<String>,
}

impl EditForumTopic {
    /// Creates a new `EditForumTopic`.
    ///
    /// # Arguments
    ///
    /// * `chat_id` - Unique identifier of the target.
    /// * `message_thread_id` - Unique identifier of the target message thread of the forum topic.
    pub fn new<C>(chat_id: C, message_thread_id: Integer) -> Self
    where
        C: Into<ChatId>,
    {
        Self {
            chat_id: chat_id.into(),
            message_thread_id,
            icon_custom_emoji_id: None,
            name: None,
        }
    }

    /// Sets a new icon custom emoji ID.
    ///
    /// # Arguments
    ///
    /// * `value` - New unique identifier of the custom emoji shown as the topic icon.
    ///
    /// Use [`GetForumTopicIconStickers`] to get all allowed custom emoji identifiers.
    /// Pass an empty string to remove the icon.
    /// If not specified, the current icon will be kept.
    pub fn with_icon_custom_emoji_id<T>(mut self, value: T) -> Self
    where
        T: Into<String>,
    {
        self.icon_custom_emoji_id = Some(value.into());
        self
    }

    /// Sets a new name.
    ///
    /// # Arguments
    ///
    /// * `value` - New topic name; 0-128 characters.
    ///
    /// If not specified or empty, the current name of the topic will be kept.
    pub fn with_name<T>(mut self, value: T) -> Self
    where
        T: Into<String>,
    {
        self.name = Some(value.into());
        self
    }
}

impl Method for EditForumTopic {
    type Response = bool;

    fn into_payload(self) -> Result<Payload, PayloadError> {
        Payload::json("editForumTopic", self)
    }
}

/// Changes the name of the 'General' topic in a forum supergroup chat.
///
/// The bot must be an administrator in the chat for this to work
/// and must have `can_manage_topics` administrator rights.
#[derive(Clone, Debug, Serialize)]
pub struct EditGeneralForumTopic {
    chat_id: ChatId,
    name: String,
}

impl EditGeneralForumTopic {
    /// Creates a new `EditGeneralForumTopic`.
    ///
    /// # Arguments
    ///
    /// * `chat_id` - Unique identifier for the target chat.
    /// * `name` - New topic name, 1-128 characters.
    pub fn new<A, B>(chat_id: A, name: B) -> Self
    where
        A: Into<ChatId>,
        B: Into<String>,
    {
        Self {
            chat_id: chat_id.into(),
            name: name.into(),
        }
    }
}

impl Method for EditGeneralForumTopic {
    type Response = bool;

    fn into_payload(self) -> Result<Payload, PayloadError> {
        Payload::json("editGeneralForumTopic", self)
    }
}

/// Returns custom emoji stickers, which can be used as a forum topic icon by any user.
#[derive(Clone, Copy, Debug)]
pub struct GetForumTopicIconStickers;

impl Method for GetForumTopicIconStickers {
    type Response = Vec<Sticker>;

    fn into_payload(self) -> Result<Payload, PayloadError> {
        Payload::empty("getForumTopicIconStickers")
    }
}

/// Hides the 'General' topic in a forum supergroup chat.
///
/// The bot must be an administrator in the chat for this to work
/// and must have the `can_manage_topics` administrator rights.
/// The topic will be automatically closed if it was open.
#[derive(Clone, Debug, Serialize)]
pub struct HideGeneralForumTopic {
    chat_id: ChatId,
}

impl HideGeneralForumTopic {
    /// Creates a new `HideGeneralForumTopic`.
    ///
    /// # Arguments
    ///
    /// * `chat_id` - Unique identifier for the target chat.
    pub fn new<T>(chat_id: T) -> Self
    where
        T: Into<ChatId>,
    {
        Self {
            chat_id: chat_id.into(),
        }
    }
}

impl Method for HideGeneralForumTopic {
    type Response = bool;

    fn into_payload(self) -> Result<Payload, PayloadError> {
        Payload::json("hideGeneralForumTopic", self)
    }
}

/// Reopens a closed topic in a forum supergroup chat.
///
/// The bot must be an administrator in the chat for this to work
/// and must have the `can_manage_topics` administrator rights,
/// unless it is the creator of the topic.
#[derive(Clone, Debug, Serialize)]
pub struct ReopenForumTopic {
    chat_id: ChatId,
    message_thread_id: Integer,
}

impl ReopenForumTopic {
    /// Creates a new `ReopenForumTopic`.
    ///
    /// # Arguments
    ///
    /// * `chat_id` - Unique identifier of the target chat.
    /// * `message_thread_id` - Unique identifier of the target message thread of the forum topic.
    pub fn new<T>(chat_id: T, message_thread_id: Integer) -> Self
    where
        T: Into<ChatId>,
    {
        Self {
            chat_id: chat_id.into(),
            message_thread_id,
        }
    }
}

impl Method for ReopenForumTopic {
    type Response = bool;

    fn into_payload(self) -> Result<Payload, PayloadError> {
        Payload::json("reopenForumTopic", self)
    }
}

/// Reopens a closed 'General' topic in a forum supergroup chat.
///
/// The bot must be an administrator in the chat for this to work
/// and must have the `can_manage_topics` administrator rights.
/// The topic will be automatically unhidden if it was hidden.
#[derive(Clone, Debug, Serialize)]
pub struct ReopenGeneralForumTopic {
    chat_id: ChatId,
}

impl ReopenGeneralForumTopic {
    /// Creates a new `ReopenGeneralForumTopic`.
    ///
    /// # Arguments
    ///
    /// * `chat_id` - Unique identifier of the target chat.
    pub fn new<T>(chat_id: T) -> Self
    where
        T: Into<ChatId>,
    {
        Self {
            chat_id: chat_id.into(),
        }
    }
}

impl Method for ReopenGeneralForumTopic {
    type Response = bool;

    fn into_payload(self) -> Result<Payload, PayloadError> {
        Payload::json("reopenGeneralForumTopic", self)
    }
}

/// Reveals the 'General' topic in a forum supergroup chat.
///
/// The bot must be an administrator in the chat for this to work
/// and must have the `can_manage_topics` administrator rights.
#[derive(Clone, Debug, Serialize)]
pub struct UnhideGeneralForumTopic {
    chat_id: ChatId,
}

impl UnhideGeneralForumTopic {
    /// Creates a new `UnhideGeneralForumTopic`.
    ///
    /// # Arguments
    ///
    /// * `chat_id` - Unique identifier of the target chat.
    pub fn new<T>(chat_id: T) -> Self
    where
        T: Into<ChatId>,
    {
        Self {
            chat_id: chat_id.into(),
        }
    }
}

impl Method for UnhideGeneralForumTopic {
    type Response = bool;

    fn into_payload(self) -> Result<Payload, PayloadError> {
        Payload::json("unhideGeneralForumTopic", self)
    }
}

/// Clears the list of pinned messages in a forum topic.
///
/// The bot must be an administrator in the chat for this to work
/// and must have the `can_pin_messages` administrator right in the supergroup.
#[derive(Clone, Debug, Serialize)]
pub struct UnpinAllForumTopicMessages {
    chat_id: ChatId,
    message_thread_id: Integer,
}

impl UnpinAllForumTopicMessages {
    /// Creates a new `UnpinAllForumTopicMessages`.
    ///
    /// # Arguments
    ///
    /// * `chat_id` - Unique identifier of the target chat.
    /// * `message_thread_id` - Unique identifier of the target message thread of the forum topic.
    pub fn new<T>(chat_id: T, message_thread_id: Integer) -> Self
    where
        T: Into<ChatId>,
    {
        Self {
            chat_id: chat_id.into(),
            message_thread_id,
        }
    }
}

impl Method for UnpinAllForumTopicMessages {
    type Response = bool;

    fn into_payload(self) -> Result<Payload, PayloadError> {
        Payload::json("unpinAllForumTopicMessages", self)
    }
}

/// Clears the list of pinned messages in a General forum topic.
///
/// The bot must be an administrator in the chat for this to work
/// and must have the `can_pin_messages` administrator right in the supergroup.
#[derive(Clone, Debug, Serialize)]
pub struct UnpinAllGeneralForumTopicMessages {
    chat_id: ChatId,
}

impl UnpinAllGeneralForumTopicMessages {
    /// Creates a new `UnpinAllGeneralForumTopicMessages`.
    ///
    /// # Arguments
    ///
    /// * `chat_id` - Unique identifier of the target chat.
    pub fn new<T>(chat_id: T) -> Self
    where
        T: Into<ChatId>,
    {
        Self {
            chat_id: chat_id.into(),
        }
    }
}

impl Method for UnpinAllGeneralForumTopicMessages {
    type Response = bool;

    fn into_payload(self) -> Result<Payload, PayloadError> {
        Payload::json("unpinAllGeneralForumTopicMessages", self)
    }
}