1use ferogram_tl_types as tl;
30
31#[derive(Clone)]
35pub struct Button {
36 inner: tl::enums::KeyboardButton,
37}
38
39impl Button {
40 pub fn callback(text: impl Into<String>, data: impl Into<Vec<u8>>) -> Self {
42 Self {
43 inner: tl::enums::KeyboardButton::Callback(tl::types::KeyboardButtonCallback {
44 requires_password: false,
45 text: text.into(),
46 data: data.into(),
47 style: None,
48 }),
49 }
50 }
51
52 pub fn url(text: impl Into<String>, url: impl Into<String>) -> Self {
54 Self {
55 inner: tl::enums::KeyboardButton::Url(tl::types::KeyboardButtonUrl {
56 text: text.into(),
57 url: url.into(),
58 style: None,
59 }),
60 }
61 }
62
63 pub fn url_auth(
65 text: impl Into<String>,
66 url: impl Into<String>,
67 fwd_text: Option<String>,
68 bot: tl::enums::InputUser,
69 ) -> Self {
70 Self {
71 inner: tl::enums::KeyboardButton::InputKeyboardButtonUrlAuth(
72 tl::types::InputKeyboardButtonUrlAuth {
73 request_write_access: false,
74 text: text.into(),
75 fwd_text,
76 url: url.into(),
77 bot,
78 style: None,
79 },
80 ),
81 }
82 }
83
84 pub fn switch_inline(text: impl Into<String>, query: impl Into<String>) -> Self {
86 Self {
87 inner: tl::enums::KeyboardButton::SwitchInline(tl::types::KeyboardButtonSwitchInline {
88 same_peer: true,
89 peer_types: None,
90 text: text.into(),
91 query: query.into(),
92 style: None,
93 }),
94 }
95 }
96
97 pub fn text(label: impl Into<String>) -> Self {
99 Self {
100 inner: tl::enums::KeyboardButton::KeyboardButton(tl::types::KeyboardButton {
101 text: label.into(),
102 style: None,
103 }),
104 }
105 }
106
107 pub fn switch_elsewhere(text: impl Into<String>, query: impl Into<String>) -> Self {
109 Self {
110 inner: tl::enums::KeyboardButton::SwitchInline(tl::types::KeyboardButtonSwitchInline {
111 same_peer: false,
112 peer_types: None,
113 text: text.into(),
114 query: query.into(),
115 style: None,
116 }),
117 }
118 }
119
120 pub fn webview(text: impl Into<String>, url: impl Into<String>) -> Self {
122 Self {
123 inner: tl::enums::KeyboardButton::WebView(tl::types::KeyboardButtonWebView {
124 text: text.into(),
125 url: url.into(),
126 style: None,
127 }),
128 }
129 }
130
131 pub fn simple_webview(text: impl Into<String>, url: impl Into<String>) -> Self {
133 Self {
134 inner: tl::enums::KeyboardButton::SimpleWebView(
135 tl::types::KeyboardButtonSimpleWebView {
136 text: text.into(),
137 url: url.into(),
138 style: None,
139 },
140 ),
141 }
142 }
143
144 pub fn request_phone(text: impl Into<String>) -> Self {
146 Self {
147 inner: tl::enums::KeyboardButton::RequestPhone(tl::types::KeyboardButtonRequestPhone {
148 text: text.into(),
149 style: None,
150 }),
151 }
152 }
153
154 pub fn request_geo(text: impl Into<String>) -> Self {
156 Self {
157 inner: tl::enums::KeyboardButton::RequestGeoLocation(
158 tl::types::KeyboardButtonRequestGeoLocation {
159 text: text.into(),
160 style: None,
161 },
162 ),
163 }
164 }
165
166 pub fn request_poll(text: impl Into<String>) -> Self {
168 Self {
169 inner: tl::enums::KeyboardButton::RequestPoll(tl::types::KeyboardButtonRequestPoll {
170 quiz: None,
171 text: text.into(),
172 style: None,
173 }),
174 }
175 }
176
177 pub fn request_quiz(text: impl Into<String>) -> Self {
179 Self {
180 inner: tl::enums::KeyboardButton::RequestPoll(tl::types::KeyboardButtonRequestPoll {
181 quiz: Some(true),
182 text: text.into(),
183 style: None,
184 }),
185 }
186 }
187
188 pub fn game(text: impl Into<String>) -> Self {
190 Self {
191 inner: tl::enums::KeyboardButton::Game(tl::types::KeyboardButtonGame {
192 text: text.into(),
193 style: None,
194 }),
195 }
196 }
197
198 pub fn buy(text: impl Into<String>) -> Self {
200 Self {
201 inner: tl::enums::KeyboardButton::Buy(tl::types::KeyboardButtonBuy {
202 text: text.into(),
203 style: None,
204 }),
205 }
206 }
207
208 pub fn copy_text(text: impl Into<String>, copy_text: impl Into<String>) -> Self {
210 Self {
211 inner: tl::enums::KeyboardButton::Copy(tl::types::KeyboardButtonCopy {
212 text: text.into(),
213 copy_text: copy_text.into(),
214 style: None,
215 }),
216 }
217 }
218
219 pub fn into_raw(self) -> tl::enums::KeyboardButton {
221 self.inner
222 }
223}
224
225#[derive(Clone, Default)]
242pub struct InlineKeyboard {
243 rows: Vec<Vec<Button>>,
244}
245
246impl InlineKeyboard {
247 pub fn new() -> Self {
249 Self::default()
250 }
251
252 pub fn row(mut self, buttons: impl IntoIterator<Item = Button>) -> Self {
254 self.rows.push(buttons.into_iter().collect());
255 self
256 }
257
258 pub fn into_markup(self) -> tl::enums::ReplyMarkup {
260 let rows = self
261 .rows
262 .into_iter()
263 .map(|row| {
264 tl::enums::KeyboardButtonRow::KeyboardButtonRow(tl::types::KeyboardButtonRow {
265 buttons: row.into_iter().map(Button::into_raw).collect(),
266 })
267 })
268 .collect();
269
270 tl::enums::ReplyMarkup::ReplyInlineMarkup(tl::types::ReplyInlineMarkup { rows })
271 }
272}
273
274impl From<InlineKeyboard> for tl::enums::ReplyMarkup {
275 fn from(kb: InlineKeyboard) -> Self {
276 kb.into_markup()
277 }
278}
279
280#[derive(Clone, Default)]
284pub struct ReplyKeyboard {
285 rows: Vec<Vec<Button>>,
286 resize: bool,
287 single_use: bool,
288 selective: bool,
289}
290
291impl ReplyKeyboard {
292 pub fn new() -> Self {
294 Self::default()
295 }
296
297 pub fn row(mut self, buttons: impl IntoIterator<Item = Button>) -> Self {
299 self.rows.push(buttons.into_iter().collect());
300 self
301 }
302
303 pub fn resize(mut self) -> Self {
305 self.resize = true;
306 self
307 }
308
309 pub fn single_use(mut self) -> Self {
311 self.single_use = true;
312 self
313 }
314
315 pub fn selective(mut self) -> Self {
317 self.selective = true;
318 self
319 }
320
321 pub fn into_markup(self) -> tl::enums::ReplyMarkup {
323 let rows = self
324 .rows
325 .into_iter()
326 .map(|row| {
327 tl::enums::KeyboardButtonRow::KeyboardButtonRow(tl::types::KeyboardButtonRow {
328 buttons: row.into_iter().map(Button::into_raw).collect(),
329 })
330 })
331 .collect();
332
333 tl::enums::ReplyMarkup::ReplyKeyboardMarkup(tl::types::ReplyKeyboardMarkup {
334 resize: self.resize,
335 single_use: self.single_use,
336 selective: self.selective,
337 persistent: false,
338 rows,
339 placeholder: None,
340 })
341 }
342}
343
344impl From<ReplyKeyboard> for tl::enums::ReplyMarkup {
345 fn from(kb: ReplyKeyboard) -> Self {
346 kb.into_markup()
347 }
348}