Skip to main content

rust_tg_bot_raw/bot/
admin.rs

1use super::{push_opt, push_opt_str, Bot, Result};
2use crate::request::request_parameter::RequestParameter;
3use crate::types::{
4    bot_command, bot_command_scope, bot_description, bot_name, chat_administrator_rights,
5    menu_button,
6};
7
8#[allow(dead_code)]
9impl Bot {
10    // ======================================================================
11    // Chat menu & commands
12    // ======================================================================
13
14    /// Use this method to change the bot's menu button in a private chat, or the default menu button.
15    ///
16    /// Calls the Telegram `setChatMenuButton` API method.
17    pub async fn set_chat_menu_button_raw(
18        &self,
19        chat_id: Option<i64>,
20        menu_button: Option<menu_button::MenuButton>,
21    ) -> Result<bool> {
22        let mut params = Vec::new();
23        push_opt(&mut params, "chat_id", &chat_id)?;
24        push_opt(&mut params, "menu_button", &menu_button)?;
25        self.do_post("setChatMenuButton", params).await
26    }
27
28    /// Use this method to get the current value of the bot's menu button in a private chat.
29    ///
30    /// Calls the Telegram `getChatMenuButton` API method.
31    pub async fn get_chat_menu_button_raw(
32        &self,
33        chat_id: Option<i64>,
34    ) -> Result<menu_button::MenuButton> {
35        let mut params = Vec::new();
36        push_opt(&mut params, "chat_id", &chat_id)?;
37        self.do_post("getChatMenuButton", params).await
38    }
39
40    /// Use this method to change the list of the bot's commands.
41    ///
42    /// Calls the Telegram `setMyCommands` API method.
43    pub async fn set_my_commands_raw(
44        &self,
45        commands: Vec<bot_command::BotCommand>,
46        scope: Option<bot_command_scope::BotCommandScope>,
47        language_code: Option<&str>,
48    ) -> Result<bool> {
49        let mut params = vec![RequestParameter::new(
50            "commands",
51            serde_json::to_value(&commands)?,
52        )];
53        push_opt(&mut params, "scope", &scope)?;
54        push_opt_str(&mut params, "language_code", language_code);
55        self.do_post("setMyCommands", params).await
56    }
57
58    /// Use this method to get the current list of the bot's commands.
59    ///
60    /// Calls the Telegram `getMyCommands` API method.
61    pub async fn get_my_commands_raw(
62        &self,
63        scope: Option<bot_command_scope::BotCommandScope>,
64        language_code: Option<&str>,
65    ) -> Result<Vec<bot_command::BotCommand>> {
66        let mut params = Vec::new();
67        push_opt(&mut params, "scope", &scope)?;
68        push_opt_str(&mut params, "language_code", language_code);
69        self.do_post("getMyCommands", params).await
70    }
71
72    /// Use this method to delete the list of the bot's commands for a given scope and language.
73    ///
74    /// Calls the Telegram `deleteMyCommands` API method.
75    pub async fn delete_my_commands_raw(
76        &self,
77        scope: Option<bot_command_scope::BotCommandScope>,
78        language_code: Option<&str>,
79    ) -> Result<bool> {
80        let mut params = Vec::new();
81        push_opt(&mut params, "scope", &scope)?;
82        push_opt_str(&mut params, "language_code", language_code);
83        self.do_post("deleteMyCommands", params).await
84    }
85
86    /// Use this method to change the default administrator rights requested by the bot.
87    ///
88    /// Calls the Telegram `setMyDefaultAdministratorRights` API method.
89    pub async fn set_my_default_administrator_rights_raw(
90        &self,
91        rights: Option<chat_administrator_rights::ChatAdministratorRights>,
92        for_channels: Option<bool>,
93    ) -> Result<bool> {
94        let mut params = Vec::new();
95        push_opt(&mut params, "rights", &rights)?;
96        push_opt(&mut params, "for_channels", &for_channels)?;
97        self.do_post("setMyDefaultAdministratorRights", params)
98            .await
99    }
100
101    /// Use this method to get the current default administrator rights of the bot.
102    ///
103    /// Calls the Telegram `getMyDefaultAdministratorRights` API method.
104    pub async fn get_my_default_administrator_rights_raw(
105        &self,
106        for_channels: Option<bool>,
107    ) -> Result<chat_administrator_rights::ChatAdministratorRights> {
108        let mut params = Vec::new();
109        push_opt(&mut params, "for_channels", &for_channels)?;
110        self.do_post("getMyDefaultAdministratorRights", params)
111            .await
112    }
113
114    // ======================================================================
115    // Bot description and name
116    // ======================================================================
117
118    /// Use this method to change the bot's description.
119    ///
120    /// Calls the Telegram `setMyDescription` API method.
121    pub async fn set_my_description_raw(
122        &self,
123        description: Option<&str>,
124        language_code: Option<&str>,
125    ) -> Result<bool> {
126        let mut params = Vec::new();
127        push_opt_str(&mut params, "description", description);
128        push_opt_str(&mut params, "language_code", language_code);
129        self.do_post("setMyDescription", params).await
130    }
131
132    /// Use this method to get the current bot description.
133    ///
134    /// Calls the Telegram `getMyDescription` API method.
135    pub async fn get_my_description_raw(
136        &self,
137        language_code: Option<&str>,
138    ) -> Result<bot_description::BotDescription> {
139        let mut params = Vec::new();
140        push_opt_str(&mut params, "language_code", language_code);
141        self.do_post("getMyDescription", params).await
142    }
143
144    /// Use this method to change the bot's short description.
145    ///
146    /// Calls the Telegram `setMyShortDescription` API method.
147    pub async fn set_my_short_description_raw(
148        &self,
149        short_description: Option<&str>,
150        language_code: Option<&str>,
151    ) -> Result<bool> {
152        let mut params = Vec::new();
153        push_opt_str(&mut params, "short_description", short_description);
154        push_opt_str(&mut params, "language_code", language_code);
155        self.do_post("setMyShortDescription", params).await
156    }
157
158    /// Use this method to get the current bot short description.
159    ///
160    /// Calls the Telegram `getMyShortDescription` API method.
161    pub async fn get_my_short_description_raw(
162        &self,
163        language_code: Option<&str>,
164    ) -> Result<bot_description::BotShortDescription> {
165        let mut params = Vec::new();
166        push_opt_str(&mut params, "language_code", language_code);
167        self.do_post("getMyShortDescription", params).await
168    }
169
170    /// Use this method to change the bot's name.
171    ///
172    /// Calls the Telegram `setMyName` API method.
173    pub async fn set_my_name_raw(
174        &self,
175        name: Option<&str>,
176        language_code: Option<&str>,
177    ) -> Result<bool> {
178        let mut params = Vec::new();
179        push_opt_str(&mut params, "name", name);
180        push_opt_str(&mut params, "language_code", language_code);
181        self.do_post("setMyName", params).await
182    }
183
184    /// Use this method to get the current bot name.
185    ///
186    /// Calls the Telegram `getMyName` API method.
187    pub async fn get_my_name_raw(&self, language_code: Option<&str>) -> Result<bot_name::BotName> {
188        let mut params = Vec::new();
189        push_opt_str(&mut params, "language_code", language_code);
190        self.do_post("getMyName", params).await
191    }
192}