pub struct BotFullInfo {Show 18 fields
pub id: UserId,
pub is_bot: True,
pub first_name: String,
pub username: Option<String>,
pub active_usernames: Option<Vec<String>>,
pub can_join_groups: bool,
pub can_read_all_group_messages: bool,
pub supports_guest_queries: bool,
pub supports_inline_queries: bool,
pub inline_query_placeholder: Option<String>,
pub needs_inline_query_location: bool,
pub can_connect_to_business: bool,
pub has_main_web_app: bool,
pub has_topics_enabled: bool,
pub allows_users_to_create_topics: bool,
pub has_topic_sidebar: bool,
pub can_manage_bots: bool,
pub supports_join_request_queries: bool,
}Expand description
Full information about the bot itself, returned by
GetMe.
Settings absent in older Bot API responses are treated as disabled.
Fields§
§id: UserIdUnique identifier of the bot.
is_bot: TrueAlways true.
first_name: StringFirst name of the bot.
username: Option<String>Primary username of the bot, if assigned.
active_usernames: Option<Vec<String>>All active usernames of the bot, if nonempty.
can_join_groups: boolWhether the bot can be added to groups.
can_read_all_group_messages: boolWhether privacy mode is disabled for the bot.
supports_guest_queries: boolWhether the bot supports guest queries from chats it is not a member of.
supports_inline_queries: boolWhether the bot supports inline queries.
inline_query_placeholder: Option<String>Placeholder shown in the input field after the bot’s username in inline mode, if not using the default.
needs_inline_query_location: boolWhether the bot requests the user’s location with every inline query.
can_connect_to_business: boolWhether the bot can be connected to a user account to manage it.
has_main_web_app: boolWhether the bot has a main Web App.
has_topics_enabled: boolWhether forum topic mode is enabled in private chats with the bot.
allows_users_to_create_topics: boolWhether users can create and delete topics in private chats with the bot.
Whether topics are shown in a sidebar in private chats with the bot.
can_manage_bots: boolWhether the bot can create and control other bots.
supports_join_request_queries: boolWhether the bot can be assigned to process join request queries.
Implementations§
Source§impl BotFullInfo
impl BotFullInfo
Sourcepub fn username(&self) -> Option<&str>
pub fn username(&self) -> Option<&str>
Returns the primary username, or the first active username if there is no primary one.
Examples found in repository?
63async fn message_handler(
64 bot: Bot,
65 msg: Message,
66 me: BotFullInfo,
67) -> Result<(), Box<dyn Error + Send + Sync>> {
68 if let Some(text) = msg.text() {
69 match BotCommands::parse(text, me.username().unwrap_or_default()) {
70 Ok(Command::Help) => {
71 // Just send the description of all commands.
72 bot.send_message(Command::descriptions().to_string()).chat_id(msg.chat.id).await?;
73 }
74 Ok(Command::Start) => {
75 // Create a list of buttons and send them.
76 let keyboard = make_keyboard();
77 bot.send_message("Debian versions:")
78 .chat_id(msg.chat.id)
79 .reply_markup(keyboard)
80 .await?;
81 }
82
83 Err(_) => {
84 bot.send_message("Command not found!").chat_id(msg.chat.id).await?;
85 }
86 }
87 }
88
89 Ok(())
90}Sourcepub fn mention(&self) -> Option<String>
pub fn mention(&self) -> Option<String>
Returns a username mention of this bot, if it has a username.
Sourcepub fn tme_url(&self) -> Option<Url>
pub fn tme_url(&self) -> Option<Url>
Returns a t.me link to this bot, if it has a username.
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: BotFullInfo,
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(format!(
75 "Hello!\n\nThis link allows anyone to message you secretly: {}?start={}",
76 me.tme_url().ok_or("The bot needs a public username for deep links")?,
77 msg.chat.id
78 ))
79 .chat_id(msg.chat.id)
80 .await?;
81 dialogue.exit().await?;
82 } else {
83 // And this means that the link is like this: https://t.me/some_bot?start=123456789,
84 // or a /start 123456789 command
85 match start.parse::<i64>() {
86 Ok(id) => {
87 bot.send_message("Send your message:").chat_id(msg.chat.id).await?;
88 dialogue.update(State::WriteToSomeone { id: ChatId(id) }).await?;
89 }
90 Err(_) => {
91 bot.send_message("Bad link!").chat_id(msg.chat.id).await?;
92 dialogue.exit().await?;
93 }
94 }
95 }
96 Ok(())
97}
98
99pub async fn send_message(
100 bot: Bot,
101 id: ChatId, // Available from `State::WriteToSomeone`
102 msg: Message,
103 dialogue: MyDialogue,
104 me: BotFullInfo,
105) -> HandlerResult {
106 match msg.text() {
107 Some(text) => {
108 // Trying to send a message to the user
109 let sent_result = bot
110 .send_message(format!("You have a new message!\n\n<i>{text}</i>"))
111 .chat_id(id)
112 .parse_mode(ParseMode::Html)
113 .await;
114
115 // And if no error is returned, success!
116 if sent_result.is_ok() {
117 bot.send_message(format!(
118 "Message sent!\n\nYour link is: {}?start={}",
119 me.tme_url().ok_or("The bot needs a public username for deep links")?,
120 msg.chat.id
121 ))
122 .chat_id(msg.chat.id)
123 .await?;
124 } else {
125 bot.send_message("Error sending message! Maybe user blocked the bot?")
126 .chat_id(msg.chat.id)
127 .await?;
128 }
129 dialogue.exit().await?;
130 }
131 None => {
132 bot.send_message("This bot can send only text.").chat_id(msg.chat.id).await?;
133 }
134 };
135 Ok(())
136}Trait Implementations§
Source§impl Clone for BotFullInfo
impl Clone for BotFullInfo
Source§fn clone(&self) -> BotFullInfo
fn clone(&self) -> BotFullInfo
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BotFullInfo
impl Debug for BotFullInfo
Source§impl<'de> Deserialize<'de> for BotFullInfo
impl<'de> Deserialize<'de> for BotFullInfo
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<BotFullInfo, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<BotFullInfo, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for BotFullInfo
Source§impl Hash for BotFullInfo
impl Hash for BotFullInfo
Source§impl PartialEq for BotFullInfo
impl PartialEq for BotFullInfo
Source§impl Serialize for BotFullInfo
impl Serialize for BotFullInfo
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 BotFullInfo
Auto Trait Implementations§
impl Forget for BotFullInfo
impl Freeze for BotFullInfo
impl Move for BotFullInfo
impl RefUnwindSafe for BotFullInfo
impl Send for BotFullInfowhere
RawVecInner: Send,
impl Sync for BotFullInfowhere
RawVecInner: Sync,
impl Unpin for BotFullInfo
impl UnsafeUnpin for BotFullInfowhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<String>: UnsafeUnpin,
impl UnwindSafe for BotFullInfowhere
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