rust_tdlib/types/
reply_markup.rs1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5use std::fmt::Debug;
6
7pub trait TDReplyMarkup: Debug + RObject {}
9
10#[derive(Debug, Clone, Deserialize, Serialize, Default)]
12#[serde(tag = "@type")]
13pub enum ReplyMarkup {
14 #[doc(hidden)]
15 #[default]
16 _Default,
17 #[serde(rename = "replyMarkupForceReply")]
19 ForceReply(ReplyMarkupForceReply),
20 #[serde(rename = "replyMarkupInlineKeyboard")]
22 InlineKeyboard(ReplyMarkupInlineKeyboard),
23 #[serde(rename = "replyMarkupRemoveKeyboard")]
25 RemoveKeyboard(ReplyMarkupRemoveKeyboard),
26 #[serde(rename = "replyMarkupShowKeyboard")]
28 ShowKeyboard(ReplyMarkupShowKeyboard),
29}
30
31impl RObject for ReplyMarkup {
32 #[doc(hidden)]
33 fn extra(&self) -> Option<&str> {
34 match self {
35 ReplyMarkup::ForceReply(t) => t.extra(),
36 ReplyMarkup::InlineKeyboard(t) => t.extra(),
37 ReplyMarkup::RemoveKeyboard(t) => t.extra(),
38 ReplyMarkup::ShowKeyboard(t) => t.extra(),
39
40 _ => None,
41 }
42 }
43 #[doc(hidden)]
44 fn client_id(&self) -> Option<i32> {
45 match self {
46 ReplyMarkup::ForceReply(t) => t.client_id(),
47 ReplyMarkup::InlineKeyboard(t) => t.client_id(),
48 ReplyMarkup::RemoveKeyboard(t) => t.client_id(),
49 ReplyMarkup::ShowKeyboard(t) => t.client_id(),
50
51 _ => None,
52 }
53 }
54}
55
56impl ReplyMarkup {
57 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
58 Ok(serde_json::from_str(json.as_ref())?)
59 }
60 #[doc(hidden)]
61 pub fn _is_default(&self) -> bool {
62 matches!(self, ReplyMarkup::_Default)
63 }
64}
65
66impl AsRef<ReplyMarkup> for ReplyMarkup {
67 fn as_ref(&self) -> &ReplyMarkup {
68 self
69 }
70}
71
72#[derive(Debug, Clone, Default, Serialize, Deserialize)]
74pub struct ReplyMarkupForceReply {
75 #[doc(hidden)]
76 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
77 extra: Option<String>,
78 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
79 client_id: Option<i32>,
80 #[serde(default)]
83 is_personal: bool,
84 #[serde(default)]
87 input_field_placeholder: String,
88}
89
90impl RObject for ReplyMarkupForceReply {
91 #[doc(hidden)]
92 fn extra(&self) -> Option<&str> {
93 self.extra.as_deref()
94 }
95 #[doc(hidden)]
96 fn client_id(&self) -> Option<i32> {
97 self.client_id
98 }
99}
100
101impl TDReplyMarkup for ReplyMarkupForceReply {}
102
103impl ReplyMarkupForceReply {
104 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
105 Ok(serde_json::from_str(json.as_ref())?)
106 }
107 pub fn builder() -> ReplyMarkupForceReplyBuilder {
108 let mut inner = ReplyMarkupForceReply::default();
109 inner.extra = Some(Uuid::new_v4().to_string());
110
111 ReplyMarkupForceReplyBuilder { inner }
112 }
113
114 pub fn is_personal(&self) -> bool {
115 self.is_personal
116 }
117
118 pub fn input_field_placeholder(&self) -> &String {
119 &self.input_field_placeholder
120 }
121}
122
123#[doc(hidden)]
124pub struct ReplyMarkupForceReplyBuilder {
125 inner: ReplyMarkupForceReply,
126}
127
128#[deprecated]
129pub type RTDReplyMarkupForceReplyBuilder = ReplyMarkupForceReplyBuilder;
130
131impl ReplyMarkupForceReplyBuilder {
132 pub fn build(&self) -> ReplyMarkupForceReply {
133 self.inner.clone()
134 }
135
136 pub fn is_personal(&mut self, is_personal: bool) -> &mut Self {
137 self.inner.is_personal = is_personal;
138 self
139 }
140
141 pub fn input_field_placeholder<T: AsRef<str>>(
142 &mut self,
143 input_field_placeholder: T,
144 ) -> &mut Self {
145 self.inner.input_field_placeholder = input_field_placeholder.as_ref().to_string();
146 self
147 }
148}
149
150impl AsRef<ReplyMarkupForceReply> for ReplyMarkupForceReply {
151 fn as_ref(&self) -> &ReplyMarkupForceReply {
152 self
153 }
154}
155
156impl AsRef<ReplyMarkupForceReply> for ReplyMarkupForceReplyBuilder {
157 fn as_ref(&self) -> &ReplyMarkupForceReply {
158 &self.inner
159 }
160}
161
162#[derive(Debug, Clone, Default, Serialize, Deserialize)]
164pub struct ReplyMarkupInlineKeyboard {
165 #[doc(hidden)]
166 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
167 extra: Option<String>,
168 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
169 client_id: Option<i32>,
170 #[serde(default)]
173 rows: Vec<Vec<InlineKeyboardButton>>,
174}
175
176impl RObject for ReplyMarkupInlineKeyboard {
177 #[doc(hidden)]
178 fn extra(&self) -> Option<&str> {
179 self.extra.as_deref()
180 }
181 #[doc(hidden)]
182 fn client_id(&self) -> Option<i32> {
183 self.client_id
184 }
185}
186
187impl TDReplyMarkup for ReplyMarkupInlineKeyboard {}
188
189impl ReplyMarkupInlineKeyboard {
190 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
191 Ok(serde_json::from_str(json.as_ref())?)
192 }
193 pub fn builder() -> ReplyMarkupInlineKeyboardBuilder {
194 let mut inner = ReplyMarkupInlineKeyboard::default();
195 inner.extra = Some(Uuid::new_v4().to_string());
196
197 ReplyMarkupInlineKeyboardBuilder { inner }
198 }
199
200 pub fn rows(&self) -> &Vec<Vec<InlineKeyboardButton>> {
201 &self.rows
202 }
203}
204
205#[doc(hidden)]
206pub struct ReplyMarkupInlineKeyboardBuilder {
207 inner: ReplyMarkupInlineKeyboard,
208}
209
210#[deprecated]
211pub type RTDReplyMarkupInlineKeyboardBuilder = ReplyMarkupInlineKeyboardBuilder;
212
213impl ReplyMarkupInlineKeyboardBuilder {
214 pub fn build(&self) -> ReplyMarkupInlineKeyboard {
215 self.inner.clone()
216 }
217
218 pub fn rows(&mut self, rows: Vec<Vec<InlineKeyboardButton>>) -> &mut Self {
219 self.inner.rows = rows;
220 self
221 }
222}
223
224impl AsRef<ReplyMarkupInlineKeyboard> for ReplyMarkupInlineKeyboard {
225 fn as_ref(&self) -> &ReplyMarkupInlineKeyboard {
226 self
227 }
228}
229
230impl AsRef<ReplyMarkupInlineKeyboard> for ReplyMarkupInlineKeyboardBuilder {
231 fn as_ref(&self) -> &ReplyMarkupInlineKeyboard {
232 &self.inner
233 }
234}
235
236#[derive(Debug, Clone, Default, Serialize, Deserialize)]
238pub struct ReplyMarkupRemoveKeyboard {
239 #[doc(hidden)]
240 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
241 extra: Option<String>,
242 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
243 client_id: Option<i32>,
244 #[serde(default)]
247 is_personal: bool,
248}
249
250impl RObject for ReplyMarkupRemoveKeyboard {
251 #[doc(hidden)]
252 fn extra(&self) -> Option<&str> {
253 self.extra.as_deref()
254 }
255 #[doc(hidden)]
256 fn client_id(&self) -> Option<i32> {
257 self.client_id
258 }
259}
260
261impl TDReplyMarkup for ReplyMarkupRemoveKeyboard {}
262
263impl ReplyMarkupRemoveKeyboard {
264 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
265 Ok(serde_json::from_str(json.as_ref())?)
266 }
267 pub fn builder() -> ReplyMarkupRemoveKeyboardBuilder {
268 let mut inner = ReplyMarkupRemoveKeyboard::default();
269 inner.extra = Some(Uuid::new_v4().to_string());
270
271 ReplyMarkupRemoveKeyboardBuilder { inner }
272 }
273
274 pub fn is_personal(&self) -> bool {
275 self.is_personal
276 }
277}
278
279#[doc(hidden)]
280pub struct ReplyMarkupRemoveKeyboardBuilder {
281 inner: ReplyMarkupRemoveKeyboard,
282}
283
284#[deprecated]
285pub type RTDReplyMarkupRemoveKeyboardBuilder = ReplyMarkupRemoveKeyboardBuilder;
286
287impl ReplyMarkupRemoveKeyboardBuilder {
288 pub fn build(&self) -> ReplyMarkupRemoveKeyboard {
289 self.inner.clone()
290 }
291
292 pub fn is_personal(&mut self, is_personal: bool) -> &mut Self {
293 self.inner.is_personal = is_personal;
294 self
295 }
296}
297
298impl AsRef<ReplyMarkupRemoveKeyboard> for ReplyMarkupRemoveKeyboard {
299 fn as_ref(&self) -> &ReplyMarkupRemoveKeyboard {
300 self
301 }
302}
303
304impl AsRef<ReplyMarkupRemoveKeyboard> for ReplyMarkupRemoveKeyboardBuilder {
305 fn as_ref(&self) -> &ReplyMarkupRemoveKeyboard {
306 &self.inner
307 }
308}
309
310#[derive(Debug, Clone, Default, Serialize, Deserialize)]
312pub struct ReplyMarkupShowKeyboard {
313 #[doc(hidden)]
314 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
315 extra: Option<String>,
316 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
317 client_id: Option<i32>,
318 #[serde(default)]
321 rows: Vec<Vec<KeyboardButton>>,
322 #[serde(default)]
325 resize_keyboard: bool,
326 #[serde(default)]
329 one_time: bool,
330 #[serde(default)]
333 is_personal: bool,
334 #[serde(default)]
337 input_field_placeholder: String,
338}
339
340impl RObject for ReplyMarkupShowKeyboard {
341 #[doc(hidden)]
342 fn extra(&self) -> Option<&str> {
343 self.extra.as_deref()
344 }
345 #[doc(hidden)]
346 fn client_id(&self) -> Option<i32> {
347 self.client_id
348 }
349}
350
351impl TDReplyMarkup for ReplyMarkupShowKeyboard {}
352
353impl ReplyMarkupShowKeyboard {
354 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
355 Ok(serde_json::from_str(json.as_ref())?)
356 }
357 pub fn builder() -> ReplyMarkupShowKeyboardBuilder {
358 let mut inner = ReplyMarkupShowKeyboard::default();
359 inner.extra = Some(Uuid::new_v4().to_string());
360
361 ReplyMarkupShowKeyboardBuilder { inner }
362 }
363
364 pub fn rows(&self) -> &Vec<Vec<KeyboardButton>> {
365 &self.rows
366 }
367
368 pub fn resize_keyboard(&self) -> bool {
369 self.resize_keyboard
370 }
371
372 pub fn one_time(&self) -> bool {
373 self.one_time
374 }
375
376 pub fn is_personal(&self) -> bool {
377 self.is_personal
378 }
379
380 pub fn input_field_placeholder(&self) -> &String {
381 &self.input_field_placeholder
382 }
383}
384
385#[doc(hidden)]
386pub struct ReplyMarkupShowKeyboardBuilder {
387 inner: ReplyMarkupShowKeyboard,
388}
389
390#[deprecated]
391pub type RTDReplyMarkupShowKeyboardBuilder = ReplyMarkupShowKeyboardBuilder;
392
393impl ReplyMarkupShowKeyboardBuilder {
394 pub fn build(&self) -> ReplyMarkupShowKeyboard {
395 self.inner.clone()
396 }
397
398 pub fn rows(&mut self, rows: Vec<Vec<KeyboardButton>>) -> &mut Self {
399 self.inner.rows = rows;
400 self
401 }
402
403 pub fn resize_keyboard(&mut self, resize_keyboard: bool) -> &mut Self {
404 self.inner.resize_keyboard = resize_keyboard;
405 self
406 }
407
408 pub fn one_time(&mut self, one_time: bool) -> &mut Self {
409 self.inner.one_time = one_time;
410 self
411 }
412
413 pub fn is_personal(&mut self, is_personal: bool) -> &mut Self {
414 self.inner.is_personal = is_personal;
415 self
416 }
417
418 pub fn input_field_placeholder<T: AsRef<str>>(
419 &mut self,
420 input_field_placeholder: T,
421 ) -> &mut Self {
422 self.inner.input_field_placeholder = input_field_placeholder.as_ref().to_string();
423 self
424 }
425}
426
427impl AsRef<ReplyMarkupShowKeyboard> for ReplyMarkupShowKeyboard {
428 fn as_ref(&self) -> &ReplyMarkupShowKeyboard {
429 self
430 }
431}
432
433impl AsRef<ReplyMarkupShowKeyboard> for ReplyMarkupShowKeyboardBuilder {
434 fn as_ref(&self) -> &ReplyMarkupShowKeyboard {
435 &self.inner
436 }
437}