tgbot/types/inline_mode/prepared/
mod.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{
4    api::{Method, Payload},
5    types::{InlineQueryResult, Integer},
6};
7
8#[cfg(test)]
9mod tests;
10
11/// Describes an inline message to be sent by a user of a Mini App.
12#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
13pub struct PreparedInlineMessage {
14    /// Unique identifier of the prepared message.
15    pub id: String,
16    /// Expiration date of the prepared message, in Unix time.
17    /// Expired prepared messages can no longer be used.
18    pub expiration_date: Integer,
19}
20
21impl PreparedInlineMessage {
22    /// Creates a new `PreparedInlineMessage`.
23    ///
24    /// # Arguments
25    ///
26    /// * `id` - Unique identifier of the prepared message.
27    /// * `expiration_date` - Expiration date of the prepared message, in Unix time.
28    pub fn new<T>(id: T, expiration_date: Integer) -> Self
29    where
30        T: Into<String>,
31    {
32        Self {
33            id: id.into(),
34            expiration_date,
35        }
36    }
37}
38
39/// Stores a message that can be sent by a user of a Mini App.
40#[serde_with::skip_serializing_none]
41#[derive(Clone, Debug, Serialize)]
42pub struct SavePreparedInlineMessage {
43    result: InlineQueryResult,
44    user_id: Integer,
45    allow_bot_chats: Option<bool>,
46    allow_channel_chats: Option<bool>,
47    allow_group_chats: Option<bool>,
48    allow_user_chats: Option<bool>,
49}
50
51impl SavePreparedInlineMessage {
52    /// Creates a new `SavePreparedInlineMessage`.
53    ///
54    /// # Arguments
55    ///
56    /// * `user_id` - Unique identifier of the target user that can use the prepared message.
57    /// * `result` - An object describing the message to be sent
58    pub fn new<T>(user_id: Integer, result: T) -> Self
59    where
60        T: Into<InlineQueryResult>,
61    {
62        Self {
63            user_id,
64            result: result.into(),
65            allow_bot_chats: None,
66            allow_channel_chats: None,
67            allow_group_chats: None,
68            allow_user_chats: None,
69        }
70    }
71
72    /// Sets a new value for the `allow_bot_chats` flag.
73    ///
74    /// # Arguments
75    ///
76    /// * `value` - Whether the message can be sent to private chats with bots.
77    pub fn with_allow_bot_chats(mut self, value: bool) -> Self {
78        self.allow_bot_chats = Some(value);
79        self
80    }
81
82    /// Sets a new value for the `allow_channel_chats` flag.
83    ///
84    /// # Arguments
85    ///
86    /// * `value` - Whether the message can be sent to channel chats.
87    pub fn with_allow_channel_chats(mut self, value: bool) -> Self {
88        self.allow_channel_chats = Some(value);
89        self
90    }
91
92    /// Sets a new value for the `allow_group_chats` flag.
93    ///
94    /// # Arguments
95    ///
96    /// * `value` - Whether the message can be sent to group and supergroup chats.
97    pub fn with_allow_group_chats(mut self, value: bool) -> Self {
98        self.allow_group_chats = Some(value);
99        self
100    }
101
102    /// Sets a new value for the `allow_user_chats` flag.
103    ///
104    /// # Arguments
105    ///
106    /// * `value` - Whether the message can be sent to private chats with users.
107    pub fn with_allow_user_chats(mut self, value: bool) -> Self {
108        self.allow_user_chats = Some(value);
109        self
110    }
111}
112
113impl Method for SavePreparedInlineMessage {
114    type Response = PreparedInlineMessage;
115
116    fn into_payload(self) -> Payload {
117        Payload::json("savePreparedInlineMessage", self)
118    }
119}