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
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
use crate::errors::*;
use crate::types::*;
use uuid::Uuid;

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

/// TRAIT | Represents the type of user. The following types are possible: regular users, deleted users and bots
pub trait TDUserType: Debug + RObject {}

/// Represents the type of user. The following types are possible: regular users, deleted users and bots
#[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
pub enum UserType {
  #[doc(hidden)]
  _Default(()),
  /// A bot (see https://core.telegram.org/bots)
  Bot(UserTypeBot),
  /// A deleted user or deleted bot. No information on the user besides the user identifier is available. It is not possible to perform any active actions on this type of user
  Deleted(UserTypeDeleted),
  /// A regular user
  Regular(UserTypeRegular),
  /// No information on the user besides the user identifier is available, yet this user has not been deleted. This object is extremely rare and must be handled like a deleted user. It is not possible to perform any actions on users of this type
  Unknown(UserTypeUnknown),
}

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

impl<'de> Deserialize<'de> for UserType {
  fn deserialize<D>(deserializer: D) -> Result<UserType, D::Error>
  where
    D: Deserializer<'de>,
  {
    use serde::de::Error;
    rtd_enum_deserialize!(
      UserType,
      (userTypeBot, Bot);
      (userTypeDeleted, Deleted);
      (userTypeRegular, Regular);
      (userTypeUnknown, Unknown);

    )(deserializer)
  }
}

impl RObject for UserType {
  #[doc(hidden)]
  fn td_name(&self) -> &'static str {
    match self {
      UserType::Bot(t) => t.td_name(),
      UserType::Deleted(t) => t.td_name(),
      UserType::Regular(t) => t.td_name(),
      UserType::Unknown(t) => t.td_name(),

      _ => "-1",
    }
  }
  #[doc(hidden)]
  fn extra(&self) -> Option<String> {
    match self {
      UserType::Bot(t) => t.extra(),
      UserType::Deleted(t) => t.extra(),
      UserType::Regular(t) => t.extra(),
      UserType::Unknown(t) => t.extra(),

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

impl UserType {
  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, UserType::_Default(_))
  }

  pub fn is_bot(&self) -> bool {
    matches!(self, UserType::Bot(_))
  }
  pub fn is_deleted(&self) -> bool {
    matches!(self, UserType::Deleted(_))
  }
  pub fn is_regular(&self) -> bool {
    matches!(self, UserType::Regular(_))
  }
  pub fn is_unknown(&self) -> bool {
    matches!(self, UserType::Unknown(_))
  }

  pub fn on_bot<F: FnOnce(&UserTypeBot)>(&self, fnc: F) -> &Self {
    if let UserType::Bot(t) = self {
      fnc(t)
    };
    self
  }
  pub fn on_deleted<F: FnOnce(&UserTypeDeleted)>(&self, fnc: F) -> &Self {
    if let UserType::Deleted(t) = self {
      fnc(t)
    };
    self
  }
  pub fn on_regular<F: FnOnce(&UserTypeRegular)>(&self, fnc: F) -> &Self {
    if let UserType::Regular(t) = self {
      fnc(t)
    };
    self
  }
  pub fn on_unknown<F: FnOnce(&UserTypeUnknown)>(&self, fnc: F) -> &Self {
    if let UserType::Unknown(t) = self {
      fnc(t)
    };
    self
  }

  pub fn as_bot(&self) -> Option<&UserTypeBot> {
    if let UserType::Bot(t) = self {
      return Some(t);
    }
    None
  }
  pub fn as_deleted(&self) -> Option<&UserTypeDeleted> {
    if let UserType::Deleted(t) = self {
      return Some(t);
    }
    None
  }
  pub fn as_regular(&self) -> Option<&UserTypeRegular> {
    if let UserType::Regular(t) = self {
      return Some(t);
    }
    None
  }
  pub fn as_unknown(&self) -> Option<&UserTypeUnknown> {
    if let UserType::Unknown(t) = self {
      return Some(t);
    }
    None
  }

  pub fn bot<T: AsRef<UserTypeBot>>(t: T) -> Self {
    UserType::Bot(t.as_ref().clone())
  }

  pub fn deleted<T: AsRef<UserTypeDeleted>>(t: T) -> Self {
    UserType::Deleted(t.as_ref().clone())
  }

  pub fn regular<T: AsRef<UserTypeRegular>>(t: T) -> Self {
    UserType::Regular(t.as_ref().clone())
  }

  pub fn unknown<T: AsRef<UserTypeUnknown>>(t: T) -> Self {
    UserType::Unknown(t.as_ref().clone())
  }
}

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

/// A bot (see https://core.telegram.org/bots)
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct UserTypeBot {
  #[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 bot is owned by the current user and can be edited using the methods toggleBotUsernameIsActive, reorderBotActiveUsernames, setBotProfilePhoto, setBotName, setBotInfoDescription, and setBotInfoShortDescription
  can_be_edited: bool,
  /// True, if the bot can be invited to basic group and supergroup chats
  can_join_groups: bool,
  /// True, if the bot can read all messages in basic group or supergroup chats and not just those addressed to the bot. In private and channel chats a bot can always read all messages
  can_read_all_group_messages: bool,
  /// True, if the bot has the main Web App
  has_main_web_app: bool,
  /// True, if the bot has topics
  has_topics: bool,
  /// True, if users can create and delete topics in the chat with the bot
  allows_users_to_create_topics: bool,
  /// True, if the bot can manage other bots
  can_manage_bots: bool,
  /// True, if the bot supports inline queries
  is_inline: bool,
  /// Placeholder for inline queries (displayed on the application input field)
  inline_query_placeholder: String,
  /// True, if the bot can be queried by username from any non-secret chat
  supports_guest_queries: bool,
  /// True, if the bot can be set as a guard bot in supergroup chats
  is_guard: bool,
  /// True, if the location of the user is expected to be sent with every inline query to this bot
  need_location: bool,
  /// True, if the bot supports connection to user accounts for chat automation
  can_connect_to_business: bool,
  /// True, if the bot can be added to attachment or side menu
  can_be_added_to_attachment_menu: bool,
  /// The number of recently active users of the bot
  active_user_count: i64,
}

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

impl TDUserType for UserTypeBot {}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  pub fn active_user_count(&self) -> i64 {
    self.active_user_count
  }
}

#[doc(hidden)]
pub struct RTDUserTypeBotBuilder {
  inner: UserTypeBot,
}

impl RTDUserTypeBotBuilder {
  pub fn build(&self) -> UserTypeBot {
    self.inner.clone()
  }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/// A deleted user or deleted bot. No information on the user besides the user identifier is available. It is not possible to perform any active actions on this type of user
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct UserTypeDeleted {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  #[doc(hidden)]
  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
  extra: Option<String>,
}

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

impl TDUserType for UserTypeDeleted {}

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

#[doc(hidden)]
pub struct RTDUserTypeDeletedBuilder {
  inner: UserTypeDeleted,
}

impl RTDUserTypeDeletedBuilder {
  pub fn build(&self) -> UserTypeDeleted {
    self.inner.clone()
  }
}

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

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

/// A regular user
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct UserTypeRegular {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  #[doc(hidden)]
  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
  extra: Option<String>,
}

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

impl TDUserType for UserTypeRegular {}

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

#[doc(hidden)]
pub struct RTDUserTypeRegularBuilder {
  inner: UserTypeRegular,
}

impl RTDUserTypeRegularBuilder {
  pub fn build(&self) -> UserTypeRegular {
    self.inner.clone()
  }
}

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

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

/// No information on the user besides the user identifier is available, yet this user has not been deleted. This object is extremely rare and must be handled like a deleted user. It is not possible to perform any actions on users of this type
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct UserTypeUnknown {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  #[doc(hidden)]
  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
  extra: Option<String>,
}

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

impl TDUserType for UserTypeUnknown {}

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

#[doc(hidden)]
pub struct RTDUserTypeUnknownBuilder {
  inner: UserTypeUnknown,
}

impl RTDUserTypeUnknownBuilder {
  pub fn build(&self) -> UserTypeUnknown {
    self.inner.clone()
  }
}

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

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