Skip to main content

rust_tg_bot_raw/bot/
forum.rs

1use super::{push_opt, push_opt_str, Bot, ChatId, Result};
2use crate::request::request_parameter::RequestParameter;
3use crate::types::forum_topic;
4
5#[allow(dead_code)]
6impl Bot {
7    // ======================================================================
8    // Forum topics
9    // ======================================================================
10
11    /// Use this method to create a topic in a forum supergroup chat.
12    ///
13    /// Calls the Telegram `createForumTopic` API method.
14    pub async fn create_forum_topic_raw(
15        &self,
16        chat_id: ChatId,
17        name: &str,
18        icon_color: Option<i64>,
19        icon_custom_emoji_id: Option<&str>,
20    ) -> Result<forum_topic::ForumTopic> {
21        let mut params = vec![
22            RequestParameter::new("chat_id", serde_json::to_value(&chat_id)?),
23            RequestParameter::new("name", serde_json::Value::String(name.to_owned())),
24        ];
25        push_opt(&mut params, "icon_color", &icon_color)?;
26        push_opt_str(&mut params, "icon_custom_emoji_id", icon_custom_emoji_id);
27        self.do_post("createForumTopic", params).await
28    }
29
30    /// Use this method to edit name and icon of a topic in a forum supergroup chat.
31    ///
32    /// Calls the Telegram `editForumTopic` API method.
33    pub async fn edit_forum_topic_raw(
34        &self,
35        chat_id: ChatId,
36        message_thread_id: i64,
37        name: Option<&str>,
38        icon_custom_emoji_id: Option<&str>,
39    ) -> Result<bool> {
40        let mut params = vec![
41            RequestParameter::new("chat_id", serde_json::to_value(&chat_id)?),
42            RequestParameter::new(
43                "message_thread_id",
44                serde_json::to_value(message_thread_id)?,
45            ),
46        ];
47        push_opt_str(&mut params, "name", name);
48        push_opt_str(&mut params, "icon_custom_emoji_id", icon_custom_emoji_id);
49        self.do_post("editForumTopic", params).await
50    }
51
52    /// Use this method to close an open topic in a forum supergroup chat.
53    ///
54    /// Calls the Telegram `closeForumTopic` API method.
55    pub async fn close_forum_topic_raw(
56        &self,
57        chat_id: ChatId,
58        message_thread_id: i64,
59    ) -> Result<bool> {
60        let params = vec![
61            RequestParameter::new("chat_id", serde_json::to_value(&chat_id)?),
62            RequestParameter::new(
63                "message_thread_id",
64                serde_json::to_value(message_thread_id)?,
65            ),
66        ];
67        self.do_post("closeForumTopic", params).await
68    }
69
70    /// Use this method to reopen a closed topic in a forum supergroup chat.
71    ///
72    /// Calls the Telegram `reopenForumTopic` API method.
73    pub async fn reopen_forum_topic_raw(
74        &self,
75        chat_id: ChatId,
76        message_thread_id: i64,
77    ) -> Result<bool> {
78        let params = vec![
79            RequestParameter::new("chat_id", serde_json::to_value(&chat_id)?),
80            RequestParameter::new(
81                "message_thread_id",
82                serde_json::to_value(message_thread_id)?,
83            ),
84        ];
85        self.do_post("reopenForumTopic", params).await
86    }
87
88    /// Use this method to delete a forum topic along with all its messages.
89    ///
90    /// Calls the Telegram `deleteForumTopic` API method.
91    pub async fn delete_forum_topic_raw(
92        &self,
93        chat_id: ChatId,
94        message_thread_id: i64,
95    ) -> Result<bool> {
96        let params = vec![
97            RequestParameter::new("chat_id", serde_json::to_value(&chat_id)?),
98            RequestParameter::new(
99                "message_thread_id",
100                serde_json::to_value(message_thread_id)?,
101            ),
102        ];
103        self.do_post("deleteForumTopic", params).await
104    }
105
106    /// Use this method to clear the list of pinned messages in a forum topic.
107    ///
108    /// Calls the Telegram `unpinAllForumTopicMessages` API method.
109    pub async fn unpin_all_forum_topic_messages_raw(
110        &self,
111        chat_id: ChatId,
112        message_thread_id: i64,
113    ) -> Result<bool> {
114        let params = vec![
115            RequestParameter::new("chat_id", serde_json::to_value(&chat_id)?),
116            RequestParameter::new(
117                "message_thread_id",
118                serde_json::to_value(message_thread_id)?,
119            ),
120        ];
121        self.do_post("unpinAllForumTopicMessages", params).await
122    }
123
124    /// Use this method to clear the list of pinned messages in a General forum topic.
125    ///
126    /// Calls the Telegram `unpinAllGeneralForumTopicMessages` API method.
127    pub async fn unpin_all_general_forum_topic_messages_raw(
128        &self,
129        chat_id: ChatId,
130    ) -> Result<bool> {
131        let params = vec![RequestParameter::new(
132            "chat_id",
133            serde_json::to_value(&chat_id)?,
134        )];
135        self.do_post("unpinAllGeneralForumTopicMessages", params)
136            .await
137    }
138
139    /// Use this method to edit the name of the 'General' topic in a forum supergroup chat.
140    ///
141    /// Calls the Telegram `editGeneralForumTopic` API method.
142    pub async fn edit_general_forum_topic_raw(&self, chat_id: ChatId, name: &str) -> Result<bool> {
143        let params = vec![
144            RequestParameter::new("chat_id", serde_json::to_value(&chat_id)?),
145            RequestParameter::new("name", serde_json::Value::String(name.to_owned())),
146        ];
147        self.do_post("editGeneralForumTopic", params).await
148    }
149
150    /// Use this method to close an open 'General' topic in a forum supergroup chat.
151    ///
152    /// Calls the Telegram `closeGeneralForumTopic` API method.
153    pub async fn close_general_forum_topic_raw(&self, chat_id: ChatId) -> Result<bool> {
154        let params = vec![RequestParameter::new(
155            "chat_id",
156            serde_json::to_value(&chat_id)?,
157        )];
158        self.do_post("closeGeneralForumTopic", params).await
159    }
160
161    /// Use this method to reopen a closed 'General' topic in a forum supergroup chat.
162    ///
163    /// Calls the Telegram `reopenGeneralForumTopic` API method.
164    pub async fn reopen_general_forum_topic_raw(&self, chat_id: ChatId) -> Result<bool> {
165        let params = vec![RequestParameter::new(
166            "chat_id",
167            serde_json::to_value(&chat_id)?,
168        )];
169        self.do_post("reopenGeneralForumTopic", params).await
170    }
171
172    /// Use this method to hide the 'General' topic in a forum supergroup chat.
173    ///
174    /// Calls the Telegram `hideGeneralForumTopic` API method.
175    pub async fn hide_general_forum_topic_raw(&self, chat_id: ChatId) -> Result<bool> {
176        let params = vec![RequestParameter::new(
177            "chat_id",
178            serde_json::to_value(&chat_id)?,
179        )];
180        self.do_post("hideGeneralForumTopic", params).await
181    }
182
183    /// Use this method to unhide the 'General' topic in a forum supergroup chat.
184    ///
185    /// Calls the Telegram `unhideGeneralForumTopic` API method.
186    pub async fn unhide_general_forum_topic_raw(&self, chat_id: ChatId) -> Result<bool> {
187        let params = vec![RequestParameter::new(
188            "chat_id",
189            serde_json::to_value(&chat_id)?,
190        )];
191        self.do_post("unhideGeneralForumTopic", params).await
192    }
193}