Skip to main content

rustigram_api/methods/
miniapp.rs

1use rustigram_types::keyboard::PreparedKeyboardButton;
2
3use crate::client::BotClient;
4use crate::error::Result;
5use rustigram_types::keyboard::KeyboardButton;
6use serde::Serialize;
7use std::future::{Future, IntoFuture};
8use std::pin::Pin;
9
10// ─── Helper macro ─────────────────────────────────────────────────────────────
11
12macro_rules! impl_into_future {
13    ($builder:ident, $return_ty:ty, $method:literal) => {
14        impl IntoFuture for $builder {
15            type Output = Result<$return_ty>;
16            type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
17            fn into_future(self) -> Self::IntoFuture {
18                Box::pin(async move { self.client.post_json($method, &self.params).await })
19            }
20        }
21    };
22}
23
24// ─── savePreparedKeyboardButton ───────────────────────────────────────────────
25
26#[derive(Serialize)]
27struct SavePreparedKeyboardButtonParams {
28    user_id: i64,
29    button: KeyboardButton,
30}
31
32/// Builder for the [`savePreparedKeyboardButton`](https://core.telegram.org/bots/api#savepreparedkeyboardbutton) method (Bot API 9.6).
33///
34/// Stores a keyboard button that can be used by a user within a Mini App.
35/// The button must be of type `request_users`, `request_chat`, or `request_managed_bot`.
36///
37/// Returns the prepared button.
38pub struct SavePreparedKeyboardButton {
39    client: BotClient,
40    params: SavePreparedKeyboardButtonParams,
41}
42
43impl SavePreparedKeyboardButton {
44    pub(crate) fn new(client: BotClient, user_id: i64, button: KeyboardButton) -> Self {
45        Self {
46            client,
47            params: SavePreparedKeyboardButtonParams { user_id, button },
48        }
49    }
50}
51impl_into_future!(
52    SavePreparedKeyboardButton,
53    PreparedKeyboardButton,
54    "savePreparedKeyboardButton"
55);
56
57// ─── setUserEmojiStatus ───────────────────────────────────────────────────────
58
59#[derive(Serialize)]
60struct SetUserEmojiStatusParams {
61    user_id: i64,
62    #[serde(skip_serializing_if = "Option::is_none")]
63    emoji_status_custom_emoji_id: Option<String>,
64    #[serde(skip_serializing_if = "Option::is_none")]
65    emoji_status_expiration_date: Option<i64>,
66}
67
68/// Builder for the [`setUserEmojiStatus`](https://core.telegram.org/bots/api#setuseremojistatus) method.
69///
70/// Changes the emoji status for a user who previously allowed the bot to manage
71/// their emoji status via the Mini App method `requestEmojiStatusAccess`.
72///
73/// Omit `emoji_status_custom_emoji_id` or pass an empty string to remove the status.
74pub struct SetUserEmojiStatus {
75    client: BotClient,
76    params: SetUserEmojiStatusParams,
77}
78
79impl SetUserEmojiStatus {
80    pub(crate) fn new(client: BotClient, user_id: i64) -> Self {
81        Self {
82            client,
83            params: SetUserEmojiStatusParams {
84                user_id,
85                emoji_status_custom_emoji_id: None,
86                emoji_status_expiration_date: None,
87            },
88        }
89    }
90    /// Sets the custom emoji identifier for the emoji status.
91    /// Pass an empty string to remove the current status.
92    pub fn emoji_status_custom_emoji_id(mut self, id: impl Into<String>) -> Self {
93        self.params.emoji_status_custom_emoji_id = Some(id.into());
94        self
95    }
96    /// Sets the expiration date of the emoji status as a Unix timestamp.
97    pub fn emoji_status_expiration_date(mut self, ts: i64) -> Self {
98        self.params.emoji_status_expiration_date = Some(ts);
99        self
100    }
101}
102
103impl_into_future!(SetUserEmojiStatus, bool, "setUserEmojiStatus");