tgbot/types/gift/
mod.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{
4    api::{Method, Payload},
5    types::{ChatId, Integer, ParseMode, Sticker, TextEntities, TextEntity, User},
6};
7
8#[cfg(test)]
9mod tests;
10
11/// Describes the types of gifts that can be gifted to a user or a chat.
12#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, PartialOrd, Serialize)]
13pub struct AcceptedGiftTypes {
14    /// Whether limited regular gifts are accepted.
15    pub limited_gifts: bool,
16    /// Whether a Telegram Premium subscription is accepted.
17    pub premium_subscription: bool,
18    /// Whether unique gifts or gifts that can be upgraded to unique for free are accepted.
19    pub unique_gifts: bool,
20    /// Whether unlimited regular gifts are accepted.
21    pub unlimited_gifts: bool,
22}
23
24impl AcceptedGiftTypes {
25    /// Sets a new value for the `limited_gifts` flag.
26    ///
27    /// # Arguments
28    ///
29    /// * `value` - Whether limited regular gifts are accepted.
30    pub fn with_limited_gifts(mut self, value: bool) -> Self {
31        self.limited_gifts = value;
32        self
33    }
34
35    /// Sets a new value for the `premium_subscription` flag.
36    ///
37    /// # Arguments
38    ///
39    /// * `value` - Whether a Telegram Premium subscription is accepted.
40    pub fn with_premium_subscription(mut self, value: bool) -> Self {
41        self.premium_subscription = value;
42        self
43    }
44
45    /// Sets a new value for the `unique_gifts` flag.
46    ///
47    /// # Arguments
48    ///
49    /// * `value` - Whether unique gifts or gifts that can be upgraded to unique for free are accepted.
50    pub fn with_unique_gifts(mut self, value: bool) -> Self {
51        self.unique_gifts = value;
52        self
53    }
54
55    /// Sets a new value for the `unlimited_gifts` flag.
56    ///
57    /// # Arguments
58    ///
59    /// * `value` - Whether unlimited regular gifts are accepted.
60    pub fn with_unlimited_gifts(mut self, value: bool) -> Self {
61        self.unlimited_gifts = value;
62        self
63    }
64}
65
66/// Represents a gift that can be sent by the bot.
67#[serde_with::skip_serializing_none]
68#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
69pub struct Gift {
70    /// Unique identifier of the gift.
71    pub id: String,
72    /// The sticker that represents the gift.
73    pub sticker: Sticker,
74    /// The number of Telegram Stars that must be paid to send the sticker.
75    pub star_count: Integer,
76    /// The number of remaining gifts of this type that can be sent;
77    /// for limited gifts only.
78    pub remaining_count: Option<Integer>,
79    /// The total number of the gifts of this type that can be sent;
80    /// for limited gifts only.
81    pub total_count: Option<Integer>,
82    /// The number of Telegram Stars that must be paid to upgrade the gift to a unique one.
83    pub upgrade_star_count: Option<Integer>,
84}
85
86impl Gift {
87    /// Creates a new `Gift`.
88    ///
89    /// # Arguments
90    ///
91    /// * `id` - Unique identifier of the gift.
92    /// * `sticker` - The sticker that represents the gift.
93    /// * `star_count` - The number of Telegram Stars that must be paid to send the sticker.
94    pub fn new<T>(id: T, sticker: Sticker, star_count: Integer) -> Self
95    where
96        T: Into<String>,
97    {
98        Self {
99            id: id.into(),
100            sticker,
101            star_count,
102            total_count: None,
103            remaining_count: None,
104            upgrade_star_count: None,
105        }
106    }
107
108    /// Sets a new remaining count.
109    ///
110    /// # Arguments
111    ///
112    /// * `value` - The number of remaining gifts of this type that can be sent.
113    pub fn with_remaining_count(mut self, value: Integer) -> Self {
114        self.remaining_count = Some(value);
115        self
116    }
117
118    /// Sets a new total count.
119    ///
120    /// # Arguments
121    ///
122    /// * `value` - The total number of the gifts of this type that can be sent.
123    pub fn with_total_count(mut self, value: Integer) -> Self {
124        self.total_count = Some(value);
125        self
126    }
127
128    /// Sets a new upgrade star count.
129    ///
130    /// # Arguments
131    ///
132    /// * `value` - The number of Telegram Stars that must be paid to upgrade the gift to a unique one.
133    pub fn with_upgrade_star_count(mut self, value: Integer) -> Self {
134        self.upgrade_star_count = Some(value);
135        self
136    }
137}
138
139/// Describes a service message about a regular gift that was sent or received.
140#[serde_with::skip_serializing_none]
141#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
142pub struct GiftInfo {
143    /// Information about the gift.
144    pub gift: Gift,
145    /// Whether the gift can be upgraded to a unique gift.
146    pub can_be_upgraded: Option<bool>,
147    /// Number of Telegram Stars that can be claimed by the receiver by converting the gift;
148    /// omitted if conversion to Telegram Stars is impossible.
149    pub convert_star_count: Option<Integer>,
150    /// Special entities that appear in the text.
151    pub entities: Option<TextEntities>,
152    /// Whether the sender and gift text are shown only to the gift receiver;
153    /// otherwise, everyone will be able to see them.
154    pub is_private: Option<bool>,
155    /// Unique identifier of the received gift for the bot;
156    /// only present for gifts received on behalf of business accounts.
157    pub owned_gift_id: Option<String>,
158    /// Number of Telegram Stars that were prepaid by the sender for the ability to upgrade the gift.
159    pub prepaid_upgrade_star_count: Option<Integer>,
160    /// Text of the message that was added to the gift.
161    pub text: Option<String>,
162}
163
164impl GiftInfo {
165    /// Creates a new `GiftInfo`.
166    ///
167    /// # Arguments
168    ///
169    /// * `gift` - Information about the gift.
170    pub fn new(gift: Gift) -> Self {
171        Self {
172            gift,
173            can_be_upgraded: None,
174            convert_star_count: None,
175            entities: None,
176            is_private: None,
177            owned_gift_id: None,
178            prepaid_upgrade_star_count: None,
179            text: None,
180        }
181    }
182
183    /// Sets a new value for the `can_be_upgraded` flag.
184    ///
185    /// # Arguments
186    ///
187    /// * `value` - Whether the gift can be upgraded to a unique gift.
188    pub fn with_can_be_upgraded(mut self, value: bool) -> Self {
189        self.can_be_upgraded = Some(value);
190        self
191    }
192
193    /// Sets a new convert star count.
194    ///
195    /// # Arguments
196    ///
197    /// * `value` - Number of Telegram Stars that can be claimed by the receiver by converting the gift;
198    ///   omitted if conversion to Telegram Stars is impossible.
199    pub fn with_convert_star_count(mut self, value: Integer) -> Self {
200        self.convert_star_count = Some(value);
201        self
202    }
203
204    /// Sets a new list of entities.
205    ///
206    /// # Arguments
207    ///
208    /// * `value` - Special entities that appear in the text.
209    pub fn with_entities<T>(mut self, value: T) -> Self
210    where
211        T: IntoIterator<Item = TextEntity>,
212    {
213        self.entities = Some(TextEntities::from_iter(value));
214        self
215    }
216
217    /// Sets a new value for the `is_private` flag.
218    ///
219    /// # Arguments
220    ///
221    /// * `value` - Whether the sender and gift text are shown only to the gift receiver;
222    ///   otherwise, everyone will be able to see them.
223    pub fn with_is_private(mut self, value: bool) -> Self {
224        self.is_private = Some(value);
225        self
226    }
227
228    /// Sets a new owned gift ID.
229    ///
230    /// # Arguments
231    ///
232    /// * `value` - Unique identifier of the received gift for the bot;
233    ///   only present for gifts received on behalf of business accounts.
234    pub fn with_owned_gift_id<T>(mut self, value: T) -> Self
235    where
236        T: Into<String>,
237    {
238        self.owned_gift_id = Some(value.into());
239        self
240    }
241
242    /// Sets a new prepaid upgrade star count.
243    ///
244    /// # Arguments
245    ///
246    /// * `value` - Number of Telegram Stars that were prepaid by the sender for the ability to upgrade the gift.
247    pub fn with_prepaid_upgrade_star_count(mut self, value: Integer) -> Self {
248        self.prepaid_upgrade_star_count = Some(value);
249        self
250    }
251
252    /// Sets a new text.
253    ///
254    /// # Arguments
255    ///
256    /// * `value` - Text of the message that was added to the gift.
257    pub fn with_text<T>(mut self, value: T) -> Self
258    where
259        T: Into<String>,
260    {
261        self.text = Some(value.into());
262        self
263    }
264}
265
266/// Represent a list of gifts.
267#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
268pub struct Gifts {
269    gifts: Vec<Gift>,
270}
271
272impl<T> From<T> for Gifts
273where
274    T: IntoIterator<Item = Gift>,
275{
276    fn from(value: T) -> Self {
277        Self {
278            gifts: value.into_iter().collect(),
279        }
280    }
281}
282
283/// Returns the list of gifts that can be sent by the bot to users.
284#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
285pub struct GetAvailableGifts;
286
287impl Method for GetAvailableGifts {
288    type Response = Gifts;
289
290    fn into_payload(self) -> Payload {
291        Payload::empty("getAvailableGifts")
292    }
293}
294
295/// Describes a gift received and owned by a user or a chat.
296#[derive(Clone, Debug, derive_more::From, Deserialize, PartialEq, PartialOrd, Serialize)]
297#[serde(tag = "type", rename_all = "snake_case")]
298#[allow(clippy::large_enum_variant)]
299pub enum OwnedGift {
300    /// A regular gift owned by a user or a chat.
301    Regular(OwnedGiftRegular),
302    /// A unique gift received and owned by a user or a chat.
303    Unique(OwnedGiftUnique),
304}
305
306/// Describes a regular gift owned by a user or a chat.
307#[serde_with::skip_serializing_none]
308#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
309pub struct OwnedGiftRegular {
310    /// Information about the regular gift.
311    pub gift: Gift,
312    /// Date the gift was sent in Unix time.
313    pub send_date: Integer,
314    /// Whether the gift can be upgraded to a unique gift;
315    /// for gifts received on behalf of business accounts only.
316    pub can_be_upgraded: Option<bool>,
317    /// Number of Telegram Stars that can be claimed by the receiver instead of the gift;
318    /// omitted if the gift cannot be converted to Telegram Stars.
319    pub convert_star_count: Option<Integer>,
320    /// Special entities that appear in the text.
321    pub entities: Option<TextEntities>,
322    /// Whether the sender and gift text are shown only to the gift receiver;
323    /// otherwise, everyone will be able to see them.
324    pub is_private: Option<bool>,
325    /// Whether the gift is displayed on the account's profile page;
326    /// for gifts received on behalf of business accounts only.
327    pub is_saved: Option<bool>,
328    /// Unique identifier of the gift for the bot; for gifts received on behalf of business accounts only.
329    pub owned_gift_id: Option<String>,
330    /// Number of Telegram Stars that were paid by the sender for the ability to upgrade the gift.
331    pub prepaid_upgrade_star_count: Option<Integer>,
332    /// Sender of the gift if it is a known user.
333    pub sender_user: Option<User>,
334    /// Text of the message that was added to the gift.
335    pub text: Option<String>,
336    /// Whether the gift was refunded and isn't available anymore.
337    pub was_refunded: Option<bool>,
338}
339
340impl OwnedGiftRegular {
341    /// Creates a new `OwnedGiftRegular`.
342    ///
343    /// # Arguments
344    ///
345    /// * `gift` - Information about the regular gift.
346    /// * `send_date` - Date the gift was sent in Unix time.
347    pub fn new(gift: Gift, send_date: Integer) -> Self {
348        Self {
349            gift,
350            send_date,
351            can_be_upgraded: None,
352            convert_star_count: None,
353            entities: None,
354            is_private: None,
355            is_saved: None,
356            owned_gift_id: None,
357            prepaid_upgrade_star_count: None,
358            sender_user: None,
359            text: None,
360            was_refunded: None,
361        }
362    }
363
364    /// Sets a new value for the `can_be_upgraded` flag.
365    ///
366    /// # Arguments
367    ///
368    /// * `value` - Whether the gift can be upgraded to a unique gift;
369    ///   for gifts received on behalf of business accounts only.
370    pub fn with_can_be_upgraded(mut self, value: bool) -> Self {
371        self.can_be_upgraded = Some(value);
372        self
373    }
374
375    /// Sets a new convert star count.
376    ///
377    /// # Arguments
378    ///
379    /// * `value` - Number of Telegram Stars that can be claimed by the receiver instead of the gift;
380    ///   omitted if the gift cannot be converted to Telegram Stars.
381    pub fn with_convert_star_count(mut self, value: Integer) -> Self {
382        self.convert_star_count = Some(value);
383        self
384    }
385
386    /// Sets a new list of text entities.
387    ///
388    /// # Arguments
389    ///
390    /// * `value` - Special entities that appear in the text.
391    pub fn with_entities<T>(mut self, value: T) -> Self
392    where
393        T: IntoIterator<Item = TextEntity>,
394    {
395        self.entities = Some(value.into_iter().collect());
396        self
397    }
398
399    /// Sets a new value for the `is_private` flag.
400    ///
401    /// # Arguments
402    ///
403    /// * `value` - Whether the sender and gift text are shown only to the gift receiver;
404    ///   otherwise, everyone will be able to see them.
405    pub fn with_is_private(mut self, value: bool) -> Self {
406        self.is_private = Some(value);
407        self
408    }
409
410    /// Sets a new value for the `is_saved` flag.
411    ///
412    /// # Arguments
413    ///
414    /// * `value` - Whether the gift is displayed on the account's profile page;
415    ///   for gifts received on behalf of business accounts only.
416    pub fn with_is_saved(mut self, value: bool) -> Self {
417        self.is_saved = Some(value);
418        self
419    }
420
421    /// Sets a new owned gift ID.
422    ///
423    /// # Arguments
424    ///
425    /// * `value` - Unique identifier of the gift for the bot;
426    ///   for gifts received on behalf of business accounts only.
427    pub fn with_owned_gift_id<T>(mut self, value: T) -> Self
428    where
429        T: Into<String>,
430    {
431        self.owned_gift_id = Some(value.into());
432        self
433    }
434
435    /// Sets a new prepaid upgrade star count.
436    ///
437    /// # Arguments
438    ///
439    /// * `value` - Number of Telegram Stars that were paid by the sender for the ability to upgrade the gift.
440    pub fn with_prepaid_upgrade_star_count(mut self, value: Integer) -> Self {
441        self.prepaid_upgrade_star_count = Some(value);
442        self
443    }
444
445    /// Sets a new sender user.
446    ///
447    /// # Arguments
448    ///
449    /// * `value` - Sender of the gift if it is a known user.
450    pub fn with_sender_user(mut self, value: User) -> Self {
451        self.sender_user = Some(value);
452        self
453    }
454
455    /// Sets a new text.
456    ///
457    /// # Arguments
458    ///
459    /// * `value` - Text of the message that was added to the gift.
460    pub fn with_text<T>(mut self, value: T) -> Self
461    where
462        T: Into<String>,
463    {
464        self.text = Some(value.into());
465        self
466    }
467
468    /// Sets a new value for the `was_refunded` flag.
469    ///
470    /// # Arguments
471    ///
472    /// * `value` - Whether the gift was refunded and isn't available anymore.
473    pub fn with_was_refunded(mut self, value: bool) -> Self {
474        self.was_refunded = Some(value);
475        self
476    }
477}
478
479/// Describes a unique gift received and owned by a user or a chat.
480#[serde_with::skip_serializing_none]
481#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
482pub struct OwnedGiftUnique {
483    /// Information about the unique gift.
484    pub gift: UniqueGift,
485    /// Date the gift was sent in Unix time.
486    pub send_date: Integer,
487    /// Number of Telegram Stars that must be paid to transfer the gift;
488    /// omitted if the bot cannot transfer the gift.
489    pub transfer_star_count: Option<Integer>,
490    /// Whether the gift can be transferred to another owner;
491    /// for gifts received on behalf of business accounts only.
492    pub can_be_transferred: Option<bool>,
493    /// Whether the gift is displayed on the account's profile page;
494    /// for gifts received on behalf of business accounts only.
495    pub is_saved: Option<bool>,
496    /// Unique identifier of the received gift for the bot;
497    /// for gifts received on behalf of business accounts only.
498    pub owned_gift_id: Option<String>,
499    /// Sender of the gift if it is a known user.
500    pub sender_user: Option<User>,
501}
502
503impl OwnedGiftUnique {
504    /// Creates a new `OwnedGiftUnique`.
505    ///
506    /// # Arguments
507    ///
508    /// * `gift` - Information about the unique gift.
509    /// * `send_date` - Date the gift was sent in Unix time.
510    pub fn new(gift: UniqueGift, send_date: Integer) -> Self {
511        Self {
512            gift,
513            send_date,
514            transfer_star_count: None,
515            can_be_transferred: None,
516            is_saved: None,
517            owned_gift_id: None,
518            sender_user: None,
519        }
520    }
521
522    /// Sets a new transfer star count.
523    ///
524    /// # Arguments
525    ///
526    /// * `value` Number of Telegram Stars that must be paid to transfer the gift;
527    ///   omitted if the bot cannot transfer the gift.
528    pub fn with_transfer_star_count(mut self, value: Integer) -> Self {
529        self.transfer_star_count = Some(value);
530        self
531    }
532
533    /// Sets a new value for the `can_be_transferred` flag.
534    ///
535    /// # Arguments
536    ///
537    /// * `value` - Whether the gift can be transferred to another owner;
538    ///   for gifts received on behalf of business accounts only.
539    pub fn with_can_be_transferred(mut self, value: bool) -> Self {
540        self.can_be_transferred = Some(value);
541        self
542    }
543
544    /// Sets a new value for the `is_saved` flag.
545    ///
546    /// # Arguments
547    ///
548    /// * `value` - Whether the gift is displayed on the account's profile page;
549    ///   for gifts received on behalf of business accounts only.
550    pub fn with_is_saved(mut self, value: bool) -> Self {
551        self.is_saved = Some(value);
552        self
553    }
554
555    /// Sets a new owned gift ID.
556    ///
557    /// # Arguments
558    ///
559    /// * `value` - Unique identifier of the received gift for the bot;
560    ///   for gifts received on behalf of business accounts only.
561    pub fn with_owned_gift_id<T>(mut self, value: T) -> Self
562    where
563        T: Into<String>,
564    {
565        self.owned_gift_id = Some(value.into());
566        self
567    }
568
569    /// Sets a new sender user.
570    ///
571    /// # Arguments
572    ///
573    /// * `value` - Sender of the gift if it is a known user.
574    pub fn with_sender_user(mut self, value: User) -> Self {
575        self.sender_user = Some(value);
576        self
577    }
578}
579
580/// Contains the list of gifts received and owned by a user or a chat.
581#[serde_with::skip_serializing_none]
582#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
583pub struct OwnedGifts {
584    /// The list of gifts.
585    pub gifts: Vec<OwnedGift>,
586    /// The total number of gifts owned by the user or the chat.
587    pub total_count: Integer,
588    /// Offset for the next request.
589    ///
590    /// If empty, then there are no more results.
591    pub next_offset: Option<String>,
592}
593
594impl OwnedGifts {
595    /// Creates a new `OwnedGifts`.
596    ///
597    /// # Arguments
598    ///
599    /// * `gifts` - The list of gifts.
600    /// * `total_count` - The total number of gifts owned by the user or the chat.
601    pub fn new<T>(gifts: T, total_count: Integer) -> Self
602    where
603        T: IntoIterator<Item = OwnedGift>,
604    {
605        Self {
606            gifts: gifts.into_iter().collect(),
607            total_count,
608            next_offset: None,
609        }
610    }
611
612    /// Sets a new next offset.
613    ///
614    /// # Arguments
615    ///
616    /// * `value` - Offset for the next request.
617    pub fn with_next_offset<T>(mut self, value: T) -> Self
618    where
619        T: Into<String>,
620    {
621        self.next_offset = Some(value.into());
622        self
623    }
624}
625
626/// Describes a unique gift that was upgraded from a regular gift.
627#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
628pub struct UniqueGift {
629    /// Backdrop of the gift.
630    pub backdrop: UniqueGiftBackdrop,
631    /// Human-readable name of the regular gift from which this unique gift was upgraded.
632    pub base_name: String,
633    /// Model of the gift.
634    pub model: UniqueGiftModel,
635    /// Unique name of the gift. This name can be used in https://t.me/nft/... links and story areas.
636    pub name: String,
637    /// Unique number of the upgraded gift among gifts upgraded from the same regular gift.
638    pub number: Integer,
639    ///  Symbol of the gift.
640    pub symbol: UniqueGiftSymbol,
641}
642
643/// Describes the backdrop of a unique gift.
644#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
645pub struct UniqueGiftBackdrop {
646    /// Colors of the backdrop.
647    pub colors: UniqueGiftBackdropColors,
648    /// Name of the backdrop.
649    pub name: String,
650    /// The number of unique gifts that receive this backdrop for every 1000 gifts upgraded.
651    pub rarity_per_mille: Integer,
652}
653
654/// Describes the colors of the backdrop of a unique gift.
655#[derive(Clone, Copy, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
656pub struct UniqueGiftBackdropColors {
657    /// The color in the center of the backdrop in RGB format
658    pub center_color: Integer,
659    /// The color on the edges of the backdrop in RGB format
660    pub edge_color: Integer,
661    /// The color to be applied to the symbol in RGB format
662    pub symbol_color: Integer,
663    /// The color for the text on the backdrop in RGB format
664    pub text_color: Integer,
665}
666
667/// Describes the model of a unique gift.
668#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
669pub struct UniqueGiftModel {
670    /// Name of the model.
671    pub name: String,
672    /// The number of unique gifts that receive this model for every 1000 gifts upgraded.
673    pub rarity_per_mille: Integer,
674    /// The sticker that represents the unique gift
675    pub sticker: Sticker,
676}
677
678/// Describes the symbol shown on the pattern of a unique gift.
679#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
680pub struct UniqueGiftSymbol {
681    /// Name of the symbol.
682    pub name: String,
683    /// The number of unique gifts that receive this model for every 1000 gifts upgraded.
684    pub rarity_per_mille: Integer,
685    /// The sticker that represents the unique gift.
686    pub sticker: Sticker,
687}
688
689/// Origin of the unique gift.
690#[derive(Clone, Copy, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
691#[serde(rename_all = "snake_case")]
692pub enum UniqueGiftOrigin {
693    /// Transfer.
694    Transfer,
695    /// Upgrade.
696    Upgrade,
697}
698
699/// Describes a service message about a unique gift that was sent or received.
700#[serde_with::skip_serializing_none]
701#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
702pub struct UniqueGiftInfo {
703    /// Information about the gift.
704    pub gift: UniqueGift,
705    /// Origin of the gift.
706    pub origin: UniqueGiftOrigin,
707    /// Unique identifier of the received gift for the bot;
708    /// only present for gifts received on behalf of business accounts.
709    pub owned_gift_id: Option<String>,
710    /// Number of Telegram Stars that must be paid to transfer the gift;
711    /// omitted if the bot cannot transfer the gift.
712    pub transfer_star_count: Option<Integer>,
713}
714
715impl UniqueGiftInfo {
716    /// Creates a new `UniqueGiftInfo`.
717    ///
718    /// # Arguments
719    ///
720    /// * `gift` - Information about the gift.
721    /// * `origin` - Origin of the gift.
722    pub fn new(gift: UniqueGift, origin: UniqueGiftOrigin) -> Self {
723        Self {
724            gift,
725            origin,
726            owned_gift_id: None,
727            transfer_star_count: None,
728        }
729    }
730
731    /// Sets a new owned gift ID.
732    ///
733    /// # Arguments
734    ///
735    /// * `value` - Unique identifier of the received gift for the bot;
736    ///   only present for gifts received on behalf of business accounts.
737    pub fn with_owned_gift_id<T>(mut self, value: T) -> Self
738    where
739        T: Into<String>,
740    {
741        self.owned_gift_id = Some(value.into());
742        self
743    }
744
745    /// Sets a new transfer star count.
746    ///
747    /// # Arguments
748    ///
749    /// * `value` - Number of Telegram Stars that must be paid to transfer the gift;
750    ///   omitted if the bot cannot transfer the gift.
751    pub fn with_transfer_star_count(mut self, value: Integer) -> Self {
752        self.transfer_star_count = Some(value);
753        self
754    }
755}
756
757/// Gifts a Telegram Premium subscription to the given user.
758#[serde_with::skip_serializing_none]
759#[derive(Clone, Debug, Serialize)]
760pub struct GiftPremiumSubscription {
761    month_count: Integer,
762    star_count: Integer,
763    user_id: Integer,
764    text: Option<String>,
765    text_entities: Option<TextEntities>,
766    text_parse_mode: Option<ParseMode>,
767}
768
769impl GiftPremiumSubscription {
770    /// Creates a new `GiftPremiumSubscription`.
771    ///
772    /// # Arguments
773    ///
774    /// * `month_count` - Number of months the Telegram Premium subscription will be active for the user;
775    ///   must be one of 3, 6, or 12.
776    /// * `star_count` - Number of Telegram Stars to pay for the Telegram Premium subscription;
777    ///   must be 1000 for 3 months, 1500 for 6 months, and 2500 for 12 months.
778    /// * `user_id` - Unique identifier of the target user who will receive a Telegram Premium subscription.
779    pub fn new(month_count: Integer, star_count: Integer, user_id: Integer) -> Self {
780        Self {
781            month_count,
782            star_count,
783            user_id,
784            text: None,
785            text_entities: None,
786            text_parse_mode: None,
787        }
788    }
789
790    /// Sets a new text.
791    ///
792    /// # Arguments
793    ///
794    /// * `value` - Text that will be shown along with the service message about the subscription; 0-128 characters
795    pub fn with_text<T>(mut self, value: T) -> Self
796    where
797        T: Into<String>,
798    {
799        self.text = Some(value.into());
800        self
801    }
802
803    /// Sets a new list of text entities.
804    ///
805    /// # Arguments
806    ///
807    /// * `value` - A list of special entities that appear in the gift text.
808    ///   Entities other than “bold”, “italic”, “underline”,
809    ///   “strikethrough”, “spoiler”, and “custom_emoji” are ignored.
810    pub fn with_text_entities<T>(mut self, value: T) -> Self
811    where
812        T: IntoIterator<Item = TextEntity>,
813    {
814        self.text_parse_mode = None;
815        self.text_entities = Some(TextEntities::from_iter(value));
816        self
817    }
818
819    /// Sets a new text parse mode.
820    ///
821    /// # Arguments
822    ///
823    /// * `value` - Mode for parsing entities in the text.
824    ///   Entities other than “bold”, “italic”, “underline”,
825    ///   “strikethrough”, “spoiler”, and “custom_emoji” are ignored.
826    pub fn with_text_parse_mode(mut self, value: ParseMode) -> Self {
827        self.text_entities = None;
828        self.text_parse_mode = Some(value);
829        self
830    }
831}
832
833impl Method for GiftPremiumSubscription {
834    type Response = bool;
835
836    fn into_payload(self) -> Payload {
837        Payload::json("giftPremiumSubscription", self)
838    }
839}
840
841/// Sends a gift to the given user.
842///
843/// The gift can't be converted to Telegram Stars by the user.
844#[serde_with::skip_serializing_none]
845#[derive(Clone, Debug, Serialize)]
846pub struct SendGift {
847    gift_id: String,
848    chat_id: Option<ChatId>,
849    pay_for_upgrade: Option<bool>,
850    text: Option<String>,
851    text_parse_mode: Option<ParseMode>,
852    text_entities: Option<TextEntities>,
853    user_id: Option<Integer>,
854}
855
856impl SendGift {
857    /// Creates a new `SendGift` with a `user_id`.
858    ///
859    /// # Arguments
860    ///
861    /// * `chat_id` - Unique identifier of the target chat that will receive the gift.
862    /// * `gift_id` - Identifier of the gift
863    pub fn for_chat_id<A, B>(chat_id: A, gift_id: B) -> Self
864    where
865        A: Into<ChatId>,
866        B: Into<String>,
867    {
868        Self {
869            gift_id: gift_id.into(),
870            chat_id: Some(chat_id.into()),
871            pay_for_upgrade: None,
872            text: None,
873            text_parse_mode: None,
874            text_entities: None,
875            user_id: None,
876        }
877    }
878
879    /// Creates a new `SendGift` with a `user_id`.
880    ///
881    /// # Arguments
882    ///
883    /// * `user_id` - Unique identifier of the target user that will receive the gift.
884    /// * `gift_id` - Identifier of the gift
885    pub fn for_user_id<T>(user_id: Integer, gift_id: T) -> Self
886    where
887        T: Into<String>,
888    {
889        Self {
890            gift_id: gift_id.into(),
891            chat_id: None,
892            pay_for_upgrade: None,
893            text: None,
894            text_parse_mode: None,
895            text_entities: None,
896            user_id: Some(user_id),
897        }
898    }
899
900    /// Sets a new value for the `pay_for_upgrade` flag.
901    ///
902    /// # Arguments
903    ///
904    /// * `value` - Whether to pay for the gift upgrade from the bot's balance,
905    ///   thereby making the upgrade free for the receiver.
906    pub fn with_pay_for_upgrade(mut self, value: bool) -> Self {
907        self.pay_for_upgrade = Some(value);
908        self
909    }
910
911    /// Sets a new text.
912    ///
913    /// # Arguments
914    ///
915    /// * `value` - Text that will be shown along with the gift; 0-255 characters.
916    pub fn with_text<T>(mut self, value: T) -> Self
917    where
918        T: Into<String>,
919    {
920        self.text = Some(value.into());
921        self
922    }
923
924    /// Sets a new text parse mode.
925    ///
926    /// # Arguments
927    ///
928    /// * `value` - Mode for parsing entities in the text.
929    ///
930    /// Entities other than “bold”, “italic”, “underline”, “strikethrough”, “spoiler”, and “custom_emoji” are ignored.
931    /// Text entities will be set to [`None`] when this method is called.
932    pub fn with_text_parse_mode(mut self, value: ParseMode) -> Self {
933        self.text_parse_mode = Some(value);
934        self.text_entities = None;
935        self
936    }
937
938    /// Sets a new text entities.
939    ///
940    /// # Arguments
941    ///
942    /// * `value` - A list of special entities that appear in the gift text.
943    ///
944    /// Entities other than “bold”, “italic”, “underline”, “strikethrough”, “spoiler”, and “custom_emoji” are ignored.
945    /// Text parse mode will be set to [`None`] when this method is called.
946    pub fn with_text_entities<T>(mut self, value: T) -> Self
947    where
948        T: IntoIterator<Item = TextEntity>,
949    {
950        self.text_entities = Some(value.into_iter().collect());
951        self.text_parse_mode = None;
952        self
953    }
954}
955
956impl Method for SendGift {
957    type Response = bool;
958
959    fn into_payload(self) -> Payload {
960        Payload::json("sendGift", self)
961    }
962}