pub struct Me {
pub user: User,
pub can_join_groups: bool,
pub can_read_all_group_messages: bool,
pub supports_inline_queries: bool,
pub can_connect_to_business: bool,
pub has_main_web_app: bool,
}Expand description
Returned only in GetMe.
Fields§
§user: User§can_join_groups: booltrue, if the bot can be invited to groups.
can_read_all_group_messages: booltrue, if privacy mode is disabled for the bot.
supports_inline_queries: booltrue, if the bot supports inline queries.
can_connect_to_business: booltrue, if the bot can be connected to a Telegram Business account to
receive its messages.
has_main_web_app: booltrue, if the bot has a main Web App.
Implementations§
Source§impl Me
impl Me
Sourcepub fn username(&self) -> &str
pub fn username(&self) -> &str
Returns the username of the bot.
Examples found in repository?
63async fn message_handler(
64 bot: Bot,
65 msg: Message,
66 me: Me,
67) -> Result<(), Box<dyn Error + Send + Sync>> {
68 if let Some(text) = msg.text() {
69 match BotCommands::parse(text, me.username()) {
70 Ok(Command::Help) => {
71 // Just send the description of all commands.
72 bot.send_message(msg.chat.id, Command::descriptions().to_string()).await?;
73 }
74 Ok(Command::Start) => {
75 // Create a list of buttons and send them.
76 let keyboard = make_keyboard();
77 bot.send_message(msg.chat.id, "Debian versions:").reply_markup(keyboard).await?;
78 }
79
80 Err(_) => {
81 bot.send_message(msg.chat.id, "Command not found!").await?;
82 }
83 }
84 }
85
86 Ok(())
87}Sourcepub fn tme_url(&self) -> Url
pub fn tme_url(&self) -> Url
Returns an URL that links to this bot in the form of t.me/<...>.
Examples found in repository?
65pub async fn start(
66 bot: Bot,
67 dialogue: MyDialogue,
68 msg: Message,
69 start: String, // Available from `case![StartCommand::Start(start)]`
70 me: Me,
71) -> HandlerResult {
72 if start.is_empty() {
73 // This means that it is just a regular link like https://t.me/some_bot, or a /start command
74 bot.send_message(
75 msg.chat.id,
76 format!(
77 "Hello!\n\nThis link allows anyone to message you secretly: {}?start={}",
78 me.tme_url(),
79 msg.chat.id
80 ),
81 )
82 .await?;
83 dialogue.exit().await?;
84 } else {
85 // And this means that the link is like this: https://t.me/some_bot?start=123456789,
86 // or a /start 123456789 command
87 match start.parse::<i64>() {
88 Ok(id) => {
89 bot.send_message(msg.chat.id, "Send your message:").await?;
90 dialogue.update(State::WriteToSomeone { id: ChatId(id) }).await?;
91 }
92 Err(_) => {
93 bot.send_message(msg.chat.id, "Bad link!").await?;
94 dialogue.exit().await?;
95 }
96 }
97 }
98 Ok(())
99}
100
101pub async fn send_message(
102 bot: Bot,
103 id: ChatId, // Available from `State::WriteToSomeone`
104 msg: Message,
105 dialogue: MyDialogue,
106 me: Me,
107) -> HandlerResult {
108 match msg.text() {
109 Some(text) => {
110 // Trying to send a message to the user
111 let sent_result = bot
112 .send_message(id, format!("You have a new message!\n\n<i>{text}</i>"))
113 .parse_mode(ParseMode::Html)
114 .await;
115
116 // And if no error is returned, success!
117 if sent_result.is_ok() {
118 bot.send_message(
119 msg.chat.id,
120 format!(
121 "Message sent!\n\nYour link is: {}?start={}",
122 me.tme_url(),
123 msg.chat.id
124 ),
125 )
126 .await?;
127 } else {
128 bot.send_message(msg.chat.id, "Error sending message! Maybe user blocked the bot?")
129 .await?;
130 }
131 dialogue.exit().await?;
132 }
133 None => {
134 bot.send_message(msg.chat.id, "This bot can send only text.").await?;
135 }
136 };
137 Ok(())
138}Methods from Deref<Target = 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(chat_member.chat.id, format!("Welcome to {telegram_group_name} {username}!"))
63 .await?;
64
65 Ok(())
66}
67
68async fn left_chat_member(bot: Bot, chat_member: ChatMemberUpdated) -> ResponseResult<()> {
69 let user = chat_member.old_chat_member.user;
70
71 let username =
72 user.mention().unwrap_or_else(|| html::user_mention(user.id, user.full_name().as_str()));
73
74 bot.send_message(chat_member.chat.id, format!("Goodbye {username}!")).await?;
75
76 Ok(())
77}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(chat_member.chat.id, format!("Welcome to {telegram_group_name} {username}!"))
63 .await?;
64
65 Ok(())
66}
67
68async fn left_chat_member(bot: Bot, chat_member: ChatMemberUpdated) -> ResponseResult<()> {
69 let user = chat_member.old_chat_member.user;
70
71 let username =
72 user.mention().unwrap_or_else(|| html::user_mention(user.id, user.full_name().as_str()));
73
74 bot.send_message(chat_member.chat.id, format!("Goodbye {username}!")).await?;
75
76 Ok(())
77}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 Me
impl<'de> Deserialize<'de> for Me
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Me, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Me, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for Me
impl Serialize for Me
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 Eq for Me
impl StructuralPartialEq for Me
Auto Trait Implementations§
impl Freeze for Me
impl RefUnwindSafe for Me
impl Send for Me
impl Sync for Me
impl Unpin for Me
impl UnwindSafe for Me
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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<T> Erasable for T
impl<T> Erasable for T
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