1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
use serde::{Deserialize, Serialize};
/// This object represents one button of the reply keyboard. At most one of the fields other than text, `icon_custom_emoji_id`, and style must be used to specify the type of the button. For simple text buttons, String can be used instead of this object to specify the button text.
/// # Documentation
/// <https://core.telegram.org/bots/api#keyboardbutton>
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct KeyboardButton {
/// Text of the button. If none of the fields other than text, `icon_custom_emoji_id`, and style are used, it will be sent as a message when the button is pressed
pub text: Box<str>,
/// Unique identifier of the custom emoji shown before the text of the button. Can only be used by bots that purchased additional usernames on Fragment or in the messages directly sent by the bot to private, group and supergroup chats if the owner of the bot has a Telegram Premium subscription.
#[serde(skip_serializing_if = "Option::is_none")]
pub icon_custom_emoji_id: Option<Box<str>>,
/// Style of the button. Must be one of `danger` (red), `success` (green) or `primary` (blue). If omitted, then an app-specific style is used.
#[serde(skip_serializing_if = "Option::is_none")]
pub style: Option<Box<str>>,
/// If specified, pressing the button will open a list of suitable users. Identifiers of selected users will be sent to the bot in a `users_shared` service message. Available in private chats only.
#[serde(skip_serializing_if = "Option::is_none")]
pub request_users: Option<crate::types::KeyboardButtonRequestUsers>,
/// If specified, pressing the button will open a list of suitable chats. Tapping on a chat will send its identifier to the bot in a `chat_shared` service message. Available in private chats only.
#[serde(skip_serializing_if = "Option::is_none")]
pub request_chat: Option<crate::types::KeyboardButtonRequestChat>,
/// If specified, pressing the button will ask the user to create and share a bot that will be managed by the current bot. Available for bots that enabled management of other bots in the @`BotFather` Mini App. Available in private chats only.
#[serde(skip_serializing_if = "Option::is_none")]
pub request_managed_bot: Option<crate::types::KeyboardButtonRequestManagedBot>,
/// If `true`, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only.
#[serde(skip_serializing_if = "Option::is_none")]
pub request_contact: Option<bool>,
/// If `true`, the user's current location will be sent when the button is pressed. Available in private chats only.
#[serde(skip_serializing_if = "Option::is_none")]
pub request_location: Option<bool>,
/// If specified, the user will be asked to create a poll and send it to the bot when the button is pressed. Available in private chats only.
#[serde(skip_serializing_if = "Option::is_none")]
pub request_poll: Option<crate::types::KeyboardButtonPollType>,
/// If specified, the described Web App will be launched when the button is pressed. The Web App will be able to send a `web_app_data` service message. Available in private chats only.
#[serde(skip_serializing_if = "Option::is_none")]
pub web_app: Option<crate::types::WebAppInfo>,
}
impl KeyboardButton {
/// Creates a new `KeyboardButton`.
///
/// # Arguments
/// * `text` - Text of the button. If none of the fields other than text, `icon_custom_emoji_id`, and style are used, it will be sent as a message when the button is pressed
///
/// # Notes
/// Use builder methods to set optional fields.
#[must_use]
pub fn new<T0: Into<Box<str>>>(text: T0) -> Self {
Self {
text: text.into(),
icon_custom_emoji_id: None,
style: None,
request_users: None,
request_chat: None,
request_managed_bot: None,
request_contact: None,
request_location: None,
request_poll: None,
web_app: None,
}
}
/// Text of the button. If none of the fields other than text, `icon_custom_emoji_id`, and style are used, it will be sent as a message when the button is pressed
#[must_use]
pub fn text<T: Into<Box<str>>>(self, val: T) -> Self {
let mut this = self;
this.text = val.into();
this
}
/// Unique identifier of the custom emoji shown before the text of the button. Can only be used by bots that purchased additional usernames on Fragment or in the messages directly sent by the bot to private, group and supergroup chats if the owner of the bot has a Telegram Premium subscription.
#[must_use]
pub fn icon_custom_emoji_id<T: Into<Box<str>>>(self, val: T) -> Self {
let mut this = self;
this.icon_custom_emoji_id = Some(val.into());
this
}
/// Unique identifier of the custom emoji shown before the text of the button. Can only be used by bots that purchased additional usernames on Fragment or in the messages directly sent by the bot to private, group and supergroup chats if the owner of the bot has a Telegram Premium subscription.
#[must_use]
pub fn icon_custom_emoji_id_option<T: Into<Box<str>>>(self, val: Option<T>) -> Self {
let mut this = self;
this.icon_custom_emoji_id = val.map(Into::into);
this
}
/// Style of the button. Must be one of `danger` (red), `success` (green) or `primary` (blue). If omitted, then an app-specific style is used.
#[must_use]
pub fn style<T: Into<Box<str>>>(self, val: T) -> Self {
let mut this = self;
this.style = Some(val.into());
this
}
/// Style of the button. Must be one of `danger` (red), `success` (green) or `primary` (blue). If omitted, then an app-specific style is used.
#[must_use]
pub fn style_option<T: Into<Box<str>>>(self, val: Option<T>) -> Self {
let mut this = self;
this.style = val.map(Into::into);
this
}
/// If specified, pressing the button will open a list of suitable users. Identifiers of selected users will be sent to the bot in a `users_shared` service message. Available in private chats only.
#[must_use]
pub fn request_users<T: Into<crate::types::KeyboardButtonRequestUsers>>(self, val: T) -> Self {
let mut this = self;
this.request_users = Some(val.into());
this
}
/// If specified, pressing the button will open a list of suitable users. Identifiers of selected users will be sent to the bot in a `users_shared` service message. Available in private chats only.
#[must_use]
pub fn request_users_option<T: Into<crate::types::KeyboardButtonRequestUsers>>(
self,
val: Option<T>,
) -> Self {
let mut this = self;
this.request_users = val.map(Into::into);
this
}
/// If specified, pressing the button will open a list of suitable chats. Tapping on a chat will send its identifier to the bot in a `chat_shared` service message. Available in private chats only.
#[must_use]
pub fn request_chat<T: Into<crate::types::KeyboardButtonRequestChat>>(self, val: T) -> Self {
let mut this = self;
this.request_chat = Some(val.into());
this
}
/// If specified, pressing the button will open a list of suitable chats. Tapping on a chat will send its identifier to the bot in a `chat_shared` service message. Available in private chats only.
#[must_use]
pub fn request_chat_option<T: Into<crate::types::KeyboardButtonRequestChat>>(
self,
val: Option<T>,
) -> Self {
let mut this = self;
this.request_chat = val.map(Into::into);
this
}
/// If specified, pressing the button will ask the user to create and share a bot that will be managed by the current bot. Available for bots that enabled management of other bots in the @`BotFather` Mini App. Available in private chats only.
#[must_use]
pub fn request_managed_bot<T: Into<crate::types::KeyboardButtonRequestManagedBot>>(
self,
val: T,
) -> Self {
let mut this = self;
this.request_managed_bot = Some(val.into());
this
}
/// If specified, pressing the button will ask the user to create and share a bot that will be managed by the current bot. Available for bots that enabled management of other bots in the @`BotFather` Mini App. Available in private chats only.
#[must_use]
pub fn request_managed_bot_option<T: Into<crate::types::KeyboardButtonRequestManagedBot>>(
self,
val: Option<T>,
) -> Self {
let mut this = self;
this.request_managed_bot = val.map(Into::into);
this
}
/// If `true`, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only.
#[must_use]
pub fn request_contact<T: Into<bool>>(self, val: T) -> Self {
let mut this = self;
this.request_contact = Some(val.into());
this
}
/// If `true`, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only.
#[must_use]
pub fn request_contact_option<T: Into<bool>>(self, val: Option<T>) -> Self {
let mut this = self;
this.request_contact = val.map(Into::into);
this
}
/// If `true`, the user's current location will be sent when the button is pressed. Available in private chats only.
#[must_use]
pub fn request_location<T: Into<bool>>(self, val: T) -> Self {
let mut this = self;
this.request_location = Some(val.into());
this
}
/// If `true`, the user's current location will be sent when the button is pressed. Available in private chats only.
#[must_use]
pub fn request_location_option<T: Into<bool>>(self, val: Option<T>) -> Self {
let mut this = self;
this.request_location = val.map(Into::into);
this
}
/// If specified, the user will be asked to create a poll and send it to the bot when the button is pressed. Available in private chats only.
#[must_use]
pub fn request_poll<T: Into<crate::types::KeyboardButtonPollType>>(self, val: T) -> Self {
let mut this = self;
this.request_poll = Some(val.into());
this
}
/// If specified, the user will be asked to create a poll and send it to the bot when the button is pressed. Available in private chats only.
#[must_use]
pub fn request_poll_option<T: Into<crate::types::KeyboardButtonPollType>>(
self,
val: Option<T>,
) -> Self {
let mut this = self;
this.request_poll = val.map(Into::into);
this
}
/// If specified, the described Web App will be launched when the button is pressed. The Web App will be able to send a `web_app_data` service message. Available in private chats only.
#[must_use]
pub fn web_app<T: Into<crate::types::WebAppInfo>>(self, val: T) -> Self {
let mut this = self;
this.web_app = Some(val.into());
this
}
/// If specified, the described Web App will be launched when the button is pressed. The Web App will be able to send a `web_app_data` service message. Available in private chats only.
#[must_use]
pub fn web_app_option<T: Into<crate::types::WebAppInfo>>(self, val: Option<T>) -> Self {
let mut this = self;
this.web_app = val.map(Into::into);
this
}
}