Skip to main content

tgbot/types/definitions/reply/markup/
prepared.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{
4    api::{Method, Payload},
5    types::{Integer, KeyboardButton},
6};
7
8/// Describes a keyboard button to be used by a user of a Mini App.
9#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
10pub struct PreparedKeyboardButton {
11    id: String,
12}
13
14impl<T> From<T> for PreparedKeyboardButton
15where
16    T: Into<String>,
17{
18    fn from(value: T) -> Self {
19        Self { id: value.into() }
20    }
21}
22
23/// Stores a keyboard button that can be used by a user within a Mini App.
24#[derive(Clone, Debug, Serialize)]
25pub struct SavePreparedKeyboardButton {
26    user_id: Integer,
27    button: KeyboardButton,
28}
29
30impl SavePreparedKeyboardButton {
31    /// Creates a new `SavePreparedKeyboardButton`.
32    ///
33    /// # Arguments
34    ///
35    /// * `user_id` - Unique identifier of the target user that can use the button.
36    /// * `button` - An object describing the button to be saved;
37    ///   the button must be of the type request_users, request_chat, or request_managed_bot.
38    pub fn new(user_id: Integer, button: KeyboardButton) -> Self {
39        Self { user_id, button }
40    }
41}
42
43impl Method for SavePreparedKeyboardButton {
44    type Response = PreparedKeyboardButton;
45
46    fn into_payload(self) -> Payload {
47        Payload::json("savePreparedKeyboardButton", self)
48    }
49}