telexide_fork/model/
markup.rs

1use super::{CallbackGame, LoginUrl};
2use serde::{Deserialize, Serialize};
3
4/// This object represents an [inline keyboard] that appears right next to the
5/// message it belongs to.
6///
7/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
8#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
9pub struct InlineKeyboardMarkup {
10    /// Vec of button rows, each represented by a Vec of
11    /// [`InlineKeyboardButton`] objects
12    pub inline_keyboard: Vec<Vec<InlineKeyboardButton>>,
13}
14
15/// This object represents one button of an inline keyboard.
16/// You **must** use exactly one of the optional fields.
17#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
18pub struct InlineKeyboardButton {
19    /// Label text on the button
20    pub text: String,
21    /// HTTP or tg:// url to be opened when button is pressed
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub url: Option<String>,
24    /// An HTTP URL used to automatically authorize the user.
25    /// Can be used as a replacement for the [Telegram Login Widget][widget].
26    ///
27    /// [widget]: https://core.telegram.org/widgets/login
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub login_url: Option<LoginUrl>,
30    /// Data to be sent in a [callback query] to the bot when button is pressed,
31    /// 1-64 bytes
32    ///
33    /// [callback query]: ../model/struct.CallbackQuery.html
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub callback_data: Option<String>,
36    /// If set, pressing the button will prompt the user to select one of their
37    /// chats, open that chat and insert the bot‘s username and the
38    /// specified inline query in the input field. Can be empty, in which
39    /// case just the bot’s username will be inserted.
40    ///
41    /// **Note:** This offers an easy way for users to start using your bot in
42    /// inline mode when they are currently in a private chat with it.
43    /// Especially useful when combined with switch_pm… actions – in this case
44    /// the user will be automatically returned to the chat they switched
45    /// from, skipping the chat selection screen.
46    ///
47    /// [inline mode]: https://core.telegram.org/bots/inline
48    /// [switch_pm]: ../api/trait.API.html#method.answer_callback_query
49    #[serde(skip_serializing_if = "Option::is_none")]
50    pub switch_inline_query: Option<String>,
51    /// If set, pressing the button will insert the bot‘s username and the
52    /// specified inline query in the current chat's input field. Can be
53    /// empty, in which case only the bot’s username will be inserted.
54    ///
55    /// This offers a quick way for the user to open your bot in inline mode in
56    /// the same chat – good for selecting something from multiple options.
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub switch_inline_query_current_chat: Option<String>,
59    /// Description of the game that will be launched when the user presses the
60    /// button.
61    ///
62    /// **NOTE:** This type of button must always be the first button in the
63    /// first row.
64    #[serde(skip_serializing_if = "Option::is_none")]
65    pub callback_game: Option<CallbackGame>,
66    /// Specify True, to send a [Pay button].
67    ///
68    /// **NOTE:** This type of button must always be the first button in the
69    /// first row.
70    ///
71    /// [Pay button]: https://core.telegram.org/bots/api#payments
72    #[serde(skip_serializing_if = "Option::is_none")]
73    pub pay: Option<bool>,
74}
75
76/// This object represents a custom keyboard with reply options
77/// (see [Introduction to bots][keyboards] for details and examples).
78///
79/// [keyboards]: https://core.telegram.org/bots#keyboards
80#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
81pub struct ReplyKeyboardMarkup {
82    /// Vec of button rows, each represented by a Vec of [`KeyboardButton`]
83    /// objects
84    pub keyboard: Vec<Vec<KeyboardButton>>,
85    /// Requests clients to resize the keyboard vertically for optimal fit
86    /// (e.g., make the keyboard smaller if there are just two rows of buttons).
87    /// Defaults to false, in which case the custom keyboard is always of the
88    /// same height as the app's standard keyboard.
89    #[serde(default)]
90    pub resize_keyboard: bool,
91    /// Requests clients to hide the keyboard as soon as it's been used.
92    /// The keyboard will still be available, but clients will automatically
93    /// display the usual letter-keyboard in the chat – the user can press a
94    /// special button in the input field to see the custom keyboard again.
95    /// Defaults to false.
96    #[serde(default)]
97    pub one_time_keyboard: bool,
98    /// Use this parameter if you want to show the keyboard to specific users
99    /// only. Targets: 1) users that are @mentioned in the text of the
100    /// [`Message`] object; 2) if the bot's message is a reply (has
101    /// reply_to_message_id), sender of the original message.
102    ///
103    /// Example: A user requests to change the bot‘s language,
104    /// bot replies to the request with akeyboard to select the new language.
105    /// Other users in the group don’t see the keyboard.
106    ///
107    /// [`Message`]: ../model/struct.Message.html
108    #[serde(default)]
109    pub selective: bool,
110}
111
112/// Upon receiving a message with this object, Telegram clients will remove
113/// the current custom keyboard and display the default letter-keyboard.
114/// By default, custom keyboards are displayed until a new keyboard is sent by a
115/// bot. An exception is made for one-time keyboards that are hidden immediately
116/// after the user presses a button (see [`ReplyKeyboardMarkup`]).
117#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
118pub struct ReplyKeyboardRemove {
119    /// Requests clients to remove the custom keyboard (user will not be able to
120    /// summon this keyboard; if you want to hide the keyboard from sight
121    /// but keep it accessible, use one_time_keyboard in
122    /// [`ReplyKeyboardMarkup`])
123    ///
124    /// **warning:** this field always has to be true
125    pub remove_keyboard: bool,
126    /// Use this parameter if you want to remove the keyboard for specific users
127    /// only. Targets: 1) users that are @mentioned in the text of the
128    /// [`Message`] object; 2) if the bot's message is a reply (has
129    /// reply_to_message_id), sender of the original message.
130    ///
131    /// Example: A user votes in a poll, bot returns confirmation message in
132    /// reply to the vote and removes the keyboard for that user, while
133    /// still showing the keyboard with poll options to users who haven't voted
134    /// yet.
135    ///
136    /// [`Message`]: ../model/struct.Message.html
137    #[serde(default)]
138    pub selective: bool,
139}
140
141/// Upon receiving a message with this object, Telegram clients will display a
142/// reply interface to the user (act as if the user has selected the bot‘s
143/// message and tapped ’Reply'). This can be extremely useful if you want to
144/// create user-friendly step-by-step interfaces without having to sacrifice
145/// [privacy mode].
146///
147/// [privacy mode]: https://core.telegram.org/bots#privacy-mode
148#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
149pub struct ForceReply {
150    /// Upon receiving a message with this object, Telegram clients will display
151    /// a reply interface to the user (act as if the user has selected the bot‘s
152    /// message and tapped ’Reply'). This can be extremely useful if you
153    /// want to create user-friendly step-by-step interfaces without having to
154    /// sacrifice [privacy mode].
155    ///
156    /// **warning:** this field always has to be true
157    ///
158    /// [privacy mode]: https://core.telegram.org/bots#privacy-mode
159    pub force_reply: bool,
160    /// Optional. Use this parameter if you want to force reply from specific
161    /// users only. Targets: 1) users that are @mentioned in the text of the
162    /// [`Message`] object; 2) if the bot's message is a reply (has
163    /// reply_to_message_id), sender of the original message.
164    ///
165    /// [`Message`]: ../model/struct.Message.html
166    #[serde(default)]
167    pub selective: bool,
168}
169
170/// This object represents one button of the reply keyboard.
171/// For simple text buttons String can be used instead of this object to specify
172/// text of the button.
173///
174/// **Note:** Optional fields `request_contact`, `request_location`, and
175/// `request_poll` are mutually exclusive.
176#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
177pub struct KeyboardButton {
178    /// Text of the button. If none of the optional fields are used,
179    /// it will be sent as a message when the button is pressed
180    pub text: String,
181    /// If true, the user's phone number will be sent as a contact when the
182    /// button is pressed. Available in private chats only
183    pub request_contact: bool,
184    /// If true, the user's current location will be sent when the button is
185    /// pressed. Available in private chats only
186    pub request_location: bool,
187    /// If specified, the user will be asked to create a poll and send it to the
188    /// bot when the button is pressed. Available in private chats only
189    #[serde(skip_serializing_if = "Option::is_none")]
190    pub request_poll: Option<KeyboardButtonPollType>,
191}
192
193/// This object represents type of a poll, which is allowed to be created and
194/// sent when the corresponding button is pressed.
195#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
196pub struct KeyboardButtonPollType {
197    /// If quiz is passed, the user will be allowed to create only polls in the
198    /// quiz mode. If regular is passed, only regular polls will be allowed.
199    /// Otherwise, the user will be allowed to create a poll of any type.
200    #[serde(rename = "type")]
201    pub poll_type: super::PollType,
202}