Skip to main content

rustigram_api/methods/
business.rs

1use crate::client::BotClient;
2use crate::error::Result;
3use rustigram_types::payments::StarAmount;
4use rustigram_types::update::BusinessConnection;
5use rustigram_types::user::ChatId;
6use serde::Serialize;
7use std::future::{Future, IntoFuture};
8use std::pin::Pin;
9
10// ─── getBusinessConnection ────────────────────────────────────────────────────
11
12#[derive(Serialize)]
13struct GetBusinessConnectionParams {
14    business_connection_id: String,
15}
16
17/// Builder for the [`getBusinessConnection`](https://core.telegram.org/bots/api#getbusinessconnection) method.
18pub struct GetBusinessConnection {
19    client: BotClient,
20    params: GetBusinessConnectionParams,
21}
22
23impl GetBusinessConnection {
24    pub(crate) fn new(client: BotClient, id: impl Into<String>) -> Self {
25        Self {
26            client,
27            params: GetBusinessConnectionParams {
28                business_connection_id: id.into(),
29            },
30        }
31    }
32}
33
34impl IntoFuture for GetBusinessConnection {
35    type Output = Result<BusinessConnection>;
36    type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
37    fn into_future(self) -> Self::IntoFuture {
38        Box::pin(async move {
39            self.client
40                .post_json("getBusinessConnection", &self.params)
41                .await
42        })
43    }
44}
45
46// ─── readBusinessMessage ──────────────────────────────────────────────────────
47
48#[derive(Serialize)]
49struct ReadBusinessMessageParams {
50    business_connection_id: String,
51    chat_id: ChatId,
52    message_id: i64,
53}
54
55/// Builder for the [`readBusinessMessage`](https://core.telegram.org/bots/api#readbusinessmessage) method.
56pub struct ReadBusinessMessage {
57    client: BotClient,
58    params: ReadBusinessMessageParams,
59}
60
61impl ReadBusinessMessage {
62    pub(crate) fn new(
63        client: BotClient,
64        business_connection_id: impl Into<String>,
65        chat_id: impl Into<ChatId>,
66        message_id: i64,
67    ) -> Self {
68        Self {
69            client,
70            params: ReadBusinessMessageParams {
71                business_connection_id: business_connection_id.into(),
72                chat_id: chat_id.into(),
73                message_id,
74            },
75        }
76    }
77}
78
79impl IntoFuture for ReadBusinessMessage {
80    type Output = Result<bool>;
81    type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
82    fn into_future(self) -> Self::IntoFuture {
83        Box::pin(async move {
84            self.client
85                .post_json("readBusinessMessage", &self.params)
86                .await
87        })
88    }
89}
90
91// ─── deleteBusinessMessages ───────────────────────────────────────────────────
92
93#[derive(Serialize)]
94struct DeleteBusinessMessagesParams {
95    business_connection_id: String,
96    message_ids: Vec<i64>,
97}
98
99/// Builder for the [`deleteBusinessMessages`](https://core.telegram.org/bots/api#deletebusinessmessages) method.
100pub struct DeleteBusinessMessages {
101    client: BotClient,
102    params: DeleteBusinessMessagesParams,
103}
104
105impl DeleteBusinessMessages {
106    pub(crate) fn new(
107        client: BotClient,
108        business_connection_id: impl Into<String>,
109        message_ids: Vec<i64>,
110    ) -> Self {
111        Self {
112            client,
113            params: DeleteBusinessMessagesParams {
114                business_connection_id: business_connection_id.into(),
115                message_ids,
116            },
117        }
118    }
119}
120
121impl IntoFuture for DeleteBusinessMessages {
122    type Output = Result<bool>;
123    type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
124    fn into_future(self) -> Self::IntoFuture {
125        Box::pin(async move {
126            self.client
127                .post_json("deleteBusinessMessages", &self.params)
128                .await
129        })
130    }
131}
132
133// ─── setBusinessAccountName ───────────────────────────────────────────────────
134
135#[derive(Serialize)]
136struct SetBusinessAccountNameParams {
137    business_connection_id: String,
138    first_name: String,
139    #[serde(skip_serializing_if = "Option::is_none")]
140    last_name: Option<String>,
141}
142
143/// Builder for the [`setBusinessAccountName`](https://core.telegram.org/bots/api#setbusinessaccountname) method.
144pub struct SetBusinessAccountName {
145    client: BotClient,
146    params: SetBusinessAccountNameParams,
147}
148
149impl SetBusinessAccountName {
150    pub(crate) fn new(
151        client: BotClient,
152        business_connection_id: impl Into<String>,
153        first_name: String,
154        last_name: Option<String>,
155    ) -> Self {
156        Self {
157            client,
158            params: SetBusinessAccountNameParams {
159                business_connection_id: business_connection_id.into(),
160                first_name,
161                last_name,
162            },
163        }
164    }
165}
166
167impl IntoFuture for SetBusinessAccountName {
168    type Output = Result<bool>;
169    type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
170    fn into_future(self) -> Self::IntoFuture {
171        Box::pin(async move {
172            self.client
173                .post_json("setBusinessAccountName", &self.params)
174                .await
175        })
176    }
177}
178
179// ─── setBusinessAccountUsername ───────────────────────────────────────────────
180
181#[derive(Serialize)]
182struct SetBusinessAccountUsernameParams {
183    business_connection_id: String,
184    #[serde(skip_serializing_if = "Option::is_none")]
185    username: Option<String>,
186}
187
188/// Builder for the [`setBusinessAccountUsername`](https://core.telegram.org/bots/api#setbusinessaccountusername) method.
189pub struct SetBusinessAccountUsername {
190    client: BotClient,
191    params: SetBusinessAccountUsernameParams,
192}
193
194impl SetBusinessAccountUsername {
195    pub(crate) fn new(
196        client: BotClient,
197        business_connection_id: impl Into<String>,
198        username: Option<String>,
199    ) -> Self {
200        Self {
201            client,
202            params: SetBusinessAccountUsernameParams {
203                business_connection_id: business_connection_id.into(),
204                username,
205            },
206        }
207    }
208}
209
210impl IntoFuture for SetBusinessAccountUsername {
211    type Output = Result<bool>;
212    type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
213    fn into_future(self) -> Self::IntoFuture {
214        Box::pin(async move {
215            self.client
216                .post_json("setBusinessAccountUsername", &self.params)
217                .await
218        })
219    }
220}
221
222// ─── setBusinessAccountBio ────────────────────────────────────────────────────
223
224#[derive(Serialize)]
225struct SetBusinessAccountBioParams {
226    business_connection_id: String,
227    #[serde(skip_serializing_if = "Option::is_none")]
228    bio: Option<String>,
229}
230
231/// Builder for the [`setBusinessAccountBio`](https://core.telegram.org/bots/api#setbusinessaccountbio) method.
232pub struct SetBusinessAccountBio {
233    client: BotClient,
234    params: SetBusinessAccountBioParams,
235}
236
237impl SetBusinessAccountBio {
238    pub(crate) fn new(
239        client: BotClient,
240        business_connection_id: impl Into<String>,
241        bio: Option<String>,
242    ) -> Self {
243        Self {
244            client,
245            params: SetBusinessAccountBioParams {
246                business_connection_id: business_connection_id.into(),
247                bio,
248            },
249        }
250    }
251}
252
253impl IntoFuture for SetBusinessAccountBio {
254    type Output = Result<bool>;
255    type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
256    fn into_future(self) -> Self::IntoFuture {
257        Box::pin(async move {
258            self.client
259                .post_json("setBusinessAccountBio", &self.params)
260                .await
261        })
262    }
263}
264
265// ─── getBusinessAccountStarBalance ───────────────────────────────────────────
266
267#[derive(Serialize)]
268struct BizConnectionIdParams {
269    business_connection_id: String,
270}
271
272/// Builder for the [`getBusinessAccountStarBalance`](https://core.telegram.org/bots/api#getbusinessaccountstarbalance) method.
273pub struct GetBusinessAccountStarBalance {
274    client: BotClient,
275    params: BizConnectionIdParams,
276}
277
278impl GetBusinessAccountStarBalance {
279    pub(crate) fn new(client: BotClient, id: impl Into<String>) -> Self {
280        Self {
281            client,
282            params: BizConnectionIdParams {
283                business_connection_id: id.into(),
284            },
285        }
286    }
287}
288
289impl IntoFuture for GetBusinessAccountStarBalance {
290    type Output = Result<StarAmount>;
291    type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
292    fn into_future(self) -> Self::IntoFuture {
293        Box::pin(async move {
294            self.client
295                .post_json("getBusinessAccountStarBalance", &self.params)
296                .await
297        })
298    }
299}
300
301// ─── transferBusinessAccountStars ─────────────────────────────────────────────
302
303#[derive(Serialize)]
304struct TransferBusinessAccountStarsParams {
305    business_connection_id: String,
306    star_count: u64,
307}
308
309/// Builder for the [`transferBusinessAccountStars`](https://core.telegram.org/bots/api#transferbusinessaccountstars) method.
310pub struct TransferBusinessAccountStars {
311    client: BotClient,
312    params: TransferBusinessAccountStarsParams,
313}
314
315impl TransferBusinessAccountStars {
316    pub(crate) fn new(
317        client: BotClient,
318        business_connection_id: impl Into<String>,
319        star_count: u64,
320    ) -> Self {
321        Self {
322            client,
323            params: TransferBusinessAccountStarsParams {
324                business_connection_id: business_connection_id.into(),
325                star_count,
326            },
327        }
328    }
329}
330
331impl IntoFuture for TransferBusinessAccountStars {
332    type Output = Result<bool>;
333    type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
334    fn into_future(self) -> Self::IntoFuture {
335        Box::pin(async move {
336            self.client
337                .post_json("transferBusinessAccountStars", &self.params)
338                .await
339        })
340    }
341}
342
343// ─── setBusinessAccountProfilePhoto ──────────────────────────────────────────
344
345#[derive(Serialize)]
346struct SetBusinessAccountProfilePhotoParams {
347    business_connection_id: String,
348    /// The new profile photo.
349    ///
350    /// Uses `serde_json::Value` — serialise from
351    /// `rustigram_types::file::InputProfilePhoto` with `serde_json::to_value`.
352    photo: serde_json::Value,
353    #[serde(skip_serializing_if = "Option::is_none")]
354    is_public: Option<bool>,
355}
356
357/// Builder for the [`setBusinessAccountProfilePhoto`](https://core.telegram.org/bots/api#setbusinessaccountprofilephoto) method.
358///
359/// Changes the profile photo of a managed business account.
360/// Requires the `can_edit_profile_photo` business bot right.
361///
362/// Pass the `photo` as `serde_json::to_value(&input_profile_photo)`.
363pub struct SetBusinessAccountProfilePhoto {
364    client: BotClient,
365    params: SetBusinessAccountProfilePhotoParams,
366}
367
368impl SetBusinessAccountProfilePhoto {
369    pub(crate) fn new(
370        client: BotClient,
371        business_connection_id: impl Into<String>,
372        photo: serde_json::Value,
373    ) -> Self {
374        Self {
375            client,
376            params: SetBusinessAccountProfilePhotoParams {
377                business_connection_id: business_connection_id.into(),
378                photo,
379                is_public: None,
380            },
381        }
382    }
383    /// Pass `true` to set the public photo, visible even if the main photo is
384    /// hidden by the account's privacy settings. An account can have only one public photo.
385    pub fn is_public(mut self, v: bool) -> Self {
386        self.params.is_public = Some(v);
387        self
388    }
389}
390
391impl IntoFuture for SetBusinessAccountProfilePhoto {
392    type Output = Result<bool>;
393    type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
394    fn into_future(self) -> Self::IntoFuture {
395        Box::pin(async move {
396            self.client
397                .post_json("setBusinessAccountProfilePhoto", &self.params)
398                .await
399        })
400    }
401}
402
403// ─── removeBusinessAccountProfilePhoto ───────────────────────────────────────
404
405#[derive(Serialize)]
406struct RemoveBusinessAccountProfilePhotoParams {
407    business_connection_id: String,
408    #[serde(skip_serializing_if = "Option::is_none")]
409    is_public: Option<bool>,
410}
411
412/// Builder for the [`removeBusinessAccountProfilePhoto`](https://core.telegram.org/bots/api#removebusinessaccountprofilephoto) method.
413///
414/// Removes the current profile photo of a managed business account.
415/// Requires the `can_edit_profile_photo` business bot right.
416pub struct RemoveBusinessAccountProfilePhoto {
417    client: BotClient,
418    params: RemoveBusinessAccountProfilePhotoParams,
419}
420
421impl RemoveBusinessAccountProfilePhoto {
422    pub(crate) fn new(client: BotClient, business_connection_id: impl Into<String>) -> Self {
423        Self {
424            client,
425            params: RemoveBusinessAccountProfilePhotoParams {
426                business_connection_id: business_connection_id.into(),
427                is_public: None,
428            },
429        }
430    }
431    /// Pass `true` to remove the public photo instead of the main photo.
432    pub fn is_public(mut self, v: bool) -> Self {
433        self.params.is_public = Some(v);
434        self
435    }
436}
437
438impl IntoFuture for RemoveBusinessAccountProfilePhoto {
439    type Output = Result<bool>;
440    type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
441    fn into_future(self) -> Self::IntoFuture {
442        Box::pin(async move {
443            self.client
444                .post_json("removeBusinessAccountProfilePhoto", &self.params)
445                .await
446        })
447    }
448}
449
450// ─── setBusinessAccountGiftSettings ──────────────────────────────────────────
451
452#[derive(Serialize)]
453struct SetBusinessAccountGiftSettingsParams {
454    business_connection_id: String,
455    show_gift_button: bool,
456    accepted_gift_types: rustigram_types::payments::AcceptedGiftTypes,
457}
458
459/// Builder for the [`setBusinessAccountGiftSettings`](https://core.telegram.org/bots/api#setbusinessaccountgiftsettings) method.
460///
461/// Changes the gift privacy settings of a managed business account.
462/// Requires the `can_change_gift_settings` business bot right.
463pub struct SetBusinessAccountGiftSettings {
464    client: BotClient,
465    params: SetBusinessAccountGiftSettingsParams,
466}
467
468impl SetBusinessAccountGiftSettings {
469    pub(crate) fn new(
470        client: BotClient,
471        business_connection_id: impl Into<String>,
472        show_gift_button: bool,
473        accepted_gift_types: rustigram_types::payments::AcceptedGiftTypes,
474    ) -> Self {
475        Self {
476            client,
477            params: SetBusinessAccountGiftSettingsParams {
478                business_connection_id: business_connection_id.into(),
479                show_gift_button,
480                accepted_gift_types,
481            },
482        }
483    }
484}
485
486impl IntoFuture for SetBusinessAccountGiftSettings {
487    type Output = Result<bool>;
488    type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
489    fn into_future(self) -> Self::IntoFuture {
490        Box::pin(async move {
491            self.client
492                .post_json("setBusinessAccountGiftSettings", &self.params)
493                .await
494        })
495    }
496}