Skip to main content

tgbot/types/definitions/
bot.rs

1use std::{error::Error, fmt};
2
3use serde::{Deserialize, Serialize};
4
5use crate::{
6    api::{Form, Method, Payload},
7    types::{ChatAdministratorRights, ChatId, InputProfilePhoto, InputProfilePhotoError, Integer, StarAmount, User},
8};
9
10/// Represents information about a bot returned in [`GetBot`].
11#[serde_with::skip_serializing_none]
12#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
13pub struct Bot {
14    /// The first name of the bot.
15    pub first_name: String,
16    /// The unique identifier for the bot.
17    pub id: Integer,
18    /// The username of the bot.
19    pub username: String,
20    /// Whether the bot allows users to create and delete topics in private chats.
21    pub allows_users_to_create_topics: bool,
22    /// Whether the bot can be connected to a Telegram Business account to receive its messages.
23    pub can_connect_to_business: bool,
24    /// Indicates whether the bot can be invited to groups.
25    pub can_join_groups: bool,
26    /// Whether other bots can be created to be controlled by the bot.
27    pub can_manage_bots: bool,
28    /// Indicates whether privacy mode is disabled, allowing the bot to read all group messages.
29    pub can_read_all_group_messages: bool,
30    /// Indicates whether the bot has a main Web App.
31    pub has_main_web_app: bool,
32    /// Indicates whether the bot has forum topic mode enabled in private chats.
33    pub has_topics_enabled: bool,
34    /// The last name of the bot.
35    pub last_name: Option<String>,
36    /// Indicates whether the bot supports guest queries from chats it is not a member of.
37    pub supports_guest_queries: bool,
38    /// Indicates whether the bot supports inline queries.
39    pub supports_inline_queries: bool,
40    /// Indicates whether the bot supports join request queries and can be assigned to process them.
41    pub supports_join_request_queries: bool,
42}
43
44impl Bot {
45    /// Creates a new `Bot`.
46    ///
47    /// # Arguments
48    ///
49    /// * `id` - The unique identifier for the bot.
50    /// * `username` - The username of the bot.
51    /// * `first_name` - The first name of the bot.
52    pub fn new<A, B>(id: Integer, username: A, first_name: B) -> Self
53    where
54        A: Into<String>,
55        B: Into<String>,
56    {
57        Self {
58            first_name: first_name.into(),
59            id,
60            username: username.into(),
61            allows_users_to_create_topics: false,
62            can_connect_to_business: false,
63            can_join_groups: false,
64            can_manage_bots: false,
65            can_read_all_group_messages: false,
66            has_main_web_app: false,
67            has_topics_enabled: false,
68            last_name: None,
69            supports_guest_queries: false,
70            supports_inline_queries: false,
71            supports_join_request_queries: false,
72        }
73    }
74
75    /// Sets a new value for the `allows_users_to_create_topics` flag.
76    ///
77    /// # Arguments
78    ///
79    /// * `value` - Whether the bot allows users to create and delete topics in private chats.
80    pub fn with_allows_users_to_create_topics(mut self, value: bool) -> Self {
81        self.allows_users_to_create_topics = value;
82        self
83    }
84
85    /// Sets a new value for the `can_connect_to_business` flag.
86    ///
87    /// # Arguments
88    ///
89    /// * `value` - Whether the bot can be connected to a Telegram Business account.
90    pub fn with_can_connect_to_business(mut self, value: bool) -> Self {
91        self.can_connect_to_business = value;
92        self
93    }
94
95    /// Sets a new value for the `can_join_groups` flag.
96    ///
97    /// # Arguments
98    ///
99    /// * `value` - Indicates whether the bot can be invited to groups.
100    pub fn with_can_join_groups(mut self, value: bool) -> Self {
101        self.can_join_groups = value;
102        self
103    }
104
105    /// Sets a new value for the `can_manage_bots` flag.
106    ///
107    /// # Arguments
108    ///
109    /// * `value` - Whether other bots can be created to be controlled by the bot.
110    pub fn with_can_manage_bots(mut self, value: bool) -> Self {
111        self.can_manage_bots = value;
112        self
113    }
114
115    /// Sets a new value for the `can_read_all_group_messages` flag.
116    ///
117    /// # Arguments
118    ///
119    /// * `value` - Indicates whether privacy mode is disabled.
120    pub fn with_can_read_all_group_messages(mut self, value: bool) -> Self {
121        self.can_read_all_group_messages = value;
122        self
123    }
124
125    /// Sets a new value for the `has_main_web_app` flag.
126    ///
127    /// # Arguments
128    ///
129    /// * `value` - Indicates whether the bot has a main Web App.
130    pub fn with_has_main_web_app(mut self, value: bool) -> Self {
131        self.has_main_web_app = value;
132        self
133    }
134
135    /// Sets a new value for the `has_topics_enabled` flag.
136    ///
137    /// # Arguments
138    ///
139    /// * `value` - Indicates whether the bot has forum topic mode enabled in private chats.
140    pub fn with_has_topics_enabled(mut self, value: bool) -> Self {
141        self.has_topics_enabled = value;
142        self
143    }
144
145    /// Sets a new value for the last name of the bot.
146    ///
147    /// # Arguments
148    ///
149    /// * `value` - The last name of the bot.
150    pub fn with_last_name<T>(mut self, value: T) -> Self
151    where
152        T: Into<String>,
153    {
154        self.last_name = Some(value.into());
155        self
156    }
157
158    /// Sets a new value for the `supports_guest_queries` flag.
159    ///
160    /// # Arguments
161    ///
162    /// * `value` - Indicates whether the bot supports guest queries.
163    pub fn with_supports_guest_queries(mut self, value: bool) -> Self {
164        self.supports_guest_queries = value;
165        self
166    }
167
168    /// Sets a new value for the `supports_inline_queries` flag.
169    ///
170    /// # Arguments
171    ///
172    /// * `value` - Indicates whether the bot supports inline queries.
173    pub fn with_supports_inline_queries(mut self, value: bool) -> Self {
174        self.supports_inline_queries = value;
175        self
176    }
177
178    /// Sets a new value for the `supports_join_request_queries` flag.
179    ///
180    /// # Arguments
181    ///
182    /// * `value` - Indicates whether the bot supports join request queries.
183    pub fn with_supports_join_request_queries(mut self, value: bool) -> Self {
184        self.supports_join_request_queries = value;
185        self
186    }
187}
188
189/// Represents the access settings of a bot.
190#[serde_with::skip_serializing_none]
191#[derive(Clone, Debug, Default, Deserialize, Serialize)]
192pub struct BotAccessSettings {
193    /// Whether only selected users can access the bot.
194    ///
195    /// The bot's owner can always access it.
196    pub is_access_restricted: bool,
197    /// The list of other users who have access to the bot if the access is restricted.
198    pub added_users: Option<Vec<User>>,
199}
200
201impl BotAccessSettings {
202    /// Sets a new list of added users
203    ///
204    /// # Arguments
205    ///
206    /// * `value` - The list of other users who have access to the bot.
207    pub fn with_added_users<T>(mut self, value: T) -> Self
208    where
209        T: IntoIterator<Item = User>,
210    {
211        self.added_users = Some(value.into_iter().collect());
212        self
213    }
214
215    /// Sets a new value for the `is_access_restricted_flag`.
216    ///
217    /// # Arguments
218    ///
219    /// * `value` - Whether the only selected users can access the bot.
220    pub fn with_is_access_restricted(mut self, value: bool) -> Self {
221        self.is_access_restricted = value;
222        self
223    }
224}
225
226/// Represents a command of a bot.
227#[derive(Clone, Debug, Deserialize, Serialize)]
228pub struct BotCommand {
229    #[serde(rename = "command")]
230    name: String,
231    description: String,
232}
233
234impl BotCommand {
235    const MIN_NAME_LEN: usize = 1;
236    const MAX_NAME_LEN: usize = 32;
237    const MIN_DESCRIPTION_LEN: usize = 3;
238    const MAX_DESCRIPTION_LEN: usize = 256;
239
240    /// Creates a new `BotCommand`.
241    ///
242    /// # Arguments
243    ///
244    /// * `name` - The name of the command; 1-32 characters;
245    ///   can contain only lowercase English letters, digits and underscores.
246    /// * `description` - The description of the command; 3-256 characters.
247    pub fn new<C, D>(name: C, description: D) -> Result<Self, BotCommandError>
248    where
249        C: Into<String>,
250        D: Into<String>,
251    {
252        let name = name.into();
253        let description = description.into();
254        let name_len = name.len();
255        let description_len = description.len();
256        if !(Self::MIN_NAME_LEN..=Self::MAX_NAME_LEN).contains(&name_len) {
257            Err(BotCommandError::BadNameLen(name_len))
258        } else if !(Self::MIN_DESCRIPTION_LEN..=Self::MAX_DESCRIPTION_LEN).contains(&description_len) {
259            Err(BotCommandError::BadDescriptionLen(description_len))
260        } else {
261            Ok(Self { name, description })
262        }
263    }
264
265    /// Returns the name of the command.
266    pub fn name(&self) -> &str {
267        &self.name
268    }
269
270    /// Sets a new name for the command.
271    ///
272    /// # Arguments
273    ///
274    /// * `value` - The new name.
275    pub fn with_name<T>(mut self, value: T) -> Self
276    where
277        T: Into<String>,
278    {
279        self.name = value.into();
280        self
281    }
282
283    /// Returns the description of the command.
284    pub fn description(&self) -> &str {
285        &self.description
286    }
287
288    /// Sets a new description for the command.
289    ///
290    /// # Arguments
291    ///
292    /// * `value` - The new description.
293    pub fn with_description<T>(mut self, value: T) -> Self
294    where
295        T: Into<String>,
296    {
297        self.description = value.into();
298        self
299    }
300}
301
302/// Represents an error that can occur when creating a new [`BotCommand`].
303#[derive(Debug)]
304pub enum BotCommandError {
305    /// The provided name has an invalid length.
306    BadNameLen(usize),
307    /// The provided description has an invalid length.
308    BadDescriptionLen(usize),
309}
310
311impl Error for BotCommandError {}
312
313impl fmt::Display for BotCommandError {
314    fn fmt(&self, out: &mut fmt::Formatter) -> fmt::Result {
315        use self::BotCommandError::*;
316        match self {
317            BadNameLen(len) => write!(
318                out,
319                "command name can have a length of {} up to {} characters, got {}",
320                BotCommand::MIN_NAME_LEN,
321                BotCommand::MAX_NAME_LEN,
322                len
323            ),
324            BadDescriptionLen(len) => write!(
325                out,
326                "command description can have a length of {} up to {} characters, got {}",
327                BotCommand::MIN_DESCRIPTION_LEN,
328                BotCommand::MAX_DESCRIPTION_LEN,
329                len
330            ),
331        }
332    }
333}
334
335/// Represents a scope to which bot commands are applied.
336#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
337#[serde(tag = "type")]
338#[serde(rename_all = "snake_case")]
339pub enum BotCommandScope {
340    /// All group and supergroup chat administrators.
341    AllChatAdministrators,
342    /// All group and supergroup chats.
343    AllGroupChats,
344    /// All private chats.
345    AllPrivateChats,
346    /// A specific chat.
347    Chat {
348        /// Unique identifier of the target chat.
349        chat_id: ChatId,
350    },
351    /// All administrators of a specific group or supergroup chat.
352    ChatAdministrators {
353        /// Unique identifier of the target chat.
354        chat_id: ChatId,
355    },
356    /// A specific member of a group or supergroup chat.
357    ChatMember {
358        /// Unique identifier of the target chat.
359        chat_id: ChatId,
360        /// Unique identifier of the target user.
361        user_id: Integer,
362    },
363    /// Default scope.
364    ///
365    /// Default commands are used if no commands with a narrower scope are specified for a user.
366    Default,
367}
368
369impl BotCommandScope {
370    /// Creates a new `BotCommandScope` covering a specific chat.
371    ///
372    /// # Arguments
373    ///
374    /// * `value` - Chat ID.
375    pub fn chat<T>(value: T) -> Self
376    where
377        T: Into<ChatId>,
378    {
379        Self::Chat { chat_id: value.into() }
380    }
381
382    /// Creates a new `BotCommandScope` covering all administrators
383    /// of a specific group or supergroup chat.
384    ///
385    /// # Arguments
386    ///
387    /// * `value` - Chat ID.
388    pub fn chat_administrators<T>(value: T) -> Self
389    where
390        T: Into<ChatId>,
391    {
392        Self::ChatAdministrators { chat_id: value.into() }
393    }
394
395    /// Creates a new `BotCommandScope` covering a specific member of a group or supergroup chat.
396    ///
397    /// # Arguments
398    ///
399    /// * `chat_id` - Chat ID.
400    /// * `user_id` - User ID.
401    pub fn chat_member<A>(chat_id: A, user_id: Integer) -> Self
402    where
403        A: Into<ChatId>,
404    {
405        Self::ChatMember {
406            chat_id: chat_id.into(),
407            user_id,
408        }
409    }
410}
411
412/// Represents a description of a bot.
413#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
414pub struct BotDescription {
415    /// The description of the bot.
416    pub description: String,
417}
418
419impl BotDescription {
420    /// Creates a new `BotDescription`.
421    ///
422    /// # Arguments
423    ///
424    /// * `value` - The description of the bot.
425    pub fn new<T>(value: T) -> Self
426    where
427        T: Into<String>,
428    {
429        Self {
430            description: value.into(),
431        }
432    }
433}
434
435/// Represents a name of a bot.
436#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
437pub struct BotName {
438    /// The name of the bot.
439    pub name: String,
440}
441
442impl BotName {
443    /// Creates a new `BotName`.
444    ///
445    /// # Arguments
446    ///
447    /// * `value` - The name of the bot.
448    pub fn new<T>(value: T) -> Self
449    where
450        T: Into<String>,
451    {
452        Self { name: value.into() }
453    }
454}
455
456/// Represents a short description of a bot.
457#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
458pub struct BotShortDescription {
459    /// The short description of the bot.
460    pub short_description: String,
461}
462
463impl BotShortDescription {
464    /// Creates a new `BotShortDescription`.
465    ///
466    /// # Arguments
467    ///
468    /// * `value` - The short description of the bot.
469    pub fn new<T>(value: T) -> Self
470    where
471        T: Into<String>,
472    {
473        Self {
474            short_description: value.into(),
475        }
476    }
477}
478
479/// Contains information about the creation, token update,
480/// or owner update of a bot that is managed by the current bot.
481#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
482pub struct ManagedBotUpdated {
483    /// Information about the bot.
484    pub bot: User,
485    /// User that created the bot.
486    pub user: User,
487}
488
489/// Closes a bot instance before moving it from one local server to another.
490///
491/// You need to delete the webhook before calling this method to ensure
492/// that the bot isn't launched again after server restart.
493///
494/// The method will return error 429 in the first 10 minutes after the bot is launched.
495#[derive(Clone, Copy, Debug)]
496pub struct Close;
497
498impl Method for Close {
499    type Response = bool;
500
501    fn into_payload(self) -> Payload {
502        Payload::empty("close")
503    }
504}
505
506/// Deletes a list of a bot commands of a given scope and user language.
507///
508/// After deletion, higher level commands will be shown to affected users.
509#[serde_with::skip_serializing_none]
510#[derive(Clone, Debug, Default, Serialize)]
511pub struct DeleteBotCommands {
512    language_code: Option<String>,
513    scope: Option<BotCommandScope>,
514}
515
516impl DeleteBotCommands {
517    /// Sets a new language code.
518    ///
519    /// # Arguments
520    ///
521    /// * `value` - Two-letter ISO 639-1 language code or an empty string.
522    pub fn with_language_code<T>(mut self, value: T) -> Self
523    where
524        T: Into<String>,
525    {
526        self.language_code = Some(value.into());
527        self
528    }
529
530    /// Sets a new scope of users.
531    ///
532    /// # Arguments
533    ///
534    /// * `value` - Scope; default - [`BotCommandScope::Default`].
535    pub fn with_scope(mut self, value: BotCommandScope) -> Self {
536        self.scope = Some(value);
537        self
538    }
539}
540
541impl Method for DeleteBotCommands {
542    type Response = bool;
543
544    fn into_payload(self) -> Payload {
545        Payload::json("deleteMyCommands", self)
546    }
547}
548
549/// Returns a basic information about a bot.
550#[derive(Clone, Copy, Debug)]
551pub struct GetBot;
552
553impl Method for GetBot {
554    type Response = Bot;
555
556    fn into_payload(self) -> Payload {
557        Payload::empty("getMe")
558    }
559}
560
561/// Returns the current list of bot commands.
562#[serde_with::skip_serializing_none]
563#[derive(Clone, Debug, Default, Serialize)]
564pub struct GetBotCommands {
565    language_code: Option<String>,
566    scope: Option<BotCommandScope>,
567}
568
569impl GetBotCommands {
570    /// Sets a new language code.
571    ///
572    /// # Arguments
573    ///
574    /// * `value` - Two-letter ISO 639-1 language code or an empty string.
575    pub fn with_language_code<T>(mut self, value: T) -> Self
576    where
577        T: Into<String>,
578    {
579        self.language_code = Some(value.into());
580        self
581    }
582
583    /// Sets a new scope.
584    ///
585    /// # Arguments
586    ///
587    /// * `value` - Scope of users; default - [`BotCommandScope::Default`].
588    pub fn with_scope(mut self, value: BotCommandScope) -> Self {
589        self.scope = Some(value);
590        self
591    }
592}
593
594impl Method for GetBotCommands {
595    type Response = Vec<BotCommand>;
596
597    fn into_payload(self) -> Payload {
598        Payload::json("getMyCommands", self)
599    }
600}
601
602/// Returns the current default administrator rights of a bot.
603#[serde_with::skip_serializing_none]
604#[derive(Clone, Copy, Debug, Default, Serialize)]
605pub struct GetBotDefaultAdministratorRights {
606    for_channels: Option<bool>,
607}
608
609impl GetBotDefaultAdministratorRights {
610    /// Sets a new value of a `for_channels` flag.
611    ///
612    /// # Arguments
613    ///
614    /// * `value` - For channels - `true`; for groups and supergroups - `false`.
615    pub fn with_for_channels(mut self, value: bool) -> Self {
616        self.for_channels = Some(value);
617        self
618    }
619}
620
621impl Method for GetBotDefaultAdministratorRights {
622    type Response = ChatAdministratorRights;
623
624    fn into_payload(self) -> Payload {
625        Payload::json("getMyDefaultAdministratorRights", self)
626    }
627}
628
629/// Returns the current description of a bot for a given user language.
630#[serde_with::skip_serializing_none]
631#[derive(Clone, Debug, Default, Serialize)]
632pub struct GetBotDescription {
633    language_code: Option<String>,
634}
635
636impl GetBotDescription {
637    /// Sets a new language code.
638    ///
639    /// # Arguments
640    ///
641    /// * `value` - Two-letter ISO 639-1 language code or an empty string.
642    pub fn with_language_code<T>(mut self, value: T) -> Self
643    where
644        T: Into<String>,
645    {
646        self.language_code = Some(value.into());
647        self
648    }
649}
650
651impl Method for GetBotDescription {
652    type Response = BotDescription;
653
654    fn into_payload(self) -> Payload {
655        Payload::json("getMyDescription", self)
656    }
657}
658
659/// Returns the current name of a bot for a given user language.
660#[serde_with::skip_serializing_none]
661#[derive(Clone, Debug, Default, Serialize)]
662pub struct GetBotName {
663    language_code: Option<String>,
664}
665
666impl GetBotName {
667    /// Sets a new language code.
668    ///
669    /// # Arguments
670    ///
671    /// * `value` - Two-letter ISO 639-1 language code or an empty string.
672    pub fn with_language_code<T>(mut self, value: T) -> Self
673    where
674        T: Into<String>,
675    {
676        self.language_code = Some(value.into());
677        self
678    }
679}
680
681impl Method for GetBotName {
682    type Response = BotName;
683
684    fn into_payload(self) -> Payload {
685        Payload::json("getMyName", self)
686    }
687}
688
689/// Returns the current short description of a bot for a given user language.
690#[serde_with::skip_serializing_none]
691#[derive(Clone, Debug, Default, Serialize)]
692pub struct GetBotShortDescription {
693    language_code: Option<String>,
694}
695
696impl GetBotShortDescription {
697    /// Sets a new language code.
698    ///
699    /// # Arguments
700    ///
701    /// * `value` - Two-letter ISO 639-1 language code or an empty string.
702    pub fn with_language_code<T>(mut self, value: T) -> Self
703    where
704        T: Into<String>,
705    {
706        self.language_code = Some(value.into());
707        self
708    }
709}
710
711impl Method for GetBotShortDescription {
712    type Response = BotShortDescription;
713
714    fn into_payload(self) -> Payload {
715        Payload::json("getMyShortDescription", self)
716    }
717}
718
719/// Returns the current Telegram Stars balance of the bot.
720#[derive(Clone, Copy, Debug)]
721pub struct GetBotStarBalance;
722
723impl Method for GetBotStarBalance {
724    type Response = StarAmount;
725
726    fn into_payload(self) -> Payload {
727        Payload::empty("getMyStarBalance")
728    }
729}
730
731/// Returns access settings of a managed bot.
732#[derive(Clone, Copy, Debug, Serialize)]
733pub struct GetManagedBotAccessSettings {
734    user_id: Integer,
735}
736
737impl From<Integer> for GetManagedBotAccessSettings {
738    fn from(value: Integer) -> Self {
739        Self { user_id: value }
740    }
741}
742
743impl Method for GetManagedBotAccessSettings {
744    type Response = BotAccessSettings;
745
746    fn into_payload(self) -> Payload {
747        Payload::json("getManagedBotAccessSettings", self)
748    }
749}
750
751/// Returns the token of a managed bot.
752#[derive(Clone, Copy, Debug, Serialize)]
753pub struct GetManagedBotToken {
754    user_id: Integer,
755}
756
757impl From<Integer> for GetManagedBotToken {
758    fn from(value: Integer) -> Self {
759        Self { user_id: value }
760    }
761}
762
763impl Method for GetManagedBotToken {
764    type Response = String;
765
766    fn into_payload(self) -> Payload {
767        Payload::json("getManagedBotToken", self)
768    }
769}
770
771/// Logs out from the Cloud Bot API.
772///
773/// You must log out a bot before running it locally,
774/// otherwise there is no guarantee that the bot will receive updates.
775///
776/// After a successful call, you can immediately log in on a local server,
777/// but will not be able to log in back to the Cloud Bot API server for 10 minutes.
778#[derive(Clone, Copy, Debug)]
779pub struct LogOut;
780
781impl Method for LogOut {
782    type Response = bool;
783
784    fn into_payload(self) -> Payload {
785        Payload::empty("logOut")
786    }
787}
788
789/// Revokes the current token of a managed bot and generates a new one.
790#[derive(Clone, Copy, Debug, Serialize)]
791pub struct ReplaceManagedBotToken {
792    user_id: Integer,
793}
794
795impl From<Integer> for ReplaceManagedBotToken {
796    fn from(value: Integer) -> Self {
797        Self { user_id: value }
798    }
799}
800
801impl Method for ReplaceManagedBotToken {
802    type Response = String;
803
804    fn into_payload(self) -> Payload {
805        Payload::json("replaceManagedBotToken", self)
806    }
807}
808
809/// Changes a list of commands of a bot.
810#[serde_with::skip_serializing_none]
811#[derive(Clone, Debug, Serialize)]
812pub struct SetBotCommands {
813    commands: Vec<BotCommand>,
814    language_code: Option<String>,
815    scope: Option<BotCommandScope>,
816}
817
818impl SetBotCommands {
819    /// Creates a new `SetBotCommands`.
820    ///
821    /// # Arguments
822    ///
823    /// * `commands` - Commands to set.
824    pub fn new(commands: impl IntoIterator<Item = BotCommand>) -> Self {
825        Self {
826            commands: commands.into_iter().collect(),
827            language_code: None,
828            scope: None,
829        }
830    }
831
832    /// Sets a new language code.
833    ///
834    /// # Arguments
835    ///
836    /// * `value` - Two-letter ISO 639-1 language code;
837    ///   if empty, commands will be applied to all users from the given scope,
838    ///   for whose language there are no dedicated commands.
839    pub fn with_language_code<T>(mut self, value: T) -> Self
840    where
841        T: Into<String>,
842    {
843        self.language_code = Some(value.into());
844        self
845    }
846
847    /// Sets a new scope.
848    ///
849    /// # Arguments
850    ///
851    /// * `value` - Scope of users for which the commands are relevant;
852    ///   default - [`BotCommandScope::Default`].
853    pub fn with_scope(mut self, value: BotCommandScope) -> Self {
854        self.scope = Some(value);
855        self
856    }
857}
858
859impl Method for SetBotCommands {
860    type Response = bool;
861
862    fn into_payload(self) -> Payload {
863        Payload::json("setMyCommands", self)
864    }
865}
866
867/// Changes default administrator rights requested by a bot
868/// when it's added as an administrator to groups or channels.
869///
870/// These rights will be suggested to users,
871/// but they are free to modify the list before adding the bot.
872#[serde_with::skip_serializing_none]
873#[derive(Clone, Copy, Debug, Default, Serialize)]
874pub struct SetBotDefaultAdministratorRights {
875    for_channels: Option<bool>,
876    rights: Option<ChatAdministratorRights>,
877}
878
879impl SetBotDefaultAdministratorRights {
880    /// Sets a new value of a `for_channels` flag.
881    ///
882    /// # Arguments
883    ///
884    /// * `value` - For channels - `true`; for groups and supergroups - `false`.
885    pub fn with_for_channels(mut self, value: bool) -> Self {
886        self.for_channels = Some(value);
887        self
888    }
889
890    /// Sets new default administrator rights
891    ///
892    /// # Arguments
893    ///
894    /// * `value` - Default administrator rights;
895    ///   if not specified, the default administrator rights will be cleared.
896    pub fn with_rights(mut self, value: ChatAdministratorRights) -> Self {
897        self.rights = Some(value);
898        self
899    }
900}
901
902impl Method for SetBotDefaultAdministratorRights {
903    type Response = bool;
904
905    fn into_payload(self) -> Payload {
906        Payload::json("setMyDefaultAdministratorRights", self)
907    }
908}
909
910/// Changes the description of a bot, which is shown in a chat with the bot if the chat is empty.
911#[serde_with::skip_serializing_none]
912#[derive(Clone, Debug, Default, Serialize)]
913pub struct SetBotDescription {
914    description: Option<String>,
915    language_code: Option<String>,
916}
917
918impl SetBotDescription {
919    /// Sets a new description.
920    ///
921    /// # Arguments
922    ///
923    /// * `value` - Description of the bot; 0-512 characters;
924    ///   pass an empty string to remove the dedicated description
925    ///   of the given language.
926    pub fn with_description<T>(mut self, value: T) -> Self
927    where
928        T: Into<String>,
929    {
930        self.description = Some(value.into());
931        self
932    }
933
934    /// Sets a new language code.
935    ///
936    /// # Arguments
937    ///
938    /// * `value` - Two-letter ISO 639-1 language code;
939    ///   if empty, the description will be applied to all users
940    ///   for whose language there is no dedicated description.
941    pub fn with_language_code<T>(mut self, value: T) -> Self
942    where
943        T: Into<String>,
944    {
945        self.language_code = Some(value.into());
946        self
947    }
948}
949
950impl Method for SetBotDescription {
951    type Response = bool;
952
953    fn into_payload(self) -> Payload {
954        Payload::json("setMyDescription", self)
955    }
956}
957
958/// Changes the name of a bot.
959#[serde_with::skip_serializing_none]
960#[derive(Clone, Debug, Default, Serialize)]
961pub struct SetBotName {
962    language_code: Option<String>,
963    name: Option<String>,
964}
965
966impl SetBotName {
967    /// Sets a new language code.
968    ///
969    /// # Arguments
970    ///
971    /// * `value` - Two-letter ISO 639-1 language code;
972    ///   if empty, the name will be shown to all users
973    ///   for whose language there is no dedicated name.
974    pub fn with_language_code<T>(mut self, value: T) -> Self
975    where
976        T: Into<String>,
977    {
978        self.language_code = Some(value.into());
979        self
980    }
981
982    /// Sets a new name of a bot.
983    ///
984    /// # Arguments
985    ///
986    /// * `value` - New name of the bot; 0-64 characters;
987    ///   pass an empty string to remove the dedicated name
988    ///   of the given language.
989    pub fn with_name<T>(mut self, value: T) -> Self
990    where
991        T: Into<String>,
992    {
993        self.name = Some(value.into());
994        self
995    }
996}
997
998impl Method for SetBotName {
999    type Response = bool;
1000
1001    fn into_payload(self) -> Payload {
1002        Payload::json("setMyName", self)
1003    }
1004}
1005
1006/// Changes the profile photo of the bot.
1007#[derive(Debug)]
1008pub struct SetBotProfilePhoto {
1009    form: Form,
1010}
1011
1012impl SetBotProfilePhoto {
1013    /// Creates a new `SetBotProfilePhoto`.
1014    ///
1015    /// # Arguments
1016    ///
1017    /// * `photo` - The new profile photo to set
1018    pub fn new<T>(photo: T) -> Result<Self, InputProfilePhotoError>
1019    where
1020        T: Into<InputProfilePhoto>,
1021    {
1022        let form = Form::try_from(photo.into())?;
1023        Ok(Self { form })
1024    }
1025}
1026
1027impl Method for SetBotProfilePhoto {
1028    type Response = bool;
1029
1030    fn into_payload(self) -> Payload {
1031        Payload::form("setMyProfilePhoto", self.form)
1032    }
1033}
1034
1035/// Changes the short description of a bot, which is shown on the bot profile page
1036/// and is sent together with the link when users share the bot.
1037#[serde_with::skip_serializing_none]
1038#[derive(Clone, Debug, Default, Serialize)]
1039pub struct SetBotShortDescription {
1040    language_code: Option<String>,
1041    short_description: Option<String>,
1042}
1043
1044impl SetBotShortDescription {
1045    /// Sets a new language code.
1046    ///
1047    /// # Arguments
1048    ///
1049    /// * `value` - Two-letter ISO 639-1 language code;
1050    ///   if empty, the short description will be applied
1051    ///   to all users for whose language there is no dedicated short description.
1052    pub fn with_language_code<T>(mut self, value: T) -> Self
1053    where
1054        T: Into<String>,
1055    {
1056        self.language_code = Some(value.into());
1057        self
1058    }
1059
1060    /// Sets a new short description.
1061    ///
1062    /// # Arguments
1063    ///
1064    /// * `value` - Short description of a bot; 0-120 characters;
1065    ///   pass an empty string to remove the dedicated short description
1066    ///   of the given language.
1067    pub fn with_short_description<T>(mut self, value: T) -> Self
1068    where
1069        T: Into<String>,
1070    {
1071        self.short_description = Some(value.into());
1072        self
1073    }
1074}
1075
1076impl Method for SetBotShortDescription {
1077    type Response = bool;
1078
1079    fn into_payload(self) -> Payload {
1080        Payload::json("setMyShortDescription", self)
1081    }
1082}
1083
1084/// Changes the access settings of a managed bot.
1085#[serde_with::skip_serializing_none]
1086#[derive(Clone, Debug, Serialize)]
1087pub struct SetManagedBotAccessSettings {
1088    user_id: Integer,
1089    is_access_restricted: bool,
1090    added_user_ids: Option<Vec<Integer>>,
1091}
1092
1093impl SetManagedBotAccessSettings {
1094    /// Creates a new `SetManagedBotAccessSettings`.
1095    ///
1096    /// # Arguments
1097    ///
1098    /// * `user_id` - User identifier of the managed bot whose access settings will ne changed.
1099    /// * `is_access_restricted` - Whether only selected users can access the bot;
1100    ///   the bot's owner can always access it.
1101    pub fn new(user_id: Integer, is_access_restricted: bool) -> Self {
1102        Self {
1103            user_id,
1104            is_access_restricted,
1105            added_user_ids: None,
1106        }
1107    }
1108
1109    /// Sets a new list of added user IDs.
1110    ///
1111    /// # Arguments
1112    ///
1113    /// * `value` - A list of up to 10 identifiers of users who will have access to the bot in addition to its owner.
1114    ///
1115    /// Ignored if `is_access_restricted` is false.
1116    pub fn with_added_user_ids<T>(mut self, value: T) -> Self
1117    where
1118        T: IntoIterator<Item = Integer>,
1119    {
1120        self.added_user_ids = Some(value.into_iter().collect());
1121        self
1122    }
1123}
1124
1125impl Method for SetManagedBotAccessSettings {
1126    type Response = bool;
1127
1128    fn into_payload(self) -> Payload {
1129        Payload::json("setManagedBotAccessSettings", self)
1130    }
1131}
1132
1133/// Removes the profile photo of the bot.
1134#[derive(Clone, Copy, Debug, Serialize)]
1135pub struct RemoveBotProfilePhoto;
1136
1137impl Method for RemoveBotProfilePhoto {
1138    type Response = bool;
1139
1140    fn into_payload(self) -> Payload {
1141        Payload::empty("removeMyProfilePhoto")
1142    }
1143}