pub struct User {
pub id: UserId,
pub is_bot: bool,
pub first_name: String,
pub last_name: Option<String>,
pub username: Option<String>,
pub language_code: Option<String>,
pub is_premium: bool,
pub added_to_attachment_menu: bool,
}Expand description
This object represents a Telegram user or bot.
Fields§
§id: UserIdUnique identifier for this user or bot.
is_bot: booltrue, if this user is a bot.
first_name: StringUser‘s or bot’s first name.
last_name: Option<String>User‘s or bot’s last name.
username: Option<String>User‘s or bot’s username.
language_code: Option<String>IETF language tag of the user’s language.
true, if this user is a Telegram Premium user.
true, if this user added the bot to the attachment menu.
Implementations§
Source§impl User
impl User
Sourcepub fn full_name(&self) -> String
pub fn full_name(&self) -> String
Returns full name of this user, ie first and last names joined with a space.
Examples found in repository?
51async fn new_chat_member(bot: Bot, chat_member: ChatMemberUpdated) -> ResponseResult<()> {
52 let user = chat_member.old_chat_member.user.clone();
53
54 let telegram_group_name = chat_member.chat.title().unwrap_or("");
55
56 // We get a "@username" mention via `mention()` method if the user has a
57 // username, otherwise we create a textual mention with "Full Name" as the
58 // text linking to the user
59 let username =
60 user.mention().unwrap_or_else(|| html::user_mention(user.id, user.full_name().as_str()));
61
62 bot.send_message(format!("Welcome to {telegram_group_name} {username}!"))
63 .chat_id(chat_member.chat.id)
64 .await?;
65
66 Ok(())
67}
68
69async fn left_chat_member(bot: Bot, chat_member: ChatMemberUpdated) -> ResponseResult<()> {
70 let user = chat_member.old_chat_member.user;
71
72 let username =
73 user.mention().unwrap_or_else(|| html::user_mention(user.id, user.full_name().as_str()));
74
75 bot.send_message(format!("Goodbye {username}!")).chat_id(chat_member.chat.id).await?;
76
77 Ok(())
78}Sourcepub fn mention(&self) -> Option<String>
pub fn mention(&self) -> Option<String>
Returns a username mention of this user. Returns None if
self.username.is_none().
Examples found in repository?
51async fn new_chat_member(bot: Bot, chat_member: ChatMemberUpdated) -> ResponseResult<()> {
52 let user = chat_member.old_chat_member.user.clone();
53
54 let telegram_group_name = chat_member.chat.title().unwrap_or("");
55
56 // We get a "@username" mention via `mention()` method if the user has a
57 // username, otherwise we create a textual mention with "Full Name" as the
58 // text linking to the user
59 let username =
60 user.mention().unwrap_or_else(|| html::user_mention(user.id, user.full_name().as_str()));
61
62 bot.send_message(format!("Welcome to {telegram_group_name} {username}!"))
63 .chat_id(chat_member.chat.id)
64 .await?;
65
66 Ok(())
67}
68
69async fn left_chat_member(bot: Bot, chat_member: ChatMemberUpdated) -> ResponseResult<()> {
70 let user = chat_member.old_chat_member.user;
71
72 let username =
73 user.mention().unwrap_or_else(|| html::user_mention(user.id, user.full_name().as_str()));
74
75 bot.send_message(format!("Goodbye {username}!")).chat_id(chat_member.chat.id).await?;
76
77 Ok(())
78}Sourcepub fn url(&self) -> Url
pub fn url(&self) -> Url
Returns an URL that links to this user in the form of
tg://user/?id=<...>.
Sourcepub fn tme_url(&self) -> Option<Url>
pub fn tme_url(&self) -> Option<Url>
Returns an URL that links to this user in the form of t.me/<...>.
Returns None if self.username.is_none().
Sourcepub fn preferably_tme_url(&self) -> Url
pub fn preferably_tme_url(&self) -> Url
Returns an URL that links to this user in the form of t.me/<...> or
tg://user/?id=<...>, preferring t.me one when possible.
Sourcepub fn is_anonymous(&self) -> bool
pub fn is_anonymous(&self) -> bool
Returns true if this is the special user used by telegram bot API to
denote an anonymous user that sends messages on behalf of a group.
Sourcepub fn is_channel(&self) -> bool
pub fn is_channel(&self) -> bool
Returns true if this is the special user used by telegram bot API to
denote an anonymous user that sends messages on behalf of a channel.
Sourcepub fn is_telegram(&self) -> bool
pub fn is_telegram(&self) -> bool
Returns true if this is the special user used by telegram itself.
It is sometimes also used as a fallback, for example when a channel post
is automatically forwarded to a group, bots in a group will get a
message where from is the Telegram user.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for User
impl<'de> Deserialize<'de> for User
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<User, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<User, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for User
Source§impl Serialize for User
impl Serialize for User
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for User
Auto Trait Implementations§
impl Forget for User
impl Freeze for User
impl Move for User
impl RefUnwindSafe for User
impl Send for Userwhere
RawVecInner: Send,
impl Sync for Userwhere
RawVecInner: Sync,
impl Unpin for User
impl UnsafeUnpin for User
impl UnwindSafe for Userwhere
RawVecInner: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Erasable for T
impl<T> Erasable for T
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more