Skip to main content

rust_tg_bot_raw/bot/
business_methods.rs

1use super::{push_opt, push_opt_str, Bot, Result};
2use crate::request::request_parameter::RequestParameter;
3use crate::types::{business, gifts, owned_gift, payment};
4
5#[allow(dead_code)]
6impl Bot {
7    // ======================================================================
8    // Business account management
9    // ======================================================================
10
11    /// Use this method to get information about the connection of the bot with a business account.
12    ///
13    /// Calls the Telegram `getBusinessConnection` API method.
14    pub async fn get_business_connection_raw(
15        &self,
16        business_connection_id: &str,
17    ) -> Result<business::BusinessConnection> {
18        let params = vec![RequestParameter::new(
19            "business_connection_id",
20            serde_json::Value::String(business_connection_id.to_owned()),
21        )];
22        self.do_post("getBusinessConnection", params).await
23    }
24
25    /// Use this method to get the gifts received by a business account.
26    ///
27    /// Calls the Telegram `getBusinessAccountGifts` API method.
28    pub async fn get_business_account_gifts_raw(
29        &self,
30        business_connection_id: &str,
31        exclude_unsaved: Option<bool>,
32        exclude_saved: Option<bool>,
33        exclude_unlimited: Option<bool>,
34        exclude_unique: Option<bool>,
35        sort_by_price: Option<bool>,
36        offset: Option<&str>,
37        limit: Option<i64>,
38        exclude_limited_upgradable: Option<bool>,
39        exclude_limited_non_upgradable: Option<bool>,
40        exclude_from_blockchain: Option<bool>,
41    ) -> Result<owned_gift::OwnedGifts> {
42        let mut params = vec![RequestParameter::new(
43            "business_connection_id",
44            serde_json::Value::String(business_connection_id.to_owned()),
45        )];
46        push_opt(&mut params, "exclude_unsaved", &exclude_unsaved)?;
47        push_opt(&mut params, "exclude_saved", &exclude_saved)?;
48        push_opt(&mut params, "exclude_unlimited", &exclude_unlimited)?;
49        push_opt(&mut params, "exclude_unique", &exclude_unique)?;
50        push_opt(&mut params, "sort_by_price", &sort_by_price)?;
51        push_opt_str(&mut params, "offset", offset);
52        push_opt(&mut params, "limit", &limit)?;
53        push_opt(
54            &mut params,
55            "exclude_limited_upgradable",
56            &exclude_limited_upgradable,
57        )?;
58        push_opt(
59            &mut params,
60            "exclude_limited_non_upgradable",
61            &exclude_limited_non_upgradable,
62        )?;
63        push_opt(
64            &mut params,
65            "exclude_from_blockchain",
66            &exclude_from_blockchain,
67        )?;
68        self.do_post("getBusinessAccountGifts", params).await
69    }
70
71    /// Use this method to get the current star balance of a business account.
72    ///
73    /// Calls the Telegram `getBusinessAccountStarBalance` API method.
74    pub async fn get_business_account_star_balance_raw(
75        &self,
76        business_connection_id: &str,
77    ) -> Result<payment::stars::star_amount::StarAmount> {
78        let params = vec![RequestParameter::new(
79            "business_connection_id",
80            serde_json::Value::String(business_connection_id.to_owned()),
81        )];
82        self.do_post("getBusinessAccountStarBalance", params).await
83    }
84
85    /// Use this method to mark a message as read on behalf of a business account.
86    ///
87    /// Calls the Telegram `readBusinessMessage` API method.
88    pub async fn read_business_message_raw(
89        &self,
90        business_connection_id: &str,
91        chat_id: i64,
92        message_id: i64,
93    ) -> Result<bool> {
94        let params = vec![
95            RequestParameter::new(
96                "business_connection_id",
97                serde_json::Value::String(business_connection_id.to_owned()),
98            ),
99            RequestParameter::new("chat_id", serde_json::to_value(chat_id)?),
100            RequestParameter::new("message_id", serde_json::to_value(message_id)?),
101        ];
102        self.do_post("readBusinessMessage", params).await
103    }
104
105    /// Use this method to delete messages on behalf of a business account.
106    ///
107    /// Calls the Telegram `deleteBusinessMessages` API method.
108    pub async fn delete_business_messages_raw(
109        &self,
110        business_connection_id: &str,
111        message_ids: Vec<i64>,
112    ) -> Result<bool> {
113        let params = vec![
114            RequestParameter::new(
115                "business_connection_id",
116                serde_json::Value::String(business_connection_id.to_owned()),
117            ),
118            RequestParameter::new("message_ids", serde_json::to_value(&message_ids)?),
119        ];
120        self.do_post("deleteBusinessMessages", params).await
121    }
122
123    /// Use this method to set the name of a business account.
124    ///
125    /// Calls the Telegram `setBusinessAccountName` API method.
126    pub async fn set_business_account_name_raw(
127        &self,
128        business_connection_id: &str,
129        first_name: &str,
130        last_name: Option<&str>,
131    ) -> Result<bool> {
132        let mut params = vec![
133            RequestParameter::new(
134                "business_connection_id",
135                serde_json::Value::String(business_connection_id.to_owned()),
136            ),
137            RequestParameter::new(
138                "first_name",
139                serde_json::Value::String(first_name.to_owned()),
140            ),
141        ];
142        push_opt_str(&mut params, "last_name", last_name);
143        self.do_post("setBusinessAccountName", params).await
144    }
145
146    /// Use this method to set the username of a business account.
147    ///
148    /// Calls the Telegram `setBusinessAccountUsername` API method.
149    pub async fn set_business_account_username_raw(
150        &self,
151        business_connection_id: &str,
152        username: Option<&str>,
153    ) -> Result<bool> {
154        let mut params = vec![RequestParameter::new(
155            "business_connection_id",
156            serde_json::Value::String(business_connection_id.to_owned()),
157        )];
158        push_opt_str(&mut params, "username", username);
159        self.do_post("setBusinessAccountUsername", params).await
160    }
161
162    /// Use this method to set the bio of a business account.
163    ///
164    /// Calls the Telegram `setBusinessAccountBio` API method.
165    pub async fn set_business_account_bio_raw(
166        &self,
167        business_connection_id: &str,
168        bio: Option<&str>,
169    ) -> Result<bool> {
170        let mut params = vec![RequestParameter::new(
171            "business_connection_id",
172            serde_json::Value::String(business_connection_id.to_owned()),
173        )];
174        push_opt_str(&mut params, "bio", bio);
175        self.do_post("setBusinessAccountBio", params).await
176    }
177
178    /// Use this method to set the gift settings of a business account.
179    ///
180    /// Calls the Telegram `setBusinessAccountGiftSettings` API method.
181    pub async fn set_business_account_gift_settings_raw(
182        &self,
183        business_connection_id: &str,
184        show_gift_button: bool,
185        accepted_gift_types: gifts::AcceptedGiftTypes,
186    ) -> Result<bool> {
187        let params = vec![
188            RequestParameter::new(
189                "business_connection_id",
190                serde_json::Value::String(business_connection_id.to_owned()),
191            ),
192            RequestParameter::new("show_gift_button", serde_json::to_value(show_gift_button)?),
193            RequestParameter::new(
194                "accepted_gift_types",
195                serde_json::to_value(&accepted_gift_types)?,
196            ),
197        ];
198        self.do_post("setBusinessAccountGiftSettings", params).await
199    }
200
201    /// Use this method to set the profile photo of a business account.
202    ///
203    /// Calls the Telegram `setBusinessAccountProfilePhoto` API method.
204    pub async fn set_business_account_profile_photo_raw(
205        &self,
206        business_connection_id: &str,
207        photo: serde_json::Value,
208        is_public: Option<bool>,
209    ) -> Result<bool> {
210        let mut params = vec![
211            RequestParameter::new(
212                "business_connection_id",
213                serde_json::Value::String(business_connection_id.to_owned()),
214            ),
215            RequestParameter::new("photo", photo),
216        ];
217        push_opt(&mut params, "is_public", &is_public)?;
218        self.do_post("setBusinessAccountProfilePhoto", params).await
219    }
220
221    /// Use this method to remove the profile photo of a business account.
222    ///
223    /// Calls the Telegram `removeBusinessAccountProfilePhoto` API method.
224    pub async fn remove_business_account_profile_photo_raw(
225        &self,
226        business_connection_id: &str,
227        is_public: Option<bool>,
228    ) -> Result<bool> {
229        let mut params = vec![RequestParameter::new(
230            "business_connection_id",
231            serde_json::Value::String(business_connection_id.to_owned()),
232        )];
233        push_opt(&mut params, "is_public", &is_public)?;
234        self.do_post("removeBusinessAccountProfilePhoto", params)
235            .await
236    }
237
238    /// Use this method to convert a regular gift owned by a business account to Telegram Stars.
239    ///
240    /// Calls the Telegram `convertGiftToStars` API method.
241    pub async fn convert_gift_to_stars_raw(
242        &self,
243        business_connection_id: &str,
244        owned_gift_id: &str,
245    ) -> Result<bool> {
246        let params = vec![
247            RequestParameter::new(
248                "business_connection_id",
249                serde_json::Value::String(business_connection_id.to_owned()),
250            ),
251            RequestParameter::new(
252                "owned_gift_id",
253                serde_json::Value::String(owned_gift_id.to_owned()),
254            ),
255        ];
256        self.do_post("convertGiftToStars", params).await
257    }
258
259    /// Use this method to upgrade a regular gift to a unique gift.
260    ///
261    /// Calls the Telegram `upgradeGift` API method.
262    pub async fn upgrade_gift_raw(
263        &self,
264        business_connection_id: &str,
265        owned_gift_id: &str,
266        keep_original_details: Option<bool>,
267        star_count: Option<i64>,
268    ) -> Result<bool> {
269        let mut params = vec![
270            RequestParameter::new(
271                "business_connection_id",
272                serde_json::Value::String(business_connection_id.to_owned()),
273            ),
274            RequestParameter::new(
275                "owned_gift_id",
276                serde_json::Value::String(owned_gift_id.to_owned()),
277            ),
278        ];
279        push_opt(&mut params, "keep_original_details", &keep_original_details)?;
280        push_opt(&mut params, "star_count", &star_count)?;
281        self.do_post("upgradeGift", params).await
282    }
283
284    /// Use this method to transfer a unique gift to another user or channel chat.
285    ///
286    /// Calls the Telegram `transferGift` API method.
287    pub async fn transfer_gift_raw(
288        &self,
289        business_connection_id: &str,
290        owned_gift_id: &str,
291        new_owner_chat_id: i64,
292        star_count: Option<i64>,
293    ) -> Result<bool> {
294        let mut params = vec![
295            RequestParameter::new(
296                "business_connection_id",
297                serde_json::Value::String(business_connection_id.to_owned()),
298            ),
299            RequestParameter::new(
300                "owned_gift_id",
301                serde_json::Value::String(owned_gift_id.to_owned()),
302            ),
303            RequestParameter::new(
304                "new_owner_chat_id",
305                serde_json::to_value(new_owner_chat_id)?,
306            ),
307        ];
308        push_opt(&mut params, "star_count", &star_count)?;
309        self.do_post("transferGift", params).await
310    }
311
312    /// Use this method to transfer Telegram Stars from a business account to the bot's balance.
313    ///
314    /// Calls the Telegram `transferBusinessAccountStars` API method.
315    pub async fn transfer_business_account_stars_raw(
316        &self,
317        business_connection_id: &str,
318        star_count: i64,
319    ) -> Result<bool> {
320        let params = vec![
321            RequestParameter::new(
322                "business_connection_id",
323                serde_json::Value::String(business_connection_id.to_owned()),
324            ),
325            RequestParameter::new("star_count", serde_json::to_value(star_count)?),
326        ];
327        self.do_post("transferBusinessAccountStars", params).await
328    }
329}