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
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
use serde::{Deserialize, Serialize};
use crate::{
api::{Method, Payload, PayloadError},
types::{Chat, ChatId, InputText, Integer, ParseMode, Sticker, TextEntities, User},
};
/// Describes the types of gifts that can be gifted to a user or a chat.
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct AcceptedGiftTypes {
/// Whether transfers of unique gifts from channels are accepted.
pub gifts_from_channels: bool,
/// Whether limited regular gifts are accepted.
pub limited_gifts: bool,
/// Whether a Telegram Premium subscription is accepted.
pub premium_subscription: bool,
/// Whether unique gifts or gifts that can be upgraded to unique for free are accepted.
pub unique_gifts: bool,
/// Whether unlimited regular gifts are accepted.
pub unlimited_gifts: bool,
}
/// Represents a gift that can be sent by the bot.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Gift {
/// Unique identifier of the gift.
pub id: String,
/// The number of Telegram Stars that must be paid to send the sticker.
pub star_count: Integer,
/// The sticker that represents the gift.
pub sticker: Sticker,
/// Background of the gift.
pub background: Option<GiftBackground>,
/// Whether the gift can be used (after being upgraded) to customize a user's appearance.
pub has_colors: Option<bool>,
/// Whether the gift can only be purchased by Telegram Premium subscribers.
pub is_premium: Option<bool>,
/// The number of remaining gifts of this type that can be sent by the bot; for limited gifts only.
pub personal_remaining_count: Option<Integer>,
/// The total number of gifts of this type that can be sent by the bot; for limited gifts only.
pub personal_total_count: Option<Integer>,
/// Information about the chat that published the gift.
pub publisher_chat: Option<Chat>,
/// The number of remaining gifts of this type that can be sent;
/// for limited gifts only.
pub remaining_count: Option<Integer>,
/// The total number of the gifts of this type that can be sent;
/// for limited gifts only.
pub total_count: Option<Integer>,
/// The total number of different unique gifts that can be obtained by upgrading the gift.
pub unique_gift_variant_count: Option<Integer>,
/// The number of Telegram Stars that must be paid to upgrade the gift to a unique one.
pub upgrade_star_count: Option<Integer>,
}
/// Describes the background of a gift.
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct GiftBackground {
/// Center color of the background in RGB format
pub center_color: Integer,
/// Edge color of the background in RGB format
pub edge_color: Integer,
/// Text color of the background in RGB format
pub text_color: Integer,
}
/// Describes a service message about a regular gift that was sent or received.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct GiftInfo {
/// Information about the gift.
pub gift: Gift,
/// Whether the gift can be upgraded to a unique gift.
pub can_be_upgraded: Option<bool>,
/// Number of Telegram Stars that can be claimed by the receiver by converting the gift;
/// omitted if conversion to Telegram Stars is impossible.
pub convert_star_count: Option<Integer>,
/// Special entities that appear in the text.
pub entities: Option<TextEntities>,
/// Whether the sender and gift text are shown only to the gift receiver;
/// otherwise, everyone will be able to see them.
pub is_private: Option<bool>,
/// Whether the gift's upgrade was purchased after the gift was sent.
pub is_upgrade_separate: Option<bool>,
/// Unique identifier of the received gift for the bot;
/// only present for gifts received on behalf of business accounts.
pub owned_gift_id: Option<String>,
/// Number of Telegram Stars that were prepaid by the sender for the ability to upgrade the gift.
pub prepaid_upgrade_star_count: Option<Integer>,
/// Text of the message that was added to the gift.
pub text: Option<String>,
/// Unique number reserved for this gift when upgraded.
///
/// See the number field in [`crate::types::UniqueGift`].
pub unique_gift_number: Option<Integer>,
}
/// Represent a list of gifts.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Gifts {
gifts: Vec<Gift>,
}
impl From<Gifts> for Vec<Gift> {
fn from(value: Gifts) -> Self {
value.gifts
}
}
/// Returns the list of gifts that can be sent by the bot to users.
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
pub struct GetAvailableGifts;
impl Method for GetAvailableGifts {
type Response = Gifts;
fn into_payload(self) -> Result<Payload, PayloadError> {
Payload::empty("getAvailableGifts")
}
}
/// Returns the gifts received and owned by a managed business account.
///
/// Requires the `can_view_gifts_and_stars` business bot right.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Serialize)]
pub struct GetBusinessAccountGifts {
business_connection_id: String,
exclude_from_blockchain: Option<bool>,
exclude_limited_non_upgradable: Option<bool>,
exclude_limited_upgradable: Option<bool>,
exclude_saved: Option<bool>,
exclude_unique: Option<bool>,
exclude_unlimited: Option<bool>,
exclude_unsaved: Option<bool>,
limit: Option<Integer>,
offset: Option<String>,
sort_by_price: Option<bool>,
}
impl GetBusinessAccountGifts {
/// Creates a new `GetBusinessAccountGifts`.
///
/// # Arguments
///
/// * `business_connection_id` - Unique identifier of the business connection.
pub fn new<T>(business_connection_id: T) -> Self
where
T: Into<String>,
{
Self {
business_connection_id: business_connection_id.into(),
exclude_from_blockchain: None,
exclude_limited_non_upgradable: None,
exclude_limited_upgradable: None,
exclude_saved: None,
exclude_unique: None,
exclude_unlimited: None,
exclude_unsaved: None,
limit: None,
offset: None,
sort_by_price: None,
}
}
/// Sets a new value for the `exclude_from_blockchain` flag.
///
/// # Arguments
///
/// * `value` - Whether to exclude gifts that were assigned from the TON blockchain
/// and can't be resold or transferred in Telegram.
pub fn with_exclude_from_blockchain(mut self, value: bool) -> Self {
self.exclude_from_blockchain = Some(value);
self
}
/// Sets a new value for the `exclude_limited_non_upgradable` flag.
///
/// # Arguments
///
/// * `value` - Whether to exclude gifts that can be purchased
/// a limited number of times and can't be upgraded to unique.
pub fn with_exclude_limited_non_upgradable(mut self, value: bool) -> Self {
self.exclude_limited_non_upgradable = Some(value);
self
}
/// Sets a new value for the `exclude_limited_upgradable` flag.
///
/// # Arguments
///
/// * `value` - Whether to exclude gifts that can be purchased
/// a limited number of times and can be upgraded to unique
pub fn with_exclude_limited_upgradable(mut self, value: bool) -> Self {
self.exclude_limited_upgradable = Some(value);
self
}
/// Sets a new value for the `exclude_saved` flag.
///
/// # Arguments
///
/// * `value` - Whether to exclude gifts that are saved to the account's profile page.
pub fn with_exclude_saved(mut self, value: bool) -> Self {
self.exclude_saved = Some(value);
self
}
/// Sets a new value for the `exclude_unique` flag.
///
/// # Arguments
///
/// * `value` - Whether to exclude unique gifts.
pub fn with_exclude_unique(mut self, value: bool) -> Self {
self.exclude_unique = Some(value);
self
}
/// Sets a new value for the `exclude_unlimited` flag.
///
/// # Arguments
///
/// * `value` - Whether to exclude gifts that can be purchased an unlimited number of times.
pub fn with_exclude_unlimited(mut self, value: bool) -> Self {
self.exclude_unlimited = Some(value);
self
}
/// Sets a new value for the `exclude_unsaved` flag.
///
/// # Arguments
///
/// * `value` - Whether to exclude gifts that aren't saved to the account's profile page.
pub fn with_exclude_unsaved(mut self, value: bool) -> Self {
self.exclude_unsaved = Some(value);
self
}
/// Sets a new limit.
///
/// # Arguments
///
/// * `value` - The maximum number of gifts to be returned; 1-100; defaults to 100.
pub fn with_limit(mut self, value: Integer) -> Self {
self.limit = Some(value);
self
}
/// Sets a new offset.
///
/// # Arguments
///
/// * `value` - Offset of the first entry to return as received from the previous request;
/// use empty string to get the first chunk of results.
pub fn with_offset<T>(mut self, value: T) -> Self
where
T: Into<String>,
{
self.offset = Some(value.into());
self
}
/// Sets a new value for the `sort_by_price` flag.
///
/// # Arguments
///
/// * `value` - Whether to sort results by gift price instead of send date;
/// sorting is applied before pagination.
pub fn with_sort_by_price(mut self, value: bool) -> Self {
self.sort_by_price = Some(value);
self
}
}
impl Method for GetBusinessAccountGifts {
type Response = OwnedGifts;
fn into_payload(self) -> Result<Payload, PayloadError> {
Payload::json("getBusinessAccountGifts", self)
}
}
/// Returns the gifts owned by a chat.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Serialize)]
pub struct GetChatGifts {
chat_id: ChatId,
exclude_from_blockchain: Option<bool>,
exclude_limited_non_upgradable: Option<bool>,
exclude_limited_upgradable: Option<bool>,
exclude_saved: Option<bool>,
exclude_unique: Option<bool>,
exclude_unlimited: Option<bool>,
exclude_unsaved: Option<bool>,
limit: Option<Integer>,
offset: Option<String>,
sort_by_price: Option<bool>,
}
impl GetChatGifts {
/// Creates a new `GetChatGifts`.
///
/// # Arguments
///
/// * `chat_id` - Unique identifier for the target chat or username of the target channel.
pub fn new<T>(chat_id: T) -> Self
where
T: Into<ChatId>,
{
Self {
chat_id: chat_id.into(),
exclude_from_blockchain: None,
exclude_limited_non_upgradable: None,
exclude_limited_upgradable: None,
exclude_saved: None,
exclude_unique: None,
exclude_unlimited: None,
exclude_unsaved: None,
limit: None,
offset: None,
sort_by_price: None,
}
}
/// Sets a new value for the `exclude_from_blockchain` flag.
///
/// # Arguments
///
/// * `value` - Whether to exclude gifts that were assigned from the TON blockchain
/// and can't be resold or transferred in Telegram.
pub fn with_exclude_from_blockchain(mut self, value: bool) -> Self {
self.exclude_from_blockchain = Some(value);
self
}
/// Sets a new value for the `exclude_limited_non_upgradable` flag.
///
/// # Arguments
///
/// * `value` - Whether to exclude gifts that can be purchased
/// a limited number of times and can't be upgraded to unique.
pub fn with_exclude_limited_non_upgradable(mut self, value: bool) -> Self {
self.exclude_limited_non_upgradable = Some(value);
self
}
/// Sets a new value for the `exclude_limited_upgradable` flag.
///
/// # Arguments
///
/// * `value` - Whether to exclude gifts that can be purchased
/// a limited number of times and can be upgraded to unique.
pub fn with_exclude_limited_upgradable(mut self, value: bool) -> Self {
self.exclude_limited_upgradable = Some(value);
self
}
/// Sets a new value for the `exclude_saved` flag.
///
/// # Arguments
///
/// * `value` - Whether to exclude gifts that are saved to the chat's profile page.
/// Always `false`, unless the bot has the `can_post_messages` administrator right in the channel.
pub fn with_exclude_saved(mut self, value: bool) -> Self {
self.exclude_saved = Some(value);
self
}
/// Sets a new value for the `exclude_unique` flag.
///
/// # Arguments
///
/// * `value` - Whether to exclude unique gifts.
pub fn with_exclude_unique(mut self, value: bool) -> Self {
self.exclude_unique = Some(value);
self
}
/// Sets a new value for the `exclude_unlimited` flag.
///
/// # Arguments
///
/// * `value` - Whether to exclude gifts that can be purchased an unlimited number of times.
pub fn with_exclude_unlimited(mut self, value: bool) -> Self {
self.exclude_unlimited = Some(value);
self
}
/// Sets a new value for the `exclude_unsaved` flag.
///
/// # Arguments
///
/// * `value` - Whether to exclude gifts that aren't saved to the chat's profile page.
/// Always `true`, unless the bot has the `can_post_messages` administrator right in the channel.
pub fn with_exclude_unsaved(mut self, value: bool) -> Self {
self.exclude_unsaved = Some(value);
self
}
/// Sets a new limit.
///
/// # Arguments
///
/// * `value` - The maximum number of gifts to be returned; 1-100. Defaults to 100.
pub fn with_limit(mut self, value: Integer) -> Self {
self.limit = Some(value);
self
}
/// Sets a new offset.
///
/// # Arguments
///
/// * `value` - Offset of the first entry to return as received from the previous request;
/// use an empty string to get the first chunk of results.
pub fn with_offset<T>(mut self, value: T) -> Self
where
T: Into<String>,
{
self.offset = Some(value.into());
self
}
/// Sets a new value for the `sort_by_price` flag.
///
/// # Arguments
///
/// * `value` - Whether to sort results by gift price instead of send date.
/// Sorting is applied before pagination.
pub fn with_sort_by_price(mut self, value: bool) -> Self {
self.sort_by_price = Some(value);
self
}
}
impl Method for GetChatGifts {
type Response = OwnedGifts;
fn into_payload(self) -> Result<Payload, PayloadError> {
Payload::json("getChatGifts", self)
}
}
/// Returns the gifts owned and hosted by a user.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Serialize)]
pub struct GetUserGifts {
user_id: Integer,
exclude_from_blockchain: Option<bool>,
exclude_limited_non_upgradable: Option<bool>,
exclude_limited_upgradable: Option<bool>,
exclude_unique: Option<bool>,
exclude_unlimited: Option<bool>,
limit: Option<Integer>,
offset: Option<String>,
sort_by_price: Option<bool>,
}
impl GetUserGifts {
/// Creates a new `GetUserGifts`.
///
/// # Arguments
///
/// * `user_id` - Unique identifier of the user.
pub fn new(user_id: Integer) -> Self {
Self {
user_id,
exclude_from_blockchain: None,
exclude_limited_non_upgradable: None,
exclude_limited_upgradable: None,
exclude_unique: None,
exclude_unlimited: None,
limit: None,
offset: None,
sort_by_price: None,
}
}
/// Sets a new value for the `exclude_from_blockchain` flag.
///
/// # Arguments
///
/// * `value` - Whether to exclude gifts that were assigned from the TON blockchain
/// and can't be resold or transferred in Telegram.
pub fn with_exclude_from_blockchain(mut self, value: bool) -> Self {
self.exclude_from_blockchain = Some(value);
self
}
/// Sets a new value for the `exclude_limited_non_upgradable` flag.
///
/// # Arguments
///
/// * `value` - Whether to exclude gifts that can be purchased
/// a limited number of times and can't be upgraded to unique.
pub fn with_exclude_limited_non_upgradable(mut self, value: bool) -> Self {
self.exclude_limited_non_upgradable = Some(value);
self
}
/// Sets a new value for the `exclude_limited_upgradable` flag.
///
/// # Arguments
///
/// * `value` - Whether to exclude gifts that can be purchased
/// a limited number of times and can be upgraded to unique.
pub fn with_exclude_limited_upgradable(mut self, value: bool) -> Self {
self.exclude_limited_upgradable = Some(value);
self
}
/// Sets a new value for the `exclude_unique` flag.
///
/// # Arguments
///
/// * `value` - Whether to exclude unique gifts.
pub fn with_exclude_unique(mut self, value: bool) -> Self {
self.exclude_unique = Some(value);
self
}
/// Sets a new value for the `exclude_unlimited` flag.
///
/// # Arguments
///
/// * `value` - Whether to exclude gifts that can be purchased an unlimited number of times.
pub fn with_exclude_unlimited(mut self, value: bool) -> Self {
self.exclude_unlimited = Some(value);
self
}
/// Sets a new limit.
///
/// # Arguments
///
/// * `value` - The maximum number of gifts to be returned; 1-100. Defaults to 100.
pub fn with_limit(mut self, value: Integer) -> Self {
self.limit = Some(value);
self
}
/// Sets a new offset.
///
/// # Arguments
///
/// * `value` - Offset of the first entry to return as received from the previous request;
/// use an empty string to get the first chunk of results.
pub fn with_offset<T>(mut self, value: T) -> Self
where
T: Into<String>,
{
self.offset = Some(value.into());
self
}
/// Sets a new value for the `sort_by_price` flag.
///
/// # Arguments
///
/// * `value` - Whether to sort results by gift price instead of send date.
/// Sorting is applied before pagination.
pub fn with_sort_by_price(mut self, value: bool) -> Self {
self.sort_by_price = Some(value);
self
}
}
impl Method for GetUserGifts {
type Response = OwnedGifts;
fn into_payload(self) -> Result<Payload, PayloadError> {
Payload::json("getUserGifts", self)
}
}
/// Describes a gift received and owned by a user or a chat.
#[derive(Clone, Debug, derive_more::From, Deserialize, PartialEq, Serialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum OwnedGift {
/// A regular gift owned by a user or a chat.
#[from(OwnedGiftRegular)]
Regular(Box<OwnedGiftRegular>),
/// A unique gift received and owned by a user or a chat.
#[from(OwnedGiftUnique)]
Unique(Box<OwnedGiftUnique>),
}
/// Describes a regular gift owned by a user or a chat.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct OwnedGiftRegular {
/// Information about the regular gift.
pub gift: Gift,
/// Date the gift was sent in Unix time.
pub send_date: Integer,
/// Whether the gift can be upgraded to a unique gift;
/// for gifts received on behalf of business accounts only.
pub can_be_upgraded: Option<bool>,
/// Number of Telegram Stars that can be claimed by the receiver instead of the gift;
/// omitted if the gift cannot be converted to Telegram Stars.
pub convert_star_count: Option<Integer>,
/// Special entities that appear in the text.
pub entities: Option<TextEntities>,
/// Whether the sender and gift text are shown only to the gift receiver;
/// otherwise, everyone will be able to see them.
pub is_private: Option<bool>,
/// Whether the gift is displayed on the account's profile page;
/// for gifts received on behalf of business accounts only.
pub is_saved: Option<bool>,
/// Whether the gift's upgrade was purchased after the gift was sent;
/// for gifts received on behalf of business accounts only.
pub is_upgrade_separate: Option<bool>,
/// Unique identifier of the gift for the bot; for gifts received on behalf of business accounts only.
pub owned_gift_id: Option<String>,
/// Number of Telegram Stars that were paid by the sender for the ability to upgrade the gift.
pub prepaid_upgrade_star_count: Option<Integer>,
/// Sender of the gift if it is a known user.
pub sender_user: Option<User>,
/// Text of the message that was added to the gift.
pub text: Option<String>,
/// Unique number reserved for this gift when upgraded.
///
/// See the number field in [`crate::types::UniqueGift`].
pub unique_gift_number: Option<Integer>,
/// Whether the gift was refunded and isn't available anymore.
pub was_refunded: Option<bool>,
}
/// Describes a unique gift received and owned by a user or a chat.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct OwnedGiftUnique {
/// Information about the unique gift.
pub gift: UniqueGift,
/// Date the gift was sent in Unix time.
pub send_date: Integer,
/// Number of Telegram Stars that must be paid to transfer the gift;
/// omitted if the bot cannot transfer the gift.
pub transfer_star_count: Option<Integer>,
/// Whether the gift can be transferred to another owner;
/// for gifts received on behalf of business accounts only.
pub can_be_transferred: Option<bool>,
/// Whether the gift is displayed on the account's profile page;
/// for gifts received on behalf of business accounts only.
pub is_saved: Option<bool>,
/// Point in time (Unix timestamp) when the gift can be transferred.
///
/// If it is in the past, then the gift can be transferred now.
pub next_transfer_date: Option<Integer>,
/// Unique identifier of the received gift for the bot;
/// for gifts received on behalf of business accounts only.
pub owned_gift_id: Option<String>,
/// Sender of the gift if it is a known user.
pub sender_user: Option<User>,
}
/// Contains the list of gifts received and owned by a user or a chat.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct OwnedGifts {
/// The list of gifts.
pub gifts: Vec<OwnedGift>,
/// The total number of gifts owned by the user or the chat.
pub total_count: Integer,
/// Offset for the next request.
///
/// If empty, then there are no more results.
pub next_offset: Option<String>,
}
/// Describes a unique gift that was upgraded from a regular gift.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct UniqueGift {
/// Backdrop of the gift.
pub backdrop: UniqueGiftBackdrop,
/// Human-readable name of the regular gift from which this unique gift was upgraded.
pub base_name: String,
/// Identifier of the regular gift from which the gift was upgraded.
pub gift_id: String,
/// Model of the gift.
pub model: UniqueGiftModel,
/// Unique name of the gift. This name can be used in https://t.me/nft/... links and story areas.
pub name: String,
/// Unique number of the upgraded gift among gifts upgraded from the same regular gift.
pub number: Integer,
/// Symbol of the gift.
pub symbol: UniqueGiftSymbol,
/// The color scheme that can be used by the gift's owner for the chat's name,
/// replies to messages and link previews;
/// for business account gifts and gifts that are currently on sale only.
pub colors: Option<UniqueGiftColors>,
/// Whether the gift was used to craft another gift and isn't available anymore.
pub is_burned: Option<bool>,
/// Whether the gift is assigned from the TON blockchain and can't be resold or transferred in Telegram.
pub is_from_blockchain: Option<bool>,
/// Whether the original regular gift was exclusively purchaseable by Telegram Premium subscribers.
pub is_premium: Option<bool>,
/// Information about the chat that published the gift.
pub publisher_chat: Option<Chat>,
}
/// Describes the backdrop of a unique gift.
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct UniqueGiftBackdrop {
/// Colors of the backdrop.
pub colors: UniqueGiftBackdropColors,
/// Name of the backdrop.
pub name: String,
/// The number of unique gifts that receive this backdrop for every 1000 gifts upgraded.
pub rarity_per_mille: Integer,
}
/// Describes the colors of the backdrop of a unique gift.
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct UniqueGiftBackdropColors {
/// The color in the center of the backdrop in RGB format
pub center_color: Integer,
/// The color on the edges of the backdrop in RGB format
pub edge_color: Integer,
/// The color to be applied to the symbol in RGB format
pub symbol_color: Integer,
/// The color for the text on the backdrop in RGB format
pub text_color: Integer,
}
/// Contains information about the color scheme for a user's name,
/// message replies and link previews based on a unique gift.
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct UniqueGiftColors {
/// Main color used in dark themes; RGB format.
pub dark_theme_main_color: Integer,
/// List of 1-3 additional colors used in dark themes; RGB format.
pub dark_theme_other_colors: Vec<Integer>,
/// Main color used in light themes; RGB format.
pub light_theme_main_color: Integer,
/// List of 1-3 additional colors used in light themes; RGB format.
pub light_theme_other_colors: Vec<Integer>,
/// Custom emoji identifier of the unique gift's model.
pub model_custom_emoji_id: String,
/// Custom emoji identifier of the unique gift's symbol.
pub symbol_custom_emoji_id: String,
}
/// Describes the model of a unique gift.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct UniqueGiftModel {
/// Name of the model.
pub name: String,
/// The number of unique gifts that receive this model for every 1000 gifts upgraded.
pub rarity_per_mille: Integer,
/// The sticker that represents the unique gift
pub sticker: Sticker,
/// Rarity of the model if it is a crafted model.
pub rarity: Option<UniqueGiftModelRarity>,
}
/// Rarity of a unique gift model.
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum UniqueGiftModelRarity {
/// Epic.
Epic,
/// Legendary.
Legendary,
/// Rare.
Rare,
/// Uncommon.
Uncommon,
}
/// Describes the symbol shown on the pattern of a unique gift.
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct UniqueGiftSymbol {
/// Name of the symbol.
pub name: String,
/// The number of unique gifts that receive this model for every 1000 gifts upgraded.
pub rarity_per_mille: Integer,
/// The sticker that represents the unique gift.
pub sticker: Sticker,
}
/// Origin of the unique gift.
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum UniqueGiftOrigin {
/// For upgrades purchased after the gift was sent.
GiftedUpgrade,
/// Gifts bought or sold through gift purchase offers.
Offer,
/// Resale for gifts bought from other users.
Resale,
/// Transfer for gifts transferred from other users or channels.
Transfer,
/// Upgrade for gifts upgraded from regular gifts.
Upgrade,
}
/// Describes a service message about a unique gift that was sent or received.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct UniqueGiftInfo {
/// Information about the gift.
pub gift: UniqueGift,
/// Origin of the gift.
pub origin: UniqueGiftOrigin,
/// For gifts bought from other users, the price paid for the gift.
pub last_resale_star_count: Option<Integer>,
/// Point in time (Unix timestamp) when the gift can be transferred.
///
/// If it is in the past, then the gift can be transferred now.
pub next_transfer_date: Option<Integer>,
/// Unique identifier of the received gift for the bot;
/// only present for gifts received on behalf of business accounts.
pub owned_gift_id: Option<String>,
/// Number of Telegram Stars that must be paid to transfer the gift;
/// omitted if the bot cannot transfer the gift.
pub transfer_star_count: Option<Integer>,
}
/// Gifts a Telegram Premium subscription to the given user.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Serialize)]
pub struct GiftPremiumSubscription {
month_count: Integer,
star_count: Integer,
user_id: Integer,
#[serde(flatten)]
text: Option<RawGiftText>,
}
impl GiftPremiumSubscription {
/// Creates a new `GiftPremiumSubscription`.
///
/// # Arguments
///
/// * `month_count` - Number of months the Telegram Premium subscription will be active for the user;
/// must be one of 3, 6, or 12.
/// * `star_count` - Number of Telegram Stars to pay for the Telegram Premium subscription;
/// must be 1000 for 3 months, 1500 for 6 months, and 2500 for 12 months.
/// * `user_id` - Unique identifier of the target user who will receive a Telegram Premium subscription.
pub fn new(month_count: Integer, star_count: Integer, user_id: Integer) -> Self {
Self {
month_count,
star_count,
user_id,
text: None,
}
}
/// Sets a new text.
///
/// # Arguments
///
/// * `value` - Text that will be shown along with the service message about the subscription; 0-128 characters
pub fn with_text<T>(mut self, value: T) -> Self
where
T: Into<InputText>,
{
self.text = Some(RawGiftText::from(value));
self
}
}
impl Method for GiftPremiumSubscription {
type Response = bool;
fn into_payload(self) -> Result<Payload, PayloadError> {
Payload::json("giftPremiumSubscription", self)
}
}
/// Sends a gift to the given user.
///
/// The gift can't be converted to Telegram Stars by the user.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Serialize)]
pub struct SendGift {
gift_id: String,
chat_id: Option<ChatId>,
pay_for_upgrade: Option<bool>,
#[serde(flatten)]
text: Option<RawGiftText>,
user_id: Option<Integer>,
}
impl SendGift {
/// Creates a new `SendGift` with a `user_id`.
///
/// # Arguments
///
/// * `chat_id` - Unique identifier of the target chat that will receive the gift.
/// * `gift_id` - Identifier of the gift
pub fn for_chat_id<A, B>(chat_id: A, gift_id: B) -> Self
where
A: Into<ChatId>,
B: Into<String>,
{
Self {
gift_id: gift_id.into(),
chat_id: Some(chat_id.into()),
pay_for_upgrade: None,
text: None,
user_id: None,
}
}
/// Creates a new `SendGift` with a `user_id`.
///
/// # Arguments
///
/// * `user_id` - Unique identifier of the target user that will receive the gift.
/// * `gift_id` - Identifier of the gift
pub fn for_user_id<T>(user_id: Integer, gift_id: T) -> Self
where
T: Into<String>,
{
Self {
gift_id: gift_id.into(),
chat_id: None,
pay_for_upgrade: None,
text: None,
user_id: Some(user_id),
}
}
/// Sets a new value for the `pay_for_upgrade` flag.
///
/// # Arguments
///
/// * `value` - Whether to pay for the gift upgrade from the bot's balance,
/// thereby making the upgrade free for the receiver.
pub fn with_pay_for_upgrade(mut self, value: bool) -> Self {
self.pay_for_upgrade = Some(value);
self
}
/// Sets a new text.
///
/// # Arguments
///
/// * `value` - Text that will be shown along with the gift; 0-255 characters.
pub fn with_text<T>(mut self, value: T) -> Self
where
T: Into<InputText>,
{
self.text = Some(RawGiftText::from(value));
self
}
}
impl Method for SendGift {
type Response = bool;
fn into_payload(self) -> Result<Payload, PayloadError> {
Payload::json("sendGift", self)
}
}
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Serialize)]
struct RawGiftText {
text: Option<String>,
text_entities: Option<TextEntities>,
text_parse_mode: Option<ParseMode>,
}
impl<T> From<T> for RawGiftText
where
T: Into<InputText>,
{
fn from(value: T) -> Self {
let value = value.into();
Self {
text: Some(value.data),
text_entities: value.entities,
text_parse_mode: value.parse_mode,
}
}
}