rustigram_types/user.rs
1use serde::{Deserialize, Serialize};
2
3/// Represents a Telegram user or bot.
4#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5pub struct User {
6 /// Unique identifier for this user or bot.
7 pub id: i64,
8
9 /// `true` if this user is a bot.
10 pub is_bot: bool,
11
12 /// User's or bot's first name.
13 pub first_name: String,
14
15 /// User's or bot's last name.
16 #[serde(skip_serializing_if = "Option::is_none")]
17 pub last_name: Option<String>,
18
19 /// User's or bot's username.
20 #[serde(skip_serializing_if = "Option::is_none")]
21 pub username: Option<String>,
22
23 /// IETF language tag of the user's language.
24 #[serde(skip_serializing_if = "Option::is_none")]
25 pub language_code: Option<String>,
26
27 /// `true` if this user is a Telegram Premium user.
28 #[serde(skip_serializing_if = "Option::is_none")]
29 pub is_premium: Option<bool>,
30
31 /// `true` if this user added the bot to the attachment menu.
32 #[serde(skip_serializing_if = "Option::is_none")]
33 pub added_to_attachment_menu: Option<bool>,
34
35 /// Bots only — `true` if the bot can be invited to groups.
36 #[serde(skip_serializing_if = "Option::is_none")]
37 pub can_join_groups: Option<bool>,
38
39 /// Bots only — `true` if privacy mode is disabled for the bot.
40 #[serde(skip_serializing_if = "Option::is_none")]
41 pub can_read_all_group_messages: Option<bool>,
42
43 /// Bots only — `true` if the bot supports inline queries.
44 #[serde(skip_serializing_if = "Option::is_none")]
45 pub supports_inline_queries: Option<bool>,
46
47 /// Bots only — `true` if the bot can be connected to a Telegram Business account.
48 #[serde(skip_serializing_if = "Option::is_none")]
49 pub can_connect_to_business: Option<bool>,
50
51 /// Bots only — `true` if the bot has a main Web App.
52 #[serde(skip_serializing_if = "Option::is_none")]
53 pub has_main_web_app: Option<bool>,
54
55 /// Bots only — `true` if the bot has forum topic mode enabled in private chats.
56 #[serde(skip_serializing_if = "Option::is_none")]
57 pub has_topics_enabled: Option<bool>,
58
59 /// Bots only — `true` if the bot allows users to create and delete topics in private chats.
60 #[serde(skip_serializing_if = "Option::is_none")]
61 pub allows_users_to_create_topics: Option<bool>,
62
63 /// Bots only — `true` if other bots can be created to be controlled by this bot.
64 #[serde(skip_serializing_if = "Option::is_none")]
65 pub can_manage_bots: Option<bool>,
66}
67
68impl User {
69 /// Returns a human-readable display name, preferring `first_name + last_name`.
70 #[must_use]
71 pub fn full_name(&self) -> String {
72 match &self.last_name {
73 Some(last) => format!("{} {}", self.first_name, last),
74 None => self.first_name.clone(),
75 }
76 }
77
78 /// Returns a `@username` mention string if available.
79 #[must_use]
80 pub fn mention(&self) -> Option<String> {
81 self.username.as_ref().map(|u| format!("@{u}"))
82 }
83}
84
85/// Container for a user's profile photos.
86#[derive(Debug, Clone, Serialize, Deserialize)]
87pub struct UserProfilePhotos {
88 /// Total number of profile pictures the target user has.
89 pub total_count: u32,
90
91 /// Requested profile pictures (in up to 4 sizes each).
92 pub photos: Vec<Vec<crate::file::PhotoSize>>,
93}
94
95/// Container for a user's profile audios.
96#[derive(Debug, Clone, Serialize, Deserialize)]
97pub struct UserProfileAudios {
98 /// Total number of profile audios.
99 pub total_count: u32,
100
101 /// Requested profile audios.
102 pub audios: Vec<crate::file::Audio>,
103}
104
105/// Bot command scope — defines where a specific list of commands applies.
106#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
107#[serde(tag = "type", rename_all = "snake_case")]
108pub enum BotCommandScope {
109 /// Default scope — used when no more specific scope is applicable.
110 Default,
111 /// Covers all private chats.
112 AllPrivateChats,
113 /// Covers all group and supergroup chats.
114 AllGroupChats,
115 /// Covers all group and supergroup chat administrators.
116 AllChatAdministrators,
117 /// Covers a specific chat.
118 Chat {
119 /// Unique identifier or username of the target chat.
120 chat_id: ChatId,
121 },
122 /// Covers all administrators of a specific group or supergroup.
123 ChatAdministrators {
124 /// Unique identifier or username of the target chat.
125 chat_id: ChatId,
126 },
127 /// Covers a specific member of a group or supergroup.
128 ChatMember {
129 /// Unique identifier or username of the target chat.
130 chat_id: ChatId,
131 /// Unique identifier of the target user.
132 user_id: i64,
133 },
134}
135
136/// Represents a bot command.
137#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
138pub struct BotCommand {
139 /// Text of the command (1–32 characters, lowercase, alphanumeric + underscore).
140 pub command: String,
141 /// Description of the command (3–256 characters).
142 pub description: String,
143}
144
145/// Flexible chat identifier — either a numeric ID or a `@username`.
146#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
147#[serde(untagged)]
148pub enum ChatId {
149 /// Numeric chat ID (can be negative for groups/channels).
150 Id(i64),
151 /// Chat `@username`.
152 Username(String),
153}
154
155impl From<i64> for ChatId {
156 fn from(id: i64) -> Self {
157 Self::Id(id)
158 }
159}
160
161impl From<&str> for ChatId {
162 fn from(username: &str) -> Self {
163 Self::Username(username.to_owned())
164 }
165}
166
167impl From<String> for ChatId {
168 fn from(username: String) -> Self {
169 Self::Username(username)
170 }
171}
172
173impl std::fmt::Display for ChatId {
174 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
175 match self {
176 Self::Id(id) => write!(f, "{id}"),
177 Self::Username(u) => write!(f, "{u}"),
178 }
179 }
180}
181
182/// The bot's display name.
183///
184/// Returned by [`getMyName`](https://core.telegram.org/bots/api#getmyname).
185#[derive(Debug, Clone, Serialize, Deserialize)]
186pub struct BotName {
187 /// The bot's name.
188 pub name: String,
189}
190
191/// The bot's description shown in the chat when the chat is empty.
192///
193/// Returned by [`getMyDescription`](https://core.telegram.org/bots/api#getmydescription).
194#[derive(Debug, Clone, Serialize, Deserialize)]
195pub struct BotDescription {
196 /// The bot's description.
197 pub description: String,
198}
199
200/// The bot's short description shown on the profile page and in sharing links.
201///
202/// Returned by [`getMyShortDescription`](https://core.telegram.org/bots/api#getmyshortdescription).
203#[derive(Debug, Clone, Serialize, Deserialize)]
204pub struct BotShortDescription {
205 /// The bot's short description.
206 pub short_description: String,
207}
208
209/// Represents the rights of an administrator in a chat.
210///
211/// Used by [`setMyDefaultAdministratorRights`](https://core.telegram.org/bots/api#setmydefaultadministratorrights)
212/// and [`getMyDefaultAdministratorRights`](https://core.telegram.org/bots/api#getmydefaultadministratorrights).
213#[derive(Debug, Clone, Default, Serialize, Deserialize)]
214pub struct ChatAdministratorRights {
215 /// `true` if the user's presence in the chat is hidden.
216 pub is_anonymous: bool,
217 /// `true` if the administrator can access the chat event log, boost list, etc.
218 pub can_manage_chat: bool,
219 /// `true` if the administrator can delete messages of other users.
220 pub can_delete_messages: bool,
221 /// `true` if the administrator can manage video chats.
222 pub can_manage_video_chats: bool,
223 /// `true` if the administrator can restrict, ban, or unban chat members.
224 pub can_restrict_members: bool,
225 /// `true` if the administrator can promote members to administrators.
226 pub can_promote_members: bool,
227 /// `true` if the user is allowed to change the chat title, photo, and other settings.
228 pub can_change_info: bool,
229 /// `true` if the user is allowed to invite new users to the chat.
230 pub can_invite_users: bool,
231 /// `true` if the administrator can post stories to the chat.
232 pub can_post_stories: bool,
233 /// `true` if the administrator can edit stories posted by other users.
234 pub can_edit_stories: bool,
235 /// `true` if the administrator can delete stories posted by other users.
236 pub can_delete_stories: bool,
237 /// `true` if the administrator can post messages in the channel; channels only.
238 #[serde(skip_serializing_if = "Option::is_none")]
239 pub can_post_messages: Option<bool>,
240 /// `true` if the administrator can edit messages of other users and pin messages; channels only.
241 #[serde(skip_serializing_if = "Option::is_none")]
242 pub can_edit_messages: Option<bool>,
243 /// `true` if the user is allowed to pin messages; groups and supergroups only.
244 #[serde(skip_serializing_if = "Option::is_none")]
245 pub can_pin_messages: Option<bool>,
246 /// `true` if the user is allowed to create, rename, close, and reopen forum topics; supergroups only.
247 #[serde(skip_serializing_if = "Option::is_none")]
248 pub can_manage_topics: Option<bool>,
249 /// `true` if the administrator can manage direct messages and decline suggested posts; channels only.
250 #[serde(skip_serializing_if = "Option::is_none")]
251 pub can_manage_direct_messages: Option<bool>,
252 /// `true` if the administrator can edit the tags of regular members; groups and supergroups only.
253 #[serde(skip_serializing_if = "Option::is_none")]
254 pub can_manage_tags: Option<bool>,
255}