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