rustigram_api/methods/
bot_settings.rs1use crate::client::BotClient;
2use rustigram_types::keyboard::MenuButton;
3use rustigram_types::user::{BotCommand, BotCommandScope, ChatId};
4use serde::Serialize;
5use std::future::{Future, IntoFuture};
6use std::pin::Pin;
7
8#[derive(Serialize)]
10struct SetMyCommandsParams {
11 commands: Vec<BotCommand>,
12 #[serde(skip_serializing_if = "Option::is_none")]
13 scope: Option<BotCommandScope>,
14 #[serde(skip_serializing_if = "Option::is_none")]
15 language_code: Option<String>,
16}
17
18pub struct SetMyCommands {
20 client: BotClient,
21 params: SetMyCommandsParams,
22}
23impl SetMyCommands {
24 pub(crate) fn new(client: BotClient, commands: Vec<BotCommand>) -> Self {
25 Self {
26 client,
27 params: SetMyCommandsParams {
28 commands,
29 scope: None,
30 language_code: None,
31 },
32 }
33 }
34 pub fn scope(mut self, s: BotCommandScope) -> Self {
36 self.params.scope = Some(s);
37 self
38 }
39 pub fn language_code(mut self, lc: impl Into<String>) -> Self {
41 self.params.language_code = Some(lc.into());
42 self
43 }
44}
45impl IntoFuture for SetMyCommands {
46 type Output = crate::error::Result<bool>;
47 type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
48 fn into_future(self) -> Self::IntoFuture {
49 Box::pin(async move { self.client.post_json("setMyCommands", &self.params).await })
50 }
51}
52
53#[derive(Serialize, Default)]
55struct GetMyCommandsParams {
56 #[serde(skip_serializing_if = "Option::is_none")]
57 scope: Option<BotCommandScope>,
58 #[serde(skip_serializing_if = "Option::is_none")]
59 language_code: Option<String>,
60}
61
62pub struct GetMyCommands {
64 client: BotClient,
65 params: GetMyCommandsParams,
66}
67impl GetMyCommands {
68 pub(crate) fn new(client: BotClient) -> Self {
69 Self {
70 client,
71 params: Default::default(),
72 }
73 }
74 pub fn scope(mut self, s: BotCommandScope) -> Self {
76 self.params.scope = Some(s);
77 self
78 }
79 pub fn language_code(mut self, lc: impl Into<String>) -> Self {
81 self.params.language_code = Some(lc.into());
82 self
83 }
84}
85impl IntoFuture for GetMyCommands {
86 type Output = crate::error::Result<Vec<BotCommand>>;
87 type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
88 fn into_future(self) -> Self::IntoFuture {
89 Box::pin(async move { self.client.post_json("getMyCommands", &self.params).await })
90 }
91}
92
93#[derive(Serialize, Default)]
95struct SetMyNameParams {
96 #[serde(skip_serializing_if = "Option::is_none")]
97 name: Option<String>,
98 #[serde(skip_serializing_if = "Option::is_none")]
99 language_code: Option<String>,
100}
101
102pub struct SetMyName {
104 client: BotClient,
105 params: SetMyNameParams,
106}
107impl SetMyName {
108 pub(crate) fn new(client: BotClient) -> Self {
109 Self {
110 client,
111 params: Default::default(),
112 }
113 }
114 pub fn name(mut self, n: impl Into<String>) -> Self {
116 self.params.name = Some(n.into());
117 self
118 }
119 pub fn language_code(mut self, lc: impl Into<String>) -> Self {
121 self.params.language_code = Some(lc.into());
122 self
123 }
124}
125impl IntoFuture for SetMyName {
126 type Output = crate::error::Result<bool>;
127 type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
128 fn into_future(self) -> Self::IntoFuture {
129 Box::pin(async move { self.client.post_json("setMyName", &self.params).await })
130 }
131}
132
133#[derive(Serialize, Default)]
135struct SetMyDescriptionParams {
136 #[serde(skip_serializing_if = "Option::is_none")]
137 description: Option<String>,
138 #[serde(skip_serializing_if = "Option::is_none")]
139 language_code: Option<String>,
140}
141
142pub struct SetMyDescription {
144 client: BotClient,
145 params: SetMyDescriptionParams,
146}
147impl SetMyDescription {
148 pub(crate) fn new(client: BotClient) -> Self {
149 Self {
150 client,
151 params: Default::default(),
152 }
153 }
154 pub fn description(mut self, d: impl Into<String>) -> Self {
156 self.params.description = Some(d.into());
157 self
158 }
159 pub fn language_code(mut self, lc: impl Into<String>) -> Self {
161 self.params.language_code = Some(lc.into());
162 self
163 }
164}
165impl IntoFuture for SetMyDescription {
166 type Output = crate::error::Result<bool>;
167 type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
168 fn into_future(self) -> Self::IntoFuture {
169 Box::pin(async move {
170 self.client
171 .post_json("setMyDescription", &self.params)
172 .await
173 })
174 }
175}
176
177#[derive(Serialize, Default)]
179struct GetChatMenuButtonParams {
180 #[serde(skip_serializing_if = "Option::is_none")]
181 chat_id: Option<ChatId>,
182}
183
184pub struct GetChatMenuButton {
186 client: BotClient,
187 params: GetChatMenuButtonParams,
188}
189impl GetChatMenuButton {
190 pub(crate) fn new(client: BotClient) -> Self {
191 Self {
192 client,
193 params: Default::default(),
194 }
195 }
196 pub fn chat_id(mut self, id: impl Into<ChatId>) -> Self {
198 self.params.chat_id = Some(id.into());
199 self
200 }
201}
202impl IntoFuture for GetChatMenuButton {
203 type Output = crate::error::Result<MenuButton>;
204 type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
205 fn into_future(self) -> Self::IntoFuture {
206 Box::pin(async move {
207 self.client
208 .post_json("getChatMenuButton", &self.params)
209 .await
210 })
211 }
212}
213
214#[derive(Serialize)]
216struct GetManagedBotTokenParams {
217 user_id: i64,
218}
219
220pub struct GetManagedBotToken {
222 client: BotClient,
223 params: GetManagedBotTokenParams,
224}
225impl GetManagedBotToken {
226 pub(crate) fn new(client: BotClient, user_id: i64) -> Self {
227 Self {
228 client,
229 params: GetManagedBotTokenParams { user_id },
230 }
231 }
232}
233impl IntoFuture for GetManagedBotToken {
234 type Output = crate::error::Result<String>;
235 type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
236 fn into_future(self) -> Self::IntoFuture {
237 Box::pin(async move {
238 self.client
239 .post_json("getManagedBotToken", &self.params)
240 .await
241 })
242 }
243}