Skip to main content

rustigram_api/methods/
miniapp.rs

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