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