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