rtdlib 1.8.70

TDLib for rust
Documentation
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
use crate::errors::*;
use crate::types::*;
use uuid::Uuid;

use serde::de::{Deserialize, Deserializer};
use std::fmt::Debug;

/// TRAIT | Contains a description of a custom keyboard and actions that can be done with it to quickly reply to bots
pub trait TDReplyMarkup: Debug + RObject {}

/// Contains a description of a custom keyboard and actions that can be done with it to quickly reply to bots
#[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
pub enum ReplyMarkup {
  #[doc(hidden)]
  _Default(()),
  /// Instructs application to force a reply to this message
  ForceReply(ReplyMarkupForceReply),
  /// Contains an inline keyboard layout
  InlineKeyboard(ReplyMarkupInlineKeyboard),
  /// Instructs application to remove the keyboard once this message has been received. This kind of keyboard can't be received in an incoming message; instead, updateChatReplyMarkup with reply_markup_message == null will be sent
  RemoveKeyboard(ReplyMarkupRemoveKeyboard),
  /// Contains a custom keyboard layout to quickly reply to bots
  ShowKeyboard(ReplyMarkupShowKeyboard),
}

impl Default for ReplyMarkup {
  fn default() -> Self {
    ReplyMarkup::_Default(())
  }
}

impl<'de> Deserialize<'de> for ReplyMarkup {
  fn deserialize<D>(deserializer: D) -> Result<ReplyMarkup, D::Error>
  where
    D: Deserializer<'de>,
  {
    use serde::de::Error;
    rtd_enum_deserialize!(
      ReplyMarkup,
      (replyMarkupForceReply, ForceReply);
      (replyMarkupInlineKeyboard, InlineKeyboard);
      (replyMarkupRemoveKeyboard, RemoveKeyboard);
      (replyMarkupShowKeyboard, ShowKeyboard);

    )(deserializer)
  }
}

impl RObject for ReplyMarkup {
  #[doc(hidden)]
  fn td_name(&self) -> &'static str {
    match self {
      ReplyMarkup::ForceReply(t) => t.td_name(),
      ReplyMarkup::InlineKeyboard(t) => t.td_name(),
      ReplyMarkup::RemoveKeyboard(t) => t.td_name(),
      ReplyMarkup::ShowKeyboard(t) => t.td_name(),

      _ => "-1",
    }
  }
  #[doc(hidden)]
  fn extra(&self) -> Option<String> {
    match self {
      ReplyMarkup::ForceReply(t) => t.extra(),
      ReplyMarkup::InlineKeyboard(t) => t.extra(),
      ReplyMarkup::RemoveKeyboard(t) => t.extra(),
      ReplyMarkup::ShowKeyboard(t) => t.extra(),

      _ => None,
    }
  }
  fn to_json(&self) -> RTDResult<String> {
    Ok(serde_json::to_string(self)?)
  }
}

impl ReplyMarkup {
  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> {
    Ok(serde_json::from_str(json.as_ref())?)
  }
  #[doc(hidden)]
  pub fn _is_default(&self) -> bool {
    matches!(self, ReplyMarkup::_Default(_))
  }

  pub fn is_force_reply(&self) -> bool {
    matches!(self, ReplyMarkup::ForceReply(_))
  }
  pub fn is_inline_keyboard(&self) -> bool {
    matches!(self, ReplyMarkup::InlineKeyboard(_))
  }
  pub fn is_remove_keyboard(&self) -> bool {
    matches!(self, ReplyMarkup::RemoveKeyboard(_))
  }
  pub fn is_show_keyboard(&self) -> bool {
    matches!(self, ReplyMarkup::ShowKeyboard(_))
  }

  pub fn on_force_reply<F: FnOnce(&ReplyMarkupForceReply)>(&self, fnc: F) -> &Self {
    if let ReplyMarkup::ForceReply(t) = self {
      fnc(t)
    };
    self
  }
  pub fn on_inline_keyboard<F: FnOnce(&ReplyMarkupInlineKeyboard)>(&self, fnc: F) -> &Self {
    if let ReplyMarkup::InlineKeyboard(t) = self {
      fnc(t)
    };
    self
  }
  pub fn on_remove_keyboard<F: FnOnce(&ReplyMarkupRemoveKeyboard)>(&self, fnc: F) -> &Self {
    if let ReplyMarkup::RemoveKeyboard(t) = self {
      fnc(t)
    };
    self
  }
  pub fn on_show_keyboard<F: FnOnce(&ReplyMarkupShowKeyboard)>(&self, fnc: F) -> &Self {
    if let ReplyMarkup::ShowKeyboard(t) = self {
      fnc(t)
    };
    self
  }

  pub fn as_force_reply(&self) -> Option<&ReplyMarkupForceReply> {
    if let ReplyMarkup::ForceReply(t) = self {
      return Some(t);
    }
    None
  }
  pub fn as_inline_keyboard(&self) -> Option<&ReplyMarkupInlineKeyboard> {
    if let ReplyMarkup::InlineKeyboard(t) = self {
      return Some(t);
    }
    None
  }
  pub fn as_remove_keyboard(&self) -> Option<&ReplyMarkupRemoveKeyboard> {
    if let ReplyMarkup::RemoveKeyboard(t) = self {
      return Some(t);
    }
    None
  }
  pub fn as_show_keyboard(&self) -> Option<&ReplyMarkupShowKeyboard> {
    if let ReplyMarkup::ShowKeyboard(t) = self {
      return Some(t);
    }
    None
  }

  pub fn force_reply<T: AsRef<ReplyMarkupForceReply>>(t: T) -> Self {
    ReplyMarkup::ForceReply(t.as_ref().clone())
  }

  pub fn inline_keyboard<T: AsRef<ReplyMarkupInlineKeyboard>>(t: T) -> Self {
    ReplyMarkup::InlineKeyboard(t.as_ref().clone())
  }

  pub fn remove_keyboard<T: AsRef<ReplyMarkupRemoveKeyboard>>(t: T) -> Self {
    ReplyMarkup::RemoveKeyboard(t.as_ref().clone())
  }

  pub fn show_keyboard<T: AsRef<ReplyMarkupShowKeyboard>>(t: T) -> Self {
    ReplyMarkup::ShowKeyboard(t.as_ref().clone())
  }
}

impl AsRef<ReplyMarkup> for ReplyMarkup {
  fn as_ref(&self) -> &ReplyMarkup {
    self
  }
}

/// Instructs application to force a reply to this message
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ReplyMarkupForceReply {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  #[doc(hidden)]
  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
  extra: Option<String>,
  /// True, if a forced reply must automatically be shown to the current user. For outgoing messages, specify true to show the forced reply only for the mentioned users and for the target user of a reply
  is_personal: bool,
  /// If non-empty, the placeholder to be shown in the input field when the reply is active; 0-64 characters
  input_field_placeholder: String,
}

impl RObject for ReplyMarkupForceReply {
  #[doc(hidden)]
  fn td_name(&self) -> &'static str {
    "replyMarkupForceReply"
  }
  #[doc(hidden)]
  fn extra(&self) -> Option<String> {
    self.extra.clone()
  }
  fn to_json(&self) -> RTDResult<String> {
    Ok(serde_json::to_string(self)?)
  }
}

impl TDReplyMarkup for ReplyMarkupForceReply {}

impl ReplyMarkupForceReply {
  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> {
    Ok(serde_json::from_str(json.as_ref())?)
  }
  pub fn builder() -> RTDReplyMarkupForceReplyBuilder {
    let inner = ReplyMarkupForceReply {
      td_name: "replyMarkupForceReply".to_string(),
      extra: Some(Uuid::new_v4().to_string()),
      ..Default::default()
    };
    RTDReplyMarkupForceReplyBuilder { inner }
  }

  pub fn is_personal(&self) -> bool {
    self.is_personal
  }

  pub fn input_field_placeholder(&self) -> &String {
    &self.input_field_placeholder
  }
}

#[doc(hidden)]
pub struct RTDReplyMarkupForceReplyBuilder {
  inner: ReplyMarkupForceReply,
}

impl RTDReplyMarkupForceReplyBuilder {
  pub fn build(&self) -> ReplyMarkupForceReply {
    self.inner.clone()
  }

  pub fn is_personal(&mut self, is_personal: bool) -> &mut Self {
    self.inner.is_personal = is_personal;
    self
  }

  pub fn input_field_placeholder<T: AsRef<str>>(
    &mut self,
    input_field_placeholder: T,
  ) -> &mut Self {
    self.inner.input_field_placeholder = input_field_placeholder.as_ref().to_string();
    self
  }
}

impl AsRef<ReplyMarkupForceReply> for ReplyMarkupForceReply {
  fn as_ref(&self) -> &ReplyMarkupForceReply {
    self
  }
}

impl AsRef<ReplyMarkupForceReply> for RTDReplyMarkupForceReplyBuilder {
  fn as_ref(&self) -> &ReplyMarkupForceReply {
    &self.inner
  }
}

/// Contains an inline keyboard layout
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ReplyMarkupInlineKeyboard {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  #[doc(hidden)]
  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
  extra: Option<String>,
  /// A list of rows of inline keyboard buttons
  rows: Vec<Vec<InlineKeyboardButton>>,
  /// True, if a reply to the message must be forced when the message is received
  force_reply: bool,
}

impl RObject for ReplyMarkupInlineKeyboard {
  #[doc(hidden)]
  fn td_name(&self) -> &'static str {
    "replyMarkupInlineKeyboard"
  }
  #[doc(hidden)]
  fn extra(&self) -> Option<String> {
    self.extra.clone()
  }
  fn to_json(&self) -> RTDResult<String> {
    Ok(serde_json::to_string(self)?)
  }
}

impl TDReplyMarkup for ReplyMarkupInlineKeyboard {}

impl ReplyMarkupInlineKeyboard {
  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> {
    Ok(serde_json::from_str(json.as_ref())?)
  }
  pub fn builder() -> RTDReplyMarkupInlineKeyboardBuilder {
    let inner = ReplyMarkupInlineKeyboard {
      td_name: "replyMarkupInlineKeyboard".to_string(),
      extra: Some(Uuid::new_v4().to_string()),
      ..Default::default()
    };
    RTDReplyMarkupInlineKeyboardBuilder { inner }
  }

  pub fn rows(&self) -> &Vec<Vec<InlineKeyboardButton>> {
    &self.rows
  }

  pub fn force_reply(&self) -> bool {
    self.force_reply
  }
}

#[doc(hidden)]
pub struct RTDReplyMarkupInlineKeyboardBuilder {
  inner: ReplyMarkupInlineKeyboard,
}

impl RTDReplyMarkupInlineKeyboardBuilder {
  pub fn build(&self) -> ReplyMarkupInlineKeyboard {
    self.inner.clone()
  }

  pub fn rows(&mut self, rows: Vec<Vec<InlineKeyboardButton>>) -> &mut Self {
    self.inner.rows = rows;
    self
  }

  pub fn force_reply(&mut self, force_reply: bool) -> &mut Self {
    self.inner.force_reply = force_reply;
    self
  }
}

impl AsRef<ReplyMarkupInlineKeyboard> for ReplyMarkupInlineKeyboard {
  fn as_ref(&self) -> &ReplyMarkupInlineKeyboard {
    self
  }
}

impl AsRef<ReplyMarkupInlineKeyboard> for RTDReplyMarkupInlineKeyboardBuilder {
  fn as_ref(&self) -> &ReplyMarkupInlineKeyboard {
    &self.inner
  }
}

/// Instructs application to remove the keyboard once this message has been received. This kind of keyboard can't be received in an incoming message; instead, updateChatReplyMarkup with reply_markup_message == null will be sent
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ReplyMarkupRemoveKeyboard {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  #[doc(hidden)]
  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
  extra: Option<String>,
  /// True, if the keyboard is removed only for the mentioned users or the target user of a reply
  is_personal: bool,
}

impl RObject for ReplyMarkupRemoveKeyboard {
  #[doc(hidden)]
  fn td_name(&self) -> &'static str {
    "replyMarkupRemoveKeyboard"
  }
  #[doc(hidden)]
  fn extra(&self) -> Option<String> {
    self.extra.clone()
  }
  fn to_json(&self) -> RTDResult<String> {
    Ok(serde_json::to_string(self)?)
  }
}

impl TDReplyMarkup for ReplyMarkupRemoveKeyboard {}

impl ReplyMarkupRemoveKeyboard {
  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> {
    Ok(serde_json::from_str(json.as_ref())?)
  }
  pub fn builder() -> RTDReplyMarkupRemoveKeyboardBuilder {
    let inner = ReplyMarkupRemoveKeyboard {
      td_name: "replyMarkupRemoveKeyboard".to_string(),
      extra: Some(Uuid::new_v4().to_string()),
      ..Default::default()
    };
    RTDReplyMarkupRemoveKeyboardBuilder { inner }
  }

  pub fn is_personal(&self) -> bool {
    self.is_personal
  }
}

#[doc(hidden)]
pub struct RTDReplyMarkupRemoveKeyboardBuilder {
  inner: ReplyMarkupRemoveKeyboard,
}

impl RTDReplyMarkupRemoveKeyboardBuilder {
  pub fn build(&self) -> ReplyMarkupRemoveKeyboard {
    self.inner.clone()
  }

  pub fn is_personal(&mut self, is_personal: bool) -> &mut Self {
    self.inner.is_personal = is_personal;
    self
  }
}

impl AsRef<ReplyMarkupRemoveKeyboard> for ReplyMarkupRemoveKeyboard {
  fn as_ref(&self) -> &ReplyMarkupRemoveKeyboard {
    self
  }
}

impl AsRef<ReplyMarkupRemoveKeyboard> for RTDReplyMarkupRemoveKeyboardBuilder {
  fn as_ref(&self) -> &ReplyMarkupRemoveKeyboard {
    &self.inner
  }
}

/// Contains a custom keyboard layout to quickly reply to bots
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ReplyMarkupShowKeyboard {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  #[doc(hidden)]
  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
  extra: Option<String>,
  /// A list of rows of bot keyboard buttons
  rows: Vec<Vec<KeyboardButton>>,
  /// True, if the keyboard is expected to always be shown when the ordinary keyboard is hidden
  is_persistent: bool,
  /// True, if the application needs to resize the keyboard vertically
  resize_keyboard: bool,
  /// True, if the application needs to hide the keyboard after use
  one_time: bool,
  /// True, if the keyboard must automatically be shown to the current user. For outgoing messages, specify true to show the keyboard only for the mentioned users and for the target user of a reply
  is_personal: bool,
  /// True, if the keyboard must force reply to the message with the keyboard
  force_reply: bool,
  /// If non-empty, the placeholder to be shown in the input field when the keyboard is active; 0-64 characters
  input_field_placeholder: String,
}

impl RObject for ReplyMarkupShowKeyboard {
  #[doc(hidden)]
  fn td_name(&self) -> &'static str {
    "replyMarkupShowKeyboard"
  }
  #[doc(hidden)]
  fn extra(&self) -> Option<String> {
    self.extra.clone()
  }
  fn to_json(&self) -> RTDResult<String> {
    Ok(serde_json::to_string(self)?)
  }
}

impl TDReplyMarkup for ReplyMarkupShowKeyboard {}

impl ReplyMarkupShowKeyboard {
  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> {
    Ok(serde_json::from_str(json.as_ref())?)
  }
  pub fn builder() -> RTDReplyMarkupShowKeyboardBuilder {
    let inner = ReplyMarkupShowKeyboard {
      td_name: "replyMarkupShowKeyboard".to_string(),
      extra: Some(Uuid::new_v4().to_string()),
      ..Default::default()
    };
    RTDReplyMarkupShowKeyboardBuilder { inner }
  }

  pub fn rows(&self) -> &Vec<Vec<KeyboardButton>> {
    &self.rows
  }

  pub fn is_persistent(&self) -> bool {
    self.is_persistent
  }

  pub fn resize_keyboard(&self) -> bool {
    self.resize_keyboard
  }

  pub fn one_time(&self) -> bool {
    self.one_time
  }

  pub fn is_personal(&self) -> bool {
    self.is_personal
  }

  pub fn force_reply(&self) -> bool {
    self.force_reply
  }

  pub fn input_field_placeholder(&self) -> &String {
    &self.input_field_placeholder
  }
}

#[doc(hidden)]
pub struct RTDReplyMarkupShowKeyboardBuilder {
  inner: ReplyMarkupShowKeyboard,
}

impl RTDReplyMarkupShowKeyboardBuilder {
  pub fn build(&self) -> ReplyMarkupShowKeyboard {
    self.inner.clone()
  }

  pub fn rows(&mut self, rows: Vec<Vec<KeyboardButton>>) -> &mut Self {
    self.inner.rows = rows;
    self
  }

  pub fn is_persistent(&mut self, is_persistent: bool) -> &mut Self {
    self.inner.is_persistent = is_persistent;
    self
  }

  pub fn resize_keyboard(&mut self, resize_keyboard: bool) -> &mut Self {
    self.inner.resize_keyboard = resize_keyboard;
    self
  }

  pub fn one_time(&mut self, one_time: bool) -> &mut Self {
    self.inner.one_time = one_time;
    self
  }

  pub fn is_personal(&mut self, is_personal: bool) -> &mut Self {
    self.inner.is_personal = is_personal;
    self
  }

  pub fn force_reply(&mut self, force_reply: bool) -> &mut Self {
    self.inner.force_reply = force_reply;
    self
  }

  pub fn input_field_placeholder<T: AsRef<str>>(
    &mut self,
    input_field_placeholder: T,
  ) -> &mut Self {
    self.inner.input_field_placeholder = input_field_placeholder.as_ref().to_string();
    self
  }
}

impl AsRef<ReplyMarkupShowKeyboard> for ReplyMarkupShowKeyboard {
  fn as_ref(&self) -> &ReplyMarkupShowKeyboard {
    self
  }
}

impl AsRef<ReplyMarkupShowKeyboard> for RTDReplyMarkupShowKeyboardBuilder {
  fn as_ref(&self) -> &ReplyMarkupShowKeyboard {
    &self.inner
  }
}