rtdlib 1.8.69

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
use crate::errors::*;
use crate::types::*;
use uuid::Uuid;

/// Describes an upgraded gift that can be transferred to another owner or transferred to the TON blockchain as an NFT
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct UpgradedGift {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  #[doc(hidden)]
  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
  extra: Option<String>,
  /// Unique identifier of the gift
  #[serde(deserialize_with = "serde_aux::field_attributes::deserialize_number_from_string")]
  id: isize,
  /// Unique identifier of the regular gift from which the gift was upgraded; may be 0 for short period of time for old gifts from database
  #[serde(deserialize_with = "serde_aux::field_attributes::deserialize_number_from_string")]
  regular_gift_id: isize,
  /// Identifier of the chat that published the gift; 0 if none
  publisher_chat_id: i64,
  /// The title of the upgraded gift
  title: String,
  /// Unique name of the upgraded gift that can be used with internalLinkTypeUpgradedGift or sendResoldGift
  name: String,
  /// Unique number of the upgraded gift among gifts upgraded from the same gift
  number: i64,
  /// Total number of gifts that were upgraded from the same gift
  total_upgraded_count: i64,
  /// The maximum number of gifts that can be upgraded from the same gift
  max_upgraded_count: i64,
  /// True, if the gift was used to craft another gift
  is_burned: bool,
  /// True, if the gift was crafted from other gifts
  is_crafted: bool,
  /// True, if the original gift could have been bought only by Telegram Premium subscribers
  is_premium: bool,
  /// True, if the gift can be used to set a theme in a chat
  is_theme_available: bool,
  /// Identifier of the chat for which the gift is used to set a theme; 0 if none or the gift isn't owned by the current user
  used_theme_chat_id: i64,
  /// Identifier of the user or the chat to which the upgraded gift was assigned from blockchain; may be null if none or unknown
  host_id: Option<MessageSender>,
  /// Identifier of the user or the chat that owns the upgraded gift; may be null if none or unknown
  owner_id: Option<MessageSender>,
  /// Address of the gift NFT owner in TON blockchain; may be empty if none. Append the address to getOption("ton_blockchain_explorer_url") to get a link with information about the address
  owner_address: String,
  /// Name of the owner for the case when owner identifier and address aren't known
  owner_name: String,
  /// Address of the gift NFT in TON blockchain; may be empty if none. Append the address to getOption("ton_blockchain_explorer_url") to get a link with information about the address
  gift_address: String,
  /// True, if the gift NFT can be used as background_nft_address in setTonWalletCardStickers
  can_be_ton_wallet_card_background: bool,
  /// Model of the upgraded gift
  model: UpgradedGiftModel,
  /// Symbol of the upgraded gift
  symbol: UpgradedGiftSymbol,
  /// Backdrop of the upgraded gift
  backdrop: UpgradedGiftBackdrop,
  /// Information about the originally sent gift; may be null if unknown
  original_details: Option<UpgradedGiftOriginalDetails>,
  /// Colors that can be set for user's name, background of empty chat photo, replies to messages and link previews; may be null if none or unknown
  colors: Option<UpgradedGiftColors>,
  /// Resale parameters of the gift; may be null if resale isn't possible
  resale_parameters: Option<GiftResaleParameters>,
  /// True, if an offer to purchase the gift can be sent using sendGiftPurchaseOffer
  can_send_purchase_offer: bool,
  /// Probability that the gift adds to the chance of successful crafting of a new gift; 0 if the gift can't be used for crafting
  craft_probability_per_mille: i64,
  /// ISO 4217 currency code of the currency in which value of the gift is represented; may be empty if unavailable
  value_currency: String,
  /// Estimated value of the gift; in the smallest units of the currency; 0 if unavailable
  value_amount: i64,
  /// Estimated value of the gift in USD; in USD cents; 0 if unavailable
  value_usd_amount: i64,
}

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

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

  pub fn id(&self) -> isize {
    self.id
  }

  pub fn regular_gift_id(&self) -> isize {
    self.regular_gift_id
  }

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

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

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

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

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

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

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

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

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

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

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

  pub fn host_id(&self) -> &Option<MessageSender> {
    &self.host_id
  }

  pub fn owner_id(&self) -> &Option<MessageSender> {
    &self.owner_id
  }

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

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

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

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

  pub fn model(&self) -> &UpgradedGiftModel {
    &self.model
  }

  pub fn symbol(&self) -> &UpgradedGiftSymbol {
    &self.symbol
  }

  pub fn backdrop(&self) -> &UpgradedGiftBackdrop {
    &self.backdrop
  }

  pub fn original_details(&self) -> &Option<UpgradedGiftOriginalDetails> {
    &self.original_details
  }

  pub fn colors(&self) -> &Option<UpgradedGiftColors> {
    &self.colors
  }

  pub fn resale_parameters(&self) -> &Option<GiftResaleParameters> {
    &self.resale_parameters
  }

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

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

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

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

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

#[doc(hidden)]
pub struct RTDUpgradedGiftBuilder {
  inner: UpgradedGift,
}

impl RTDUpgradedGiftBuilder {
  pub fn build(&self) -> UpgradedGift {
    self.inner.clone()
  }

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

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

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

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

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

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

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

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

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

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

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

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

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

  pub fn host_id<T: AsRef<MessageSender>>(&mut self, host_id: T) -> &mut Self {
    self.inner.host_id = Some(host_id.as_ref().clone());
    self
  }

  pub fn owner_id<T: AsRef<MessageSender>>(&mut self, owner_id: T) -> &mut Self {
    self.inner.owner_id = Some(owner_id.as_ref().clone());
    self
  }

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

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

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

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

  pub fn model<T: AsRef<UpgradedGiftModel>>(&mut self, model: T) -> &mut Self {
    self.inner.model = model.as_ref().clone();
    self
  }

  pub fn symbol<T: AsRef<UpgradedGiftSymbol>>(&mut self, symbol: T) -> &mut Self {
    self.inner.symbol = symbol.as_ref().clone();
    self
  }

  pub fn backdrop<T: AsRef<UpgradedGiftBackdrop>>(&mut self, backdrop: T) -> &mut Self {
    self.inner.backdrop = backdrop.as_ref().clone();
    self
  }

  pub fn original_details<T: AsRef<UpgradedGiftOriginalDetails>>(
    &mut self,
    original_details: T,
  ) -> &mut Self {
    self.inner.original_details = Some(original_details.as_ref().clone());
    self
  }

  pub fn colors<T: AsRef<UpgradedGiftColors>>(&mut self, colors: T) -> &mut Self {
    self.inner.colors = Some(colors.as_ref().clone());
    self
  }

  pub fn resale_parameters<T: AsRef<GiftResaleParameters>>(
    &mut self,
    resale_parameters: T,
  ) -> &mut Self {
    self.inner.resale_parameters = Some(resale_parameters.as_ref().clone());
    self
  }

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

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

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

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

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

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

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