tgbot/types/definitions/forum.rs
1use serde::{Deserialize, Serialize};
2
3use crate::{
4 api::{Method, Payload},
5 types::{ChatId, ForumTopicIconColor, Integer, Sticker},
6};
7
8/// Represents a forum topic.
9#[serde_with::skip_serializing_none]
10#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
11pub struct ForumTopic {
12 /// Color of the icon.
13 pub icon_color: ForumTopicIconColor,
14 /// Unique identifier.
15 pub message_thread_id: Integer,
16 /// Name.
17 pub name: String,
18 /// Unique identifier of the custom emoji shown as the topic icon.
19 pub icon_custom_emoji_id: Option<String>,
20}
21
22impl ForumTopic {
23 /// Creates a new `ForumTopic`.
24 ///
25 /// # Arguments
26 ///
27 /// * `icon_color` - Color of the icon.
28 /// * `message_thread_id` - Unique identifier of the topic.
29 /// * `name` - Name of the topic.
30 pub fn new<A, B>(icon_color: A, message_thread_id: Integer, name: B) -> Self
31 where
32 A: Into<ForumTopicIconColor>,
33 B: Into<String>,
34 {
35 Self {
36 icon_color: icon_color.into(),
37 message_thread_id,
38 name: name.into(),
39 icon_custom_emoji_id: None,
40 }
41 }
42
43 /// Sets a new icon custom emoji ID.
44 ///
45 /// # Arguments
46 ///
47 /// * `value` - Emoji ID.
48 pub fn with_icon_custom_emoji_id<T>(mut self, value: T) -> Self
49 where
50 T: Into<String>,
51 {
52 self.icon_custom_emoji_id = Some(value.into());
53 self
54 }
55}
56
57/// Closes an open topic in a forum supergroup chat.
58///
59/// The bot must be an administrator in the chat for this to work
60/// and must have the `can_manage_topics` administrator rights,
61/// unless it is the creator of the topic.
62#[derive(Clone, Debug, Serialize)]
63pub struct CloseForumTopic {
64 chat_id: ChatId,
65 message_thread_id: Integer,
66}
67
68impl CloseForumTopic {
69 /// Creates a new `CloseForumTopic`.
70 ///
71 /// # Arguments
72 ///
73 /// * `chat_id` - Unique identifier of the target chat.
74 /// * `message_thread_id` - Unique identifier of the target message thread of the forum topic.
75 pub fn new<T>(chat_id: T, message_thread_id: Integer) -> Self
76 where
77 T: Into<ChatId>,
78 {
79 Self {
80 chat_id: chat_id.into(),
81 message_thread_id,
82 }
83 }
84}
85
86impl Method for CloseForumTopic {
87 type Response = bool;
88
89 fn into_payload(self) -> Payload {
90 Payload::json("closeForumTopic", self)
91 }
92}
93
94/// Creates a topic in a forum supergroup chat.
95///
96/// The bot must be an administrator in the chat for this to work
97/// and must have the can_manage_topics administrator rights.
98#[serde_with::skip_serializing_none]
99#[derive(Clone, Debug, Serialize)]
100pub struct CreateForumTopic {
101 chat_id: ChatId,
102 name: String,
103 icon_color: Option<ForumTopicIconColor>,
104 icon_custom_emoji_id: Option<String>,
105}
106
107impl CreateForumTopic {
108 /// Creates a new `CreateForumTopic`.
109 ///
110 /// # Arguments
111 ///
112 /// * `chat_id` - Unique identifier of the target chat.
113 /// * `name` - Topic name; 1 - 128 characters.
114 pub fn new<A, B>(chat_id: A, name: B) -> Self
115 where
116 A: Into<ChatId>,
117 B: Into<String>,
118 {
119 Self {
120 chat_id: chat_id.into(),
121 name: name.into(),
122 icon_color: None,
123 icon_custom_emoji_id: None,
124 }
125 }
126
127 /// Sets a new color of the topic icon.
128 ///
129 /// # Arguments
130 ///
131 /// * `value` - Color of the topic icon.
132 pub fn with_icon_color(mut self, value: ForumTopicIconColor) -> Self {
133 self.icon_color = Some(value);
134 self
135 }
136
137 /// Sets a new icon custom emoji ID.
138 ///
139 /// # Arguments
140 ///
141 /// * `value` - Unique identifier of the custom emoji shown as the topic icon.
142 ///
143 /// Use [`GetForumTopicIconStickers`] to get all allowed custom emoji identifiers.
144 pub fn with_icon_custom_emoji_id<T>(mut self, value: T) -> Self
145 where
146 T: Into<String>,
147 {
148 self.icon_custom_emoji_id = Some(value.into());
149 self
150 }
151}
152
153impl Method for CreateForumTopic {
154 type Response = ForumTopic;
155
156 fn into_payload(self) -> Payload {
157 Payload::json("createForumTopic", self)
158 }
159}
160
161/// Closes an opened 'General' topic in a forum supergroup chat.
162///
163/// The bot must be an administrator in the chat for this to work
164/// and must have the can_manage_topics administrator rights.
165#[derive(Clone, Debug, Serialize)]
166pub struct CloseGeneralForumTopic {
167 chat_id: ChatId,
168}
169
170impl CloseGeneralForumTopic {
171 /// Creates a new `CloseGeneralForumTopic`.
172 ///
173 /// # Arguments
174 ///
175 /// * `chat_id` - Unique identifier of the target chat.
176 pub fn new<T>(chat_id: T) -> Self
177 where
178 T: Into<ChatId>,
179 {
180 Self {
181 chat_id: chat_id.into(),
182 }
183 }
184}
185
186impl Method for CloseGeneralForumTopic {
187 type Response = bool;
188
189 fn into_payload(self) -> Payload {
190 Payload::json("closeGeneralForumTopic", self)
191 }
192}
193
194/// Deletes a forum topic along with all its messages in a forum supergroup chat.
195///
196/// The bot must be an administrator in the chat for this to work
197/// and must have the can_delete_messages administrator rights.
198#[derive(Clone, Debug, Serialize)]
199pub struct DeleteForumTopic {
200 chat_id: ChatId,
201 message_thread_id: Integer,
202}
203
204impl DeleteForumTopic {
205 /// Creates a new `DeleteForumTopic`.
206 ///
207 /// # Arguments
208 ///
209 /// * `chat_id` - Unique identifier of the target chat.
210 /// * `message_thread_id` - Unique identifier of the target message thread of the forum topic.
211 pub fn new<T>(chat_id: T, message_thread_id: Integer) -> Self
212 where
213 T: Into<ChatId>,
214 {
215 Self {
216 chat_id: chat_id.into(),
217 message_thread_id,
218 }
219 }
220}
221
222impl Method for DeleteForumTopic {
223 type Response = bool;
224
225 fn into_payload(self) -> Payload {
226 Payload::json("deleteForumTopic", self)
227 }
228}
229
230/// Changes name and icon of a topic in a forum supergroup chat.
231///
232/// The bot must be an administrator in the chat for this to work
233/// and must have can_manage_topics administrator rights,
234/// unless it is the creator of the topic.
235#[serde_with::skip_serializing_none]
236#[derive(Clone, Debug, Serialize)]
237pub struct EditForumTopic {
238 chat_id: ChatId,
239 message_thread_id: Integer,
240 icon_custom_emoji_id: Option<String>,
241 name: Option<String>,
242}
243
244impl EditForumTopic {
245 /// Creates a new `EditForumTopic`.
246 ///
247 /// # Arguments
248 ///
249 /// * `chat_id` - Unique identifier of the target.
250 /// * `message_thread_id` - Unique identifier of the target message thread of the forum topic.
251 pub fn new<C>(chat_id: C, message_thread_id: Integer) -> Self
252 where
253 C: Into<ChatId>,
254 {
255 Self {
256 chat_id: chat_id.into(),
257 message_thread_id,
258 icon_custom_emoji_id: None,
259 name: None,
260 }
261 }
262
263 /// Sets a new icon custom emoji ID.
264 ///
265 /// # Arguments
266 ///
267 /// * `value` - New unique identifier of the custom emoji shown as the topic icon.
268 ///
269 /// Use [`GetForumTopicIconStickers`] to get all allowed custom emoji identifiers.
270 /// Pass an empty string to remove the icon.
271 /// If not specified, the current icon will be kept.
272 pub fn with_icon_custom_emoji_id<T>(mut self, value: T) -> Self
273 where
274 T: Into<String>,
275 {
276 self.icon_custom_emoji_id = Some(value.into());
277 self
278 }
279
280 /// Sets a new name.
281 ///
282 /// # Arguments
283 ///
284 /// * `value` - New topic name; 0-128 characters.
285 ///
286 /// If not specified or empty, the current name of the topic will be kept.
287 pub fn with_name<T>(mut self, value: T) -> Self
288 where
289 T: Into<String>,
290 {
291 self.name = Some(value.into());
292 self
293 }
294}
295
296impl Method for EditForumTopic {
297 type Response = bool;
298
299 fn into_payload(self) -> Payload {
300 Payload::json("editForumTopic", self)
301 }
302}
303
304/// Changes the name of the 'General' topic in a forum supergroup chat.
305///
306/// The bot must be an administrator in the chat for this to work
307/// and must have `can_manage_topics` administrator rights.
308#[derive(Clone, Debug, Serialize)]
309pub struct EditGeneralForumTopic {
310 chat_id: ChatId,
311 name: String,
312}
313
314impl EditGeneralForumTopic {
315 /// Creates a new `EditGeneralForumTopic`.
316 ///
317 /// # Arguments
318 ///
319 /// * `chat_id` - Unique identifier for the target chat.
320 /// * `name` - New topic name, 1-128 characters.
321 pub fn new<A, B>(chat_id: A, name: B) -> Self
322 where
323 A: Into<ChatId>,
324 B: Into<String>,
325 {
326 Self {
327 chat_id: chat_id.into(),
328 name: name.into(),
329 }
330 }
331}
332
333impl Method for EditGeneralForumTopic {
334 type Response = bool;
335
336 fn into_payload(self) -> Payload {
337 Payload::json("editGeneralForumTopic", self)
338 }
339}
340
341/// Returns custom emoji stickers, which can be used as a forum topic icon by any user.
342#[derive(Clone, Copy, Debug)]
343pub struct GetForumTopicIconStickers;
344
345impl Method for GetForumTopicIconStickers {
346 type Response = Vec<Sticker>;
347
348 fn into_payload(self) -> Payload {
349 Payload::empty("getForumTopicIconStickers")
350 }
351}
352
353/// Hides the 'General' topic in a forum supergroup chat.
354///
355/// The bot must be an administrator in the chat for this to work
356/// and must have the `can_manage_topics` administrator rights.
357/// The topic will be automatically closed if it was open.
358#[derive(Clone, Debug, Serialize)]
359pub struct HideGeneralForumTopic {
360 chat_id: ChatId,
361}
362
363impl HideGeneralForumTopic {
364 /// Creates a new `HideGeneralForumTopic`.
365 ///
366 /// # Arguments
367 ///
368 /// * `chat_id` - Unique identifier for the target chat.
369 pub fn new<T>(chat_id: T) -> Self
370 where
371 T: Into<ChatId>,
372 {
373 Self {
374 chat_id: chat_id.into(),
375 }
376 }
377}
378
379impl Method for HideGeneralForumTopic {
380 type Response = bool;
381
382 fn into_payload(self) -> Payload {
383 Payload::json("hideGeneralForumTopic", self)
384 }
385}
386
387/// Reopens a closed topic in a forum supergroup chat.
388///
389/// The bot must be an administrator in the chat for this to work
390/// and must have the `can_manage_topics` administrator rights,
391/// unless it is the creator of the topic.
392#[derive(Clone, Debug, Serialize)]
393pub struct ReopenForumTopic {
394 chat_id: ChatId,
395 message_thread_id: Integer,
396}
397
398impl ReopenForumTopic {
399 /// Creates a new `ReopenForumTopic`.
400 ///
401 /// # Arguments
402 ///
403 /// * `chat_id` - Unique identifier of the target chat.
404 /// * `message_thread_id` - Unique identifier of the target message thread of the forum topic.
405 pub fn new<T>(chat_id: T, message_thread_id: Integer) -> Self
406 where
407 T: Into<ChatId>,
408 {
409 Self {
410 chat_id: chat_id.into(),
411 message_thread_id,
412 }
413 }
414}
415
416impl Method for ReopenForumTopic {
417 type Response = bool;
418
419 fn into_payload(self) -> Payload {
420 Payload::json("reopenForumTopic", self)
421 }
422}
423
424/// Reopens a closed 'General' topic in a forum supergroup chat.
425///
426/// The bot must be an administrator in the chat for this to work
427/// and must have the `can_manage_topics` administrator rights.
428/// The topic will be automatically unhidden if it was hidden.
429#[derive(Clone, Debug, Serialize)]
430pub struct ReopenGeneralForumTopic {
431 chat_id: ChatId,
432}
433
434impl ReopenGeneralForumTopic {
435 /// Creates a new `ReopenGeneralForumTopic`.
436 ///
437 /// # Arguments
438 ///
439 /// * `chat_id` - Unique identifier of the target chat.
440 pub fn new<T>(chat_id: T) -> Self
441 where
442 T: Into<ChatId>,
443 {
444 Self {
445 chat_id: chat_id.into(),
446 }
447 }
448}
449
450impl Method for ReopenGeneralForumTopic {
451 type Response = bool;
452
453 fn into_payload(self) -> Payload {
454 Payload::json("reopenGeneralForumTopic", self)
455 }
456}
457
458/// Reveals the 'General' topic in a forum supergroup chat.
459///
460/// The bot must be an administrator in the chat for this to work
461/// and must have the `can_manage_topics` administrator rights.
462#[derive(Clone, Debug, Serialize)]
463pub struct UnhideGeneralForumTopic {
464 chat_id: ChatId,
465}
466
467impl UnhideGeneralForumTopic {
468 /// Creates a new `UnhideGeneralForumTopic`.
469 ///
470 /// # Arguments
471 ///
472 /// * `chat_id` - Unique identifier of the target chat.
473 pub fn new<T>(chat_id: T) -> Self
474 where
475 T: Into<ChatId>,
476 {
477 Self {
478 chat_id: chat_id.into(),
479 }
480 }
481}
482
483impl Method for UnhideGeneralForumTopic {
484 type Response = bool;
485
486 fn into_payload(self) -> Payload {
487 Payload::json("unhideGeneralForumTopic", self)
488 }
489}
490
491/// Clears the list of pinned messages in a forum topic.
492///
493/// The bot must be an administrator in the chat for this to work
494/// and must have the `can_pin_messages` administrator right in the supergroup.
495#[derive(Clone, Debug, Serialize)]
496pub struct UnpinAllForumTopicMessages {
497 chat_id: ChatId,
498 message_thread_id: Integer,
499}
500
501impl UnpinAllForumTopicMessages {
502 /// Creates a new `UnpinAllForumTopicMessages`.
503 ///
504 /// # Arguments
505 ///
506 /// * `chat_id` - Unique identifier of the target chat.
507 /// * `message_thread_id` - Unique identifier of the target message thread of the forum topic.
508 pub fn new<T>(chat_id: T, message_thread_id: Integer) -> Self
509 where
510 T: Into<ChatId>,
511 {
512 Self {
513 chat_id: chat_id.into(),
514 message_thread_id,
515 }
516 }
517}
518
519impl Method for UnpinAllForumTopicMessages {
520 type Response = bool;
521
522 fn into_payload(self) -> Payload {
523 Payload::json("unpinAllForumTopicMessages", self)
524 }
525}
526
527/// Clears the list of pinned messages in a General forum topic.
528///
529/// The bot must be an administrator in the chat for this to work
530/// and must have the `can_pin_messages` administrator right in the supergroup.
531#[derive(Clone, Debug, Serialize)]
532pub struct UnpinAllGeneralForumTopicMessages {
533 chat_id: ChatId,
534}
535
536impl UnpinAllGeneralForumTopicMessages {
537 /// Creates a new `UnpinAllGeneralForumTopicMessages`.
538 ///
539 /// # Arguments
540 ///
541 /// * `chat_id` - Unique identifier of the target chat.
542 pub fn new<T>(chat_id: T) -> Self
543 where
544 T: Into<ChatId>,
545 {
546 Self {
547 chat_id: chat_id.into(),
548 }
549 }
550}
551
552impl Method for UnpinAllGeneralForumTopicMessages {
553 type Response = bool;
554
555 fn into_payload(self) -> Payload {
556 Payload::json("unpinAllGeneralForumTopicMessages", self)
557 }
558}