tgbot/types/definitions/
business.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{
4    api::{Form, Method, Payload},
5    types::{
6        AcceptedGiftTypes,
7        Chat,
8        InputProfilePhoto,
9        InputProfilePhotoError,
10        InputStoryContent,
11        InputStoryContentError,
12        Integer,
13        Location,
14        OwnedGifts,
15        ParseMode,
16        StarAmount,
17        Sticker,
18        Story,
19        StoryAreas,
20        StoryAreasError,
21        TextEntities,
22        TextEntity,
23        TextEntityError,
24        User,
25    },
26};
27
28/// Represents the rights of a business bot
29#[serde_with::skip_serializing_none]
30#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, PartialOrd, Serialize)]
31pub struct BusinessBotRights {
32    /// Whether the bot can change the privacy settings pertaining to gifts for the business account.
33    pub can_change_gift_settings: Option<bool>,
34    /// Whether the bot can convert regular gifts owned by the business account to Telegram Stars.
35    pub can_convert_gifts_to_stars: Option<bool>,
36    /// Whether the bot can delete all private messages in managed chats.
37    pub can_delete_all_messages: Option<bool>,
38    /// Whether the bot can delete messages sent by the bot.
39    pub can_delete_outgoing_messages: Option<bool>,
40    /// Whether the bot can edit the bio of the business account.
41    pub can_edit_bio: Option<bool>,
42    /// Whether the bot can edit the first and last name of the business account.
43    pub can_edit_name: Option<bool>,
44    /// Whether the bot can edit the profile photo of the business account.
45    pub can_edit_profile_photo: Option<bool>,
46    /// Whether the bot can edit the username of the business account.
47    pub can_edit_username: Option<bool>,
48    /// Whether the bot can post, edit and delete stories on behalf of the business account.
49    pub can_manage_stories: Option<bool>,
50    /// Whether the bot can mark incoming private messages as read.
51    pub can_read_messages: Option<bool>,
52    /// Whether the bot can send and edit messages in the private chats
53    /// that had incoming messages in the last 24 hours.
54    pub can_reply: Option<bool>,
55    /// Whether the bot can transfer and upgrade gifts owned by the business account.
56    pub can_transfer_and_upgrade_gifts: Option<bool>,
57    /// Whether the bot can transfer Telegram Stars received by the business account to its own account,
58    /// or use them to upgrade and transfer gifts.
59    pub can_transfer_stars: Option<bool>,
60    /// Whether the bot can view gifts and the amount of Telegram Stars owned by the business account.
61    pub can_view_gifts_and_stars: Option<bool>,
62}
63
64impl BusinessBotRights {
65    /// Sets a new value for the `can_change_gift_settings` flag.
66    ///
67    /// # Arguments
68    ///
69    /// * `value` - Whether the bot can change the privacy settings pertaining to gifts for the business account.
70    pub fn with_can_change_gift_settings(mut self, value: bool) -> Self {
71        self.can_change_gift_settings = Some(value);
72        self
73    }
74
75    /// Sets a new value for the `can_convert_gifts_to_stars` flag.
76    ///
77    /// # Arguments
78    ///
79    /// * `value` - Whether the bot can convert regular gifts owned by the business account to Telegram Stars.
80    pub fn with_can_convert_gifts_to_stars(mut self, value: bool) -> Self {
81        self.can_convert_gifts_to_stars = Some(value);
82        self
83    }
84
85    /// Sets a new value for the `can_delete_all_messages` flag.
86    ///
87    /// # Arguments
88    ///
89    /// * `value` - Whether the bot can delete all private messages in managed chats.
90    pub fn with_can_delete_all_messages(mut self, value: bool) -> Self {
91        self.can_delete_all_messages = Some(value);
92        self
93    }
94
95    /// Sets a new value for the `can_delete_outgoing_messages` flag.
96    ///
97    /// # Arguments
98    ///
99    /// * `value` - Whether the bot can delete messages sent by the bot.
100    pub fn with_can_delete_outgoing_messages(mut self, value: bool) -> Self {
101        self.can_delete_outgoing_messages = Some(value);
102        self
103    }
104
105    /// Sets a new value for the `can_edit_bio` flag.
106    ///
107    /// # Arguments
108    ///
109    /// * `value` - Whether the bot can edit the bio of the business account.
110    pub fn with_can_edit_bio(mut self, value: bool) -> Self {
111        self.can_edit_bio = Some(value);
112        self
113    }
114
115    /// Sets a new value for the `can_edit_name` flag.
116    ///
117    /// # Arguments
118    ///
119    /// * `value` - Whether the bot can edit the first and last name of the business account.
120    pub fn with_can_edit_name(mut self, value: bool) -> Self {
121        self.can_edit_name = Some(value);
122        self
123    }
124
125    /// Sets a new value for the `can_edit_profile_photo` flag.
126    ///
127    /// # Arguments
128    ///
129    /// * `value` - Whether the bot can edit the profile photo of the business account.
130    pub fn with_can_edit_profile_photo(mut self, value: bool) -> Self {
131        self.can_edit_profile_photo = Some(value);
132        self
133    }
134
135    /// Sets a new value for the `can_edit_username` flag.
136    ///
137    /// # Arguments
138    ///
139    /// * `value` - Whether the bot can edit the username of the business account.
140    pub fn with_can_edit_username(mut self, value: bool) -> Self {
141        self.can_edit_username = Some(value);
142        self
143    }
144
145    /// Sets a new value for the `can_manage_stories` flag.
146    ///
147    /// # Arguments
148    ///
149    /// * `value` - Whether the bot can post, edit and delete stories on behalf of the business account.
150    pub fn with_can_manage_stories(mut self, value: bool) -> Self {
151        self.can_manage_stories = Some(value);
152        self
153    }
154
155    /// Sets a new value for the `can_read_messages` flag.
156    ///
157    /// # Arguments
158    ///
159    /// * `value` - Whether the bot can mark incoming private messages as read.
160    pub fn with_can_read_messages(mut self, value: bool) -> Self {
161        self.can_read_messages = Some(value);
162        self
163    }
164
165    /// Sets a new value for the `can_reply` flag.
166    ///
167    /// # Arguments
168    ///
169    /// * `value` - Whether the bot can send and edit messages in the private chats
170    ///   that had incoming messages in the last 24 hours.
171    pub fn with_can_reply(mut self, value: bool) -> Self {
172        self.can_reply = Some(value);
173        self
174    }
175
176    /// Sets a new value for the `can_transfer_and_upgrade_gifts` flag.
177    ///
178    /// # Arguments
179    ///
180    /// * `value` - Whether the bot can transfer and upgrade gifts owned by the business account.
181    pub fn with_can_transfer_and_upgrade_gifts(mut self, value: bool) -> Self {
182        self.can_transfer_and_upgrade_gifts = Some(value);
183        self
184    }
185
186    /// Sets a new value for the `can_transfer_stars` flag.
187    ///
188    /// # Arguments
189    ///
190    /// * `value` - Whether the bot can transfer Telegram Stars received by the business account to its own account,
191    ///   or use them to upgrade and transfer gifts.
192    pub fn with_can_transfer_stars(mut self, value: bool) -> Self {
193        self.can_transfer_stars = Some(value);
194        self
195    }
196
197    /// Sets a new value for the `can_view_gifts_and_stars` flag.
198    ///
199    /// # Arguments
200    ///
201    /// * `value` - Whether the bot can view gifts and the amount of Telegram Stars owned by the business account.
202    pub fn with_can_view_gifts_and_stars(mut self, value: bool) -> Self {
203        self.can_view_gifts_and_stars = Some(value);
204        self
205    }
206}
207
208/// Describes the connection of the bot with a business account.
209#[serde_with::skip_serializing_none]
210#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
211pub struct BusinessConnection {
212    /// Date the connection was established in Unix time.
213    pub date: Integer,
214    /// Unique identifier of the business connection.
215    pub id: String,
216    /// Whether the connection is active.
217    pub is_enabled: bool,
218    /// Business account user that created the business connection.
219    pub user: User,
220    /// Identifier of a private chat with the user who created the business connection.
221    pub user_chat_id: Integer,
222    /// Rights of the business bot.
223    pub rights: Option<BusinessBotRights>,
224}
225
226impl BusinessConnection {
227    /// Creates a new `BusinessConnection`.
228    ///
229    /// # Arguments
230    ///
231    /// * `date` - Date the connection was established in Unix time.
232    /// * `id` - Unique identifier of the business connection.
233    /// * `user` - Business account user that created the business connection.
234    /// * `user_chat_id` - Identifier of a private chat with the user who created the business connection.
235    pub fn new<T>(date: Integer, id: T, user: User, user_chat_id: Integer) -> Self
236    where
237        T: Into<String>,
238    {
239        Self {
240            date,
241            id: id.into(),
242            is_enabled: false,
243            user,
244            user_chat_id,
245            rights: None,
246        }
247    }
248
249    /// Sets a new value for the `is_enabled` flag.
250    ///
251    /// # Arguments
252    ///
253    /// * `value` - Whether the connection is active.
254    pub fn with_is_enabled(mut self, value: bool) -> Self {
255        self.is_enabled = value;
256        self
257    }
258
259    /// Sets a new rights.
260    ///
261    /// # Arguments
262    ///
263    /// * `value` - Rights of the business bot.
264    pub fn with_rights(mut self, value: BusinessBotRights) -> Self {
265        self.rights = Some(value);
266        self
267    }
268}
269
270/// Represents the intro of the business.
271#[serde_with::skip_serializing_none]
272#[derive(Clone, Default, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
273pub struct BusinessIntro {
274    /// Message text of the business intro.
275    pub message: Option<String>,
276    /// Sticker of the business intro.
277    pub sticker: Option<Sticker>,
278    /// Title text of the business intro.
279    pub title: Option<String>,
280}
281
282impl BusinessIntro {
283    /// Sets a new message.
284    ///
285    /// # Arguments
286    ///
287    /// * `value` - .Message text of the business intro.
288    pub fn with_message<T>(mut self, value: T) -> Self
289    where
290        T: Into<String>,
291    {
292        self.message = Some(value.into());
293        self
294    }
295
296    /// Sets a new sticker.
297    ///
298    /// # Arguments
299    ///
300    /// * `value` - .Sticker of the business intro.
301    pub fn with_sticker(mut self, value: Sticker) -> Self {
302        self.sticker = Some(value);
303        self
304    }
305
306    /// Sets a new title.
307    ///
308    /// # Arguments
309    ///
310    /// * `value` - .Title text of the business intro.
311    pub fn with_title<T>(mut self, value: T) -> Self
312    where
313        T: Into<String>,
314    {
315        self.title = Some(value.into());
316        self
317    }
318}
319
320/// Provides information about address and location of the business.
321#[serde_with::skip_serializing_none]
322#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
323pub struct BusinessLocation {
324    /// Address of the business.
325    pub address: String,
326    /// Location of the business.
327    pub location: Option<Location>,
328}
329
330impl BusinessLocation {
331    /// Creates a new `BusinessLocation`.
332    ///
333    /// # Arguments
334    ///
335    /// * `address` - Address of the business.
336    pub fn new<T>(address: T) -> Self
337    where
338        T: Into<String>,
339    {
340        Self {
341            address: address.into(),
342            location: None,
343        }
344    }
345
346    /// Sets a new location.
347    ///
348    /// # Arguments
349    ///
350    /// * `value` - Location of the business.
351    pub fn with_location(mut self, value: Location) -> Self {
352        self.location = Some(value);
353        self
354    }
355}
356
357/// Provides information about messages deleted from a connected business account.
358#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
359pub struct BusinessMessagesDeleted {
360    /// Unique identifier of the business connection.
361    pub business_connection_id: String,
362    /// Information about a chat in the business account.
363    /// The bot may not have access to the chat or the corresponding user.
364    pub chat: Chat,
365    /// A list of identifiers of deleted messages in the chat of the business account.
366    pub message_ids: Vec<Integer>,
367}
368
369impl BusinessMessagesDeleted {
370    /// Creates a new `BusinessMessagesDeleted`.
371    ///
372    /// # Arguments
373    ///
374    /// * `business_connection_id` - Unique identifier of the business connection.
375    /// * `chat` - Information about a chat in the business account.
376    /// * `message_ids` - A list of identifiers of deleted messages in the chat of the business account.
377    pub fn new<A, B, C>(business_connection_id: A, chat: B, message_ids: C) -> Self
378    where
379        A: Into<String>,
380        B: Into<Chat>,
381        C: IntoIterator<Item = Integer>,
382    {
383        Self {
384            business_connection_id: business_connection_id.into(),
385            chat: chat.into(),
386            message_ids: message_ids.into_iter().collect(),
387        }
388    }
389}
390
391/// Provides information about the time interval describing business opening hours.
392#[derive(Clone, Copy, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
393pub struct BusinessOpeningHoursInterval {
394    /// The minute's sequence number in a week, starting on Monday,
395    /// marking the start of the time interval during which the business is open; 0 - 7 24 60.
396    pub opening_minute: Integer,
397    /// The minute's sequence number in a week, starting on Monday,
398    /// marking the end of the time interval during which the business is open; 0 - 8 24 60.
399    pub closing_minute: Integer,
400}
401
402impl BusinessOpeningHoursInterval {
403    /// Creates a new `BusinessOpeningHoursInterval`.
404    ///
405    /// # Arguments
406    ///
407    /// * `opening_minute` - Start of the time interval during which the business is open.
408    /// * `closing_minute` - End of the time interval during which the business is open.
409    pub fn new(opening_minute: Integer, closing_minute: Integer) -> Self {
410        Self {
411            opening_minute,
412            closing_minute,
413        }
414    }
415}
416
417impl From<(Integer, Integer)> for BusinessOpeningHoursInterval {
418    fn from((opening_minute, closing_minute): (Integer, Integer)) -> Self {
419        Self::new(opening_minute, closing_minute)
420    }
421}
422
423/// Provides information about the opening hours of the business.
424#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
425pub struct BusinessOpeningHours {
426    /// Unique name of the time zone for which the opening hours are defined.
427    pub time_zone_name: String,
428    /// List of time intervals describing business opening hours.
429    pub opening_hours: Vec<BusinessOpeningHoursInterval>,
430}
431
432impl BusinessOpeningHours {
433    /// Creates a new `BusinessOpeningHours`.
434    ///
435    /// # Arguments
436    ///
437    /// * `time_zone_name` - Unique name of the time zone for which the opening hours are defined.
438    /// * `opening_hours` - List of time intervals describing business opening hours.
439    pub fn new<A, B, C>(time_zone_name: A, opening_hours: B) -> Self
440    where
441        A: Into<String>,
442        B: IntoIterator<Item = C>,
443        C: Into<BusinessOpeningHoursInterval>,
444    {
445        Self {
446            time_zone_name: time_zone_name.into(),
447            opening_hours: opening_hours.into_iter().map(Into::into).collect(),
448        }
449    }
450}
451
452/// Converts a given regular gift to Telegram Stars.
453///
454/// Requires the can_convert_gifts_to_stars business bot right.
455#[derive(Clone, Debug, Serialize)]
456pub struct ConvertGiftToStars {
457    business_connection_id: String,
458    owned_gift_id: String,
459}
460
461impl ConvertGiftToStars {
462    /// Creates a new `ConvertGiftToStars`.
463    ///
464    /// # Arguments
465    ///
466    /// * `business_connection_id` - Unique identifier of the business connection.
467    /// * `owned_gift_id` - Unique identifier of the regular gift that should be converted to Telegram Stars.
468    pub fn new<A, B>(business_connection_id: A, owned_gift_id: B) -> Self
469    where
470        A: Into<String>,
471        B: Into<String>,
472    {
473        Self {
474            business_connection_id: business_connection_id.into(),
475            owned_gift_id: owned_gift_id.into(),
476        }
477    }
478}
479
480impl Method for ConvertGiftToStars {
481    type Response = bool;
482
483    fn into_payload(self) -> Payload {
484        Payload::json("convertGiftToStars", self)
485    }
486}
487
488/// Deletes messages on behalf of a business account.
489///
490/// Requires the `can_delete_outgoing_messages` business bot right to delete messages sent by the bot itself,
491/// or the `can_delete_all_messages` business bot right to delete any message.
492#[derive(Clone, Debug, Serialize)]
493pub struct DeleteBusinessMessages {
494    business_connection_id: String,
495    message_ids: Vec<Integer>,
496}
497
498impl DeleteBusinessMessages {
499    /// Creates a new `DeleteBusinessMessages`.
500    ///
501    /// # Arguments
502    ///
503    /// * `business_connection_id` - Unique identifier of the business connection
504    ///   on behalf of which to delete the messages.
505    /// * `message_ids` - A list of 1-100 identifiers of messages to delete;
506    ///   all messages must be from the same chat;
507    ///   see deleteMessage for limitations on which messages can be deleted.
508    pub fn new<A, B>(business_connection_id: A, message_ids: B) -> Self
509    where
510        A: Into<String>,
511        B: IntoIterator<Item = Integer>,
512    {
513        Self {
514            business_connection_id: business_connection_id.into(),
515            message_ids: message_ids.into_iter().collect(),
516        }
517    }
518}
519
520impl Method for DeleteBusinessMessages {
521    type Response = bool;
522
523    fn into_payload(self) -> Payload {
524        Payload::json("deleteBusinessMessages", self)
525    }
526}
527
528/// Deletes a story previously posted by the bot on behalf of a managed business account.
529///
530/// Requires the can_manage_stories business bot right.
531#[derive(Clone, Debug, Serialize)]
532pub struct DeleteStory {
533    business_connection_id: String,
534    story_id: Integer,
535}
536
537impl DeleteStory {
538    /// Creates a new `DeleteStory`.
539    ///
540    /// # Arguments
541    ///
542    /// * `business_connection_id` - Unique identifier of the business connection.
543    /// * `story_id` - Unique identifier of the story to delete.
544    pub fn new<T>(business_connection_id: T, story_id: Integer) -> Self
545    where
546        T: Into<String>,
547    {
548        Self {
549            business_connection_id: business_connection_id.into(),
550            story_id,
551        }
552    }
553}
554
555impl Method for DeleteStory {
556    type Response = bool;
557
558    fn into_payload(self) -> Payload {
559        Payload::json("deleteStory", self)
560    }
561}
562
563/// Edits a story previously posted by the bot on behalf of a managed business account.
564///
565/// Requires the `can_manage_stories` business bot right.
566pub struct EditStory {
567    form: Form,
568}
569
570impl EditStory {
571    /// Creates a new `EditStory`.
572    ///
573    /// # Arguments
574    ///
575    /// * `business_connection_id` - Unique identifier of the business connection.
576    /// * `content` - Content of the story.
577    /// * `story_id` - Unique identifier of the story to edit.
578    pub fn new<A, B>(business_connection_id: A, content: B, story_id: Integer) -> Result<Self, InputStoryContentError>
579    where
580        A: Into<String>,
581        B: Into<InputStoryContent>,
582    {
583        let mut form: Form = content.into().try_into()?;
584        form.insert_field("business_connection_id", business_connection_id.into());
585        form.insert_field("story_id", story_id);
586        Ok(Self { form })
587    }
588
589    /// Sets a new list of areas.
590    ///
591    /// # Arguments
592    ///
593    /// * `value` - A list of clickable areas to be shown on the story.
594    pub fn with_areas<T>(mut self, value: T) -> Result<Self, StoryAreasError>
595    where
596        T: Into<StoryAreas>,
597    {
598        let value = value.into().serialize()?;
599        self.form.insert_field("areas", value);
600        Ok(self)
601    }
602
603    /// Sets a new caption.
604    ///
605    /// # Arguments
606    ///
607    /// * `value` -  Caption of the story, 0-2048 characters after entities parsing.
608    pub fn with_caption<T>(mut self, value: T) -> Self
609    where
610        T: Into<String>,
611    {
612        self.form.insert_field("caption", value.into());
613        self
614    }
615
616    /// Sets a new list of caption entities.
617    ///
618    /// # Arguments
619    ///
620    /// * `value` - A list of special entities that appear in the caption.
621    pub fn with_caption_entities<T>(mut self, value: T) -> Result<Self, TextEntityError>
622    where
623        T: IntoIterator<Item = TextEntity>,
624    {
625        let value = TextEntities::from_iter(value);
626        let value = value.serialize()?;
627        self.form.remove_field("parse_mode");
628        self.form.insert_field("caption_entities", value);
629        Ok(self)
630    }
631
632    /// Sets a new parse mode.
633    ///
634    /// # Arguments
635    ///
636    /// * `value` - Mode for parsing entities in the story caption.
637    pub fn with_parse_mode(mut self, value: ParseMode) -> Self {
638        self.form.remove_field("caption_entities");
639        self.form.insert_field("parse_mode", value);
640        self
641    }
642}
643
644impl Method for EditStory {
645    type Response = Story;
646
647    fn into_payload(self) -> Payload {
648        Payload::form("editStory", self.form)
649    }
650}
651
652/// Returns the gifts received and owned by a managed business account.
653///
654/// Requires the `can_view_gifts_and_stars` business bot right.
655#[serde_with::skip_serializing_none]
656#[derive(Clone, Debug, Serialize)]
657pub struct GetBusinessAccountGifts {
658    business_connection_id: String,
659    exclude_limited: Option<bool>,
660    exclude_saved: Option<bool>,
661    exclude_unique: Option<bool>,
662    exclude_unlimited: Option<bool>,
663    exclude_unsaved: Option<bool>,
664    limit: Option<Integer>,
665    offset: Option<String>,
666    sort_by_price: Option<bool>,
667}
668
669impl GetBusinessAccountGifts {
670    /// Creates a new `GetBusinessAccountGifts`.
671    ///
672    /// # Arguments
673    ///
674    /// * `business_connection_id` - Unique identifier of the business connection.
675    pub fn new<T>(business_connection_id: T) -> Self
676    where
677        T: Into<String>,
678    {
679        Self {
680            business_connection_id: business_connection_id.into(),
681            exclude_limited: None,
682            exclude_saved: None,
683            exclude_unique: None,
684            exclude_unlimited: None,
685            exclude_unsaved: None,
686            limit: None,
687            offset: None,
688            sort_by_price: None,
689        }
690    }
691
692    /// Sets a new value for the `exclude_limited` flag.
693    ///
694    /// # Arguments
695    ///
696    /// * `value` - Whether to exclude gifts that can be purchased a limited number of times.
697    pub fn with_exclude_limited(mut self, value: bool) -> Self {
698        self.exclude_limited = Some(value);
699        self
700    }
701
702    /// Sets a new value for the `exclude_saved` flag.
703    ///
704    /// # Arguments
705    ///
706    /// * `value` - Whether to exclude gifts that are saved to the account's profile page.
707    pub fn with_exclude_saved(mut self, value: bool) -> Self {
708        self.exclude_saved = Some(value);
709        self
710    }
711
712    /// Sets a new value for the `exclude_unique` flag.
713    ///
714    /// # Arguments
715    ///
716    /// * `value` - Whether to exclude unique gifts.
717    pub fn with_exclude_unique(mut self, value: bool) -> Self {
718        self.exclude_unique = Some(value);
719        self
720    }
721
722    /// Sets a new value for the `exclude_unlimited` flag.
723    ///
724    /// # Arguments
725    ///
726    /// * `value` - Whether to exclude gifts that can be purchased an unlimited number of times.
727    pub fn with_exclude_unlimited(mut self, value: bool) -> Self {
728        self.exclude_unlimited = Some(value);
729        self
730    }
731
732    /// Sets a new value for the `exclude_unsaved` flag.
733    ///
734    /// # Arguments
735    ///
736    /// * `value` - Whether to exclude gifts that aren't saved to the account's profile page.
737    pub fn with_exclude_unsaved(mut self, value: bool) -> Self {
738        self.exclude_unsaved = Some(value);
739        self
740    }
741
742    /// Sets a new limit.
743    ///
744    /// # Arguments
745    ///
746    /// * `value` - The maximum number of gifts to be returned; 1-100; defaults to 100.
747    pub fn with_limit(mut self, value: Integer) -> Self {
748        self.limit = Some(value);
749        self
750    }
751
752    /// Sets a new offset.
753    ///
754    /// # Arguments
755    ///
756    /// * `value` - Offset of the first entry to return as received from the previous request;
757    ///   use empty string to get the first chunk of results.
758    pub fn with_offset<T>(mut self, value: T) -> Self
759    where
760        T: Into<String>,
761    {
762        self.offset = Some(value.into());
763        self
764    }
765
766    /// Sets a new value for the `sort_by_price` flag.
767    ///
768    /// # Arguments
769    ///
770    /// * `value` - Whether to sort results by gift price instead of send date;
771    ///   sorting is applied before pagination.
772    pub fn with_sort_by_price(mut self, value: bool) -> Self {
773        self.sort_by_price = Some(value);
774        self
775    }
776}
777
778impl Method for GetBusinessAccountGifts {
779    type Response = OwnedGifts;
780
781    fn into_payload(self) -> Payload {
782        Payload::json("getBusinessAccountGifts", self)
783    }
784}
785
786/// Returns the amount of Telegram Stars owned by a managed business account.
787///
788/// Requires the can_view_gifts_and_stars business bot right.
789#[derive(Clone, Debug, Serialize)]
790pub struct GetBusinessAccountStarBalance {
791    business_connection_id: String,
792}
793
794impl GetBusinessAccountStarBalance {
795    /// Creates a new `GetBusinessAccountStarBalance`.
796    ///
797    /// # Arguments
798    ///
799    /// * `business_connection_id` - Unique identifier of the business connection.
800    pub fn new<T>(business_connection_id: T) -> Self
801    where
802        T: Into<String>,
803    {
804        Self {
805            business_connection_id: business_connection_id.into(),
806        }
807    }
808}
809
810impl Method for GetBusinessAccountStarBalance {
811    type Response = StarAmount;
812
813    fn into_payload(self) -> Payload {
814        Payload::json("getBusinessAccountStarBalance", self)
815    }
816}
817
818/// Returns information about the connection of the bot with a business account.
819#[derive(Clone, Debug, Serialize)]
820pub struct GetBusinessConnection {
821    business_connection_id: String,
822}
823
824impl GetBusinessConnection {
825    /// Creates a new `GetBusinessConnection`.
826    ///
827    /// # Arguments
828    ///
829    /// * `business_connection_id` - Unique identifier of the business connection.
830    pub fn new<T>(business_connection_id: T) -> Self
831    where
832        T: Into<String>,
833    {
834        Self {
835            business_connection_id: business_connection_id.into(),
836        }
837    }
838}
839
840impl Method for GetBusinessConnection {
841    type Response = BusinessConnection;
842
843    fn into_payload(self) -> Payload {
844        Payload::json("getBusinessConnection", self)
845    }
846}
847
848/// Posts a story on behalf of a managed business account.
849///
850/// Requires the `can_manage_stories` business bot right.
851pub struct PostStory {
852    form: Form,
853}
854
855impl PostStory {
856    /// Creates a new `PostStory`.
857    ///
858    /// # Arguments
859    ///
860    /// * `active_period` - Period after which the story is moved to the archive, in seconds;
861    ///   must be one of 6 * 3600, 12 * 3600, 86400, or 2 * 86400.
862    /// * `business_connection_id` - Unique identifier of the business connection.
863    /// * `content` - Content of the story.
864    pub fn new<A, B>(
865        active_period: Integer,
866        business_connection_id: A,
867        content: B,
868    ) -> Result<Self, InputStoryContentError>
869    where
870        A: Into<String>,
871        B: Into<InputStoryContent>,
872    {
873        let mut form: Form = content.into().try_into()?;
874        form.insert_field("active_period", active_period);
875        form.insert_field("business_connection_id", business_connection_id.into());
876        Ok(Self { form })
877    }
878
879    /// Sets a new list of areas.
880    ///
881    /// # Arguments
882    ///
883    /// * `value` - A list of clickable areas to be shown on the story.
884    pub fn with_areas<T>(mut self, value: T) -> Result<Self, StoryAreasError>
885    where
886        T: Into<StoryAreas>,
887    {
888        let value = value.into().serialize()?;
889        self.form.insert_field("areas", value);
890        Ok(self)
891    }
892
893    /// Sets a new caption.
894    ///
895    /// # Arguments
896    ///
897    /// * `value` -  Caption of the story, 0-2048 characters after entities parsing.
898    pub fn with_caption<T>(mut self, value: T) -> Self
899    where
900        T: Into<String>,
901    {
902        self.form.insert_field("caption", value.into());
903        self
904    }
905
906    /// Sets a new list of caption entities.
907    ///
908    /// # Arguments
909    ///
910    /// * `value` - A list of special entities that appear in the caption.
911    pub fn with_caption_entities<T>(mut self, value: T) -> Result<Self, TextEntityError>
912    where
913        T: IntoIterator<Item = TextEntity>,
914    {
915        let value = TextEntities::from_iter(value);
916        let value = value.serialize()?;
917        self.form.remove_field("parse_mode");
918        self.form.insert_field("caption_entities", value);
919        Ok(self)
920    }
921
922    /// Sets a new parse mode.
923    ///
924    /// # Arguments
925    ///
926    /// * `value` - Mode for parsing entities in the story caption.
927    pub fn with_parse_mode(mut self, value: ParseMode) -> Self {
928        self.form.remove_field("caption_entities");
929        self.form.insert_field("parse_mode", value);
930        self
931    }
932
933    /// Sets a new value for the `post_to_chat_page` flag.
934    ///
935    /// # Arguments
936    ///
937    /// * `value` - Whether to keep the story accessible after it expires.
938    pub fn with_post_to_chat_page(mut self, value: bool) -> Self {
939        self.form.insert_field("post_to_chat_page", value);
940        self
941    }
942
943    /// Sets a new value for the `protect_content` flag.
944    ///
945    /// # Arguments
946    ///
947    /// * `value` Whether the content of the story must be protected from forwarding and screenshotting.
948    pub fn with_protect_content(mut self, value: bool) -> Self {
949        self.form.insert_field("protect_content", value);
950        self
951    }
952}
953
954impl Method for PostStory {
955    type Response = Story;
956
957    fn into_payload(self) -> Payload {
958        Payload::form("postStory", self.form)
959    }
960}
961
962/// Marks incoming message as read on behalf of a business account.
963///
964/// Requires the can_read_messages business bot right.
965#[derive(Clone, Debug, Serialize)]
966pub struct ReadBusinessMessage {
967    business_connection_id: String,
968    chat_id: Integer,
969    message_id: Integer,
970}
971
972impl ReadBusinessMessage {
973    /// Creates a new `ReadBusinessMessage`.
974    ///
975    /// # Arguments
976    ///
977    /// * `business_connection_id` - Unique identifier of the business connection
978    ///   on behalf of which to read the message.
979    /// * `chat_id` - Unique identifier of the chat in which the message was received;
980    ///   the chat must have been active in the last 24 hours.
981    /// * `message_id` - Unique identifier of the message to mark as read.
982    pub fn new<T>(business_connection_id: T, chat_id: Integer, message_id: Integer) -> Self
983    where
984        T: Into<String>,
985    {
986        Self {
987            business_connection_id: business_connection_id.into(),
988            chat_id,
989            message_id,
990        }
991    }
992}
993
994impl Method for ReadBusinessMessage {
995    type Response = bool;
996
997    fn into_payload(self) -> Payload {
998        Payload::json("readBusinessMessage", self)
999    }
1000}
1001
1002/// Removes the current profile photo of a managed business account.
1003///
1004/// Requires the can_edit_profile_photo business bot right.
1005#[serde_with::skip_serializing_none]
1006#[derive(Clone, Debug, Serialize)]
1007pub struct RemoveBusinessAccountProfilePhoto {
1008    business_connection_id: String,
1009    is_public: Option<bool>,
1010}
1011
1012impl RemoveBusinessAccountProfilePhoto {
1013    /// Creates a new `RemoveBusinessAccountProfilePhoto`.
1014    ///
1015    /// # Arguments
1016    ///
1017    /// * `business_connection_id` - Unique identifier of the business connection
1018    pub fn new<T>(business_connection_id: T) -> Self
1019    where
1020        T: Into<String>,
1021    {
1022        Self {
1023            business_connection_id: business_connection_id.into(),
1024            is_public: None,
1025        }
1026    }
1027
1028    /// Sets a new value for the `is_public` flag.
1029    ///
1030    /// # Arguments
1031    ///
1032    /// * `value` - Whether to remove the public photo,
1033    ///   which is visible even if the main photo is hidden by the business account's privacy settings;
1034    ///   after the main photo is removed, the previous profile photo (if present) becomes the main photo.
1035    pub fn with_is_public(mut self, value: bool) -> Self {
1036        self.is_public = Some(value);
1037        self
1038    }
1039}
1040
1041impl Method for RemoveBusinessAccountProfilePhoto {
1042    type Response = bool;
1043
1044    fn into_payload(self) -> Payload {
1045        Payload::json("removeBusinessAccountProfilePhoto", self)
1046    }
1047}
1048
1049/// Changes the bio of a managed business account.
1050///
1051/// Requires the can_change_bio business bot right.
1052#[serde_with::skip_serializing_none]
1053#[derive(Clone, Debug, Serialize)]
1054pub struct SetBusinessAccountBio {
1055    business_connection_id: String,
1056    bio: Option<String>,
1057}
1058
1059impl SetBusinessAccountBio {
1060    /// Creates a new `SetBusinessAccountBio`.
1061    ///
1062    /// # Arguments
1063    ///
1064    /// * `business_connection_id` - Unique identifier of the business connection
1065    pub fn new<T>(business_connection_id: T) -> Self
1066    where
1067        T: Into<String>,
1068    {
1069        Self {
1070            business_connection_id: business_connection_id.into(),
1071            bio: None,
1072        }
1073    }
1074
1075    /// Sets a new bio
1076    ///
1077    /// # Arguments
1078    ///
1079    // * `value` - The new value of the bio for the business account; 0-140 characters.
1080    pub fn with_bio<T>(mut self, value: T) -> Self
1081    where
1082        T: Into<String>,
1083    {
1084        self.bio = Some(value.into());
1085        self
1086    }
1087}
1088
1089impl Method for SetBusinessAccountBio {
1090    type Response = bool;
1091
1092    fn into_payload(self) -> Payload {
1093        Payload::json("setBusinessAccountBio", self)
1094    }
1095}
1096
1097/// Changes the privacy settings pertaining to incoming gifts in a managed business account.
1098///
1099/// Requires the can_change_gift_settings business bot right.
1100#[derive(Clone, Debug, Serialize)]
1101pub struct SetBusinessAccountGiftSettings {
1102    accepted_gift_types: AcceptedGiftTypes,
1103    business_connection_id: String,
1104    show_gift_button: bool,
1105}
1106
1107impl SetBusinessAccountGiftSettings {
1108    /// Creates a new `SetBusinessAccountGiftSettings`.
1109    ///
1110    /// # Arguments
1111    ///
1112    /// * `business_connection_id` - Unique identifier of the business connection.
1113    /// * `show_gift_button` - Whether a button for sending a gift to the user
1114    ///   or by the business account must always be shown in the input field
1115    /// * `accepted_gift_types` - Types of gifts accepted by the business account.
1116    pub fn new<T>(business_connection_id: T, show_gift_button: bool, accepted_gift_types: AcceptedGiftTypes) -> Self
1117    where
1118        T: Into<String>,
1119    {
1120        Self {
1121            business_connection_id: business_connection_id.into(),
1122            show_gift_button,
1123            accepted_gift_types,
1124        }
1125    }
1126}
1127
1128impl Method for SetBusinessAccountGiftSettings {
1129    type Response = bool;
1130
1131    fn into_payload(self) -> Payload {
1132        Payload::json("setBusinessAccountGiftSettings", self)
1133    }
1134}
1135
1136/// Changes the first and last name of a managed business account.
1137///
1138/// Requires the can_change_name business bot right.
1139#[serde_with::skip_serializing_none]
1140#[derive(Clone, Debug, Serialize)]
1141pub struct SetBusinessAccountName {
1142    business_connection_id: String,
1143    first_name: String,
1144    last_name: Option<String>,
1145}
1146
1147impl SetBusinessAccountName {
1148    /// Creates a new `SetBusinessAccountName`.
1149    ///
1150    /// # Arguments
1151    ///
1152    /// * `business_connection_id` - Unique identifier of the business connection.
1153    /// * `first_name` - The new value of the first name for the business account; 1-64 characters.
1154    pub fn new<A, B>(business_connection_id: A, first_name: B) -> Self
1155    where
1156        A: Into<String>,
1157        B: Into<String>,
1158    {
1159        Self {
1160            business_connection_id: business_connection_id.into(),
1161            first_name: first_name.into(),
1162            last_name: None,
1163        }
1164    }
1165
1166    /// Sets a new last name.
1167    ///
1168    /// # Arguments
1169    ///
1170    /// * `value` - The new value of the last name for the business account; 0-64 characters.
1171    pub fn with_last_name<T>(mut self, value: T) -> Self
1172    where
1173        T: Into<String>,
1174    {
1175        self.last_name = Some(value.into());
1176        self
1177    }
1178}
1179
1180impl Method for SetBusinessAccountName {
1181    type Response = bool;
1182
1183    fn into_payload(self) -> Payload {
1184        Payload::json("setBusinessAccountName", self)
1185    }
1186}
1187
1188/// Changes the profile photo of a managed business account.
1189///
1190/// Requires the can_edit_profile_photo business bot right.
1191#[derive(Debug)]
1192pub struct SetBusinessAccountProfilePhoto {
1193    form: Form,
1194}
1195
1196impl SetBusinessAccountProfilePhoto {
1197    /// Creates a new `SetBusinessAccountProfilePhoto`.
1198    ///
1199    /// # Arguments
1200    ///
1201    /// * `business_connection_id` - Unique identifier of the business connection.
1202    /// * `photo` - The new profile photo to set.
1203    pub fn new<A, B>(business_connection_id: A, photo: B) -> Result<Self, InputProfilePhotoError>
1204    where
1205        A: Into<String>,
1206        B: Into<InputProfilePhoto>,
1207    {
1208        let mut form = Form::try_from(photo.into())?;
1209        form.insert_field("business_connection_id", business_connection_id.into());
1210        Ok(Self { form })
1211    }
1212
1213    /// Sets a new value for the `is_public` flag.
1214    ///
1215    /// # Arguments
1216    ///
1217    /// * `value` - Whether to set the public photo,
1218    ///   which will be visible even if the main photo is hidden by the business account's privacy settings;
1219    ///   an account can have only one public photo.
1220    pub fn with_is_public(mut self, value: bool) -> Self {
1221        self.form.insert_field("is_public", value);
1222        self
1223    }
1224}
1225
1226impl Method for SetBusinessAccountProfilePhoto {
1227    type Response = bool;
1228
1229    fn into_payload(self) -> Payload {
1230        Payload::form("setBusinessAccountProfilePhoto", self.form)
1231    }
1232}
1233
1234/// Changes the username of a managed business account.
1235///
1236/// Requires the can_change_username business bot right.
1237#[serde_with::skip_serializing_none]
1238#[derive(Clone, Debug, Serialize)]
1239pub struct SetBusinessAccountUsername {
1240    business_connection_id: String,
1241    username: Option<String>,
1242}
1243
1244impl SetBusinessAccountUsername {
1245    /// Creates a new `SetBusinessAccountUsername`.
1246    ///
1247    /// # Arguments
1248    ///
1249    /// * `business_connection_id` - Unique identifier of the business connection.
1250    pub fn new<T>(business_connection_id: T) -> Self
1251    where
1252        T: Into<String>,
1253    {
1254        Self {
1255            business_connection_id: business_connection_id.into(),
1256            username: None,
1257        }
1258    }
1259
1260    /// Sets a new username
1261    ///
1262    /// # Arguments
1263    ///
1264    /// * `value` - The new value of the username for the business account; 0-32 characters.
1265    pub fn with_username<T>(mut self, value: T) -> Self
1266    where
1267        T: Into<String>,
1268    {
1269        self.username = Some(value.into());
1270        self
1271    }
1272}
1273
1274impl Method for SetBusinessAccountUsername {
1275    type Response = bool;
1276
1277    fn into_payload(self) -> Payload {
1278        Payload::json("setBusinessAccountUsername", self)
1279    }
1280}
1281
1282/// Transfers Telegram Stars from the business account balance to the bot's balance.
1283///
1284/// Requires the can_transfer_stars business bot right.
1285#[derive(Clone, Debug, Serialize)]
1286pub struct TransferBusinessAccountStars {
1287    business_connection_id: String,
1288    star_count: Integer,
1289}
1290
1291impl TransferBusinessAccountStars {
1292    /// Creates a new `TransferBusinessAccountStars`.
1293    ///
1294    /// # Arguments
1295    ///
1296    /// * `business_connection_id` - Unique identifier of the business connection.
1297    /// * `star_count` - Number of Telegram Stars to transfer; 1-10000.
1298    pub fn new<T>(business_connection_id: T, star_count: Integer) -> Self
1299    where
1300        T: Into<String>,
1301    {
1302        Self {
1303            business_connection_id: business_connection_id.into(),
1304            star_count,
1305        }
1306    }
1307}
1308
1309impl Method for TransferBusinessAccountStars {
1310    type Response = bool;
1311
1312    fn into_payload(self) -> Payload {
1313        Payload::json("transferBusinessAccountStars", self)
1314    }
1315}
1316
1317/// Transfers an owned unique gift to another user.
1318///
1319/// Requires the `can_transfer_and_upgrade_gifts` business bot right.
1320/// Requires `can_transfer_stars` business bot right if the transfer is paid.
1321#[serde_with::skip_serializing_none]
1322#[derive(Clone, Debug, Serialize)]
1323pub struct TransferGift {
1324    business_connection_id: String,
1325    owned_gift_id: String,
1326    new_owner_chat_id: Integer,
1327    star_count: Option<Integer>,
1328}
1329
1330impl TransferGift {
1331    /// Creates a new `TransferGift`.
1332    ///
1333    /// # Arguments
1334    ///
1335    /// * `business_connection_id` - Unique identifier of the business connection.
1336    /// * `owned_gift_id` - Unique identifier of the regular gift that should be transferred.
1337    /// * `new_owner_chat_id` - Unique identifier of the chat which will own the gift;
1338    ///   the chat must be active in the last 24 hours.
1339    pub fn new<A, B>(business_connection_id: A, owned_gift_id: B, new_owner_chat_id: Integer) -> Self
1340    where
1341        A: Into<String>,
1342        B: Into<String>,
1343    {
1344        Self {
1345            business_connection_id: business_connection_id.into(),
1346            owned_gift_id: owned_gift_id.into(),
1347            new_owner_chat_id,
1348            star_count: None,
1349        }
1350    }
1351
1352    /// Sets a new star count
1353    ///
1354    /// # Arguments
1355    ///
1356    /// * `value` - The amount of Telegram Stars that will be paid for the transfer from the business account balance;
1357    ///   if positive, then the can_transfer_stars business bot right is required.
1358    pub fn with_star_count(mut self, value: Integer) -> Self {
1359        self.star_count = Some(value);
1360        self
1361    }
1362}
1363
1364impl Method for TransferGift {
1365    type Response = bool;
1366
1367    fn into_payload(self) -> Payload {
1368        Payload::json("transferGift", self)
1369    }
1370}
1371
1372/// Upgrades a given regular gift to a unique gift.
1373///
1374/// Requires the can_transfer_and_upgrade_gifts business bot right.
1375/// Additionally requires the can_transfer_stars business bot right if the upgrade is paid.
1376#[serde_with::skip_serializing_none]
1377#[derive(Clone, Debug, Serialize)]
1378pub struct UpgradeGift {
1379    business_connection_id: String,
1380    owned_gift_id: String,
1381    keep_original_details: Option<bool>,
1382    star_count: Option<Integer>,
1383}
1384
1385impl UpgradeGift {
1386    /// Creates a new `UpgradeGift`.
1387    ///
1388    /// # Arguments
1389    ///
1390    /// * `business_connection_id` - Unique identifier of the business connection.
1391    /// * `owned_gift_id` - Unique identifier of the regular gift that should be upgraded to a unique one.
1392    pub fn new<A, B>(business_connection_id: A, owned_gift_id: B) -> Self
1393    where
1394        A: Into<String>,
1395        B: Into<String>,
1396    {
1397        Self {
1398            business_connection_id: business_connection_id.into(),
1399            owned_gift_id: owned_gift_id.into(),
1400            keep_original_details: None,
1401            star_count: None,
1402        }
1403    }
1404
1405    /// Sets a new value for the `keep_original_details` flag.
1406    ///
1407    /// # Arguments
1408    ///
1409    /// * `value` - Whether to keep the original gift text, sender and receiver in the upgraded gift.
1410    pub fn with_keep_original_details(mut self, value: bool) -> Self {
1411        self.keep_original_details = Some(value);
1412        self
1413    }
1414
1415    /// Sets a new star count.
1416    ///
1417    /// If `gift.prepaid_upgrade_star_count > 0`, then pass 0,
1418    /// otherwise, the `can_transfer_stars` business bot right is required and `gift.upgrade_star_count` must be passed.
1419    ///
1420    /// * `value` - The amount of Telegram Stars that will be paid for the upgrade from the business account balance.
1421    pub fn with_star_count(mut self, value: Integer) -> Self {
1422        self.star_count = Some(value);
1423        self
1424    }
1425}
1426
1427impl Method for UpgradeGift {
1428    type Response = bool;
1429
1430    fn into_payload(self) -> Payload {
1431        Payload::json("upgradeGift", self)
1432    }
1433}