Skip to main content

Me

Struct Me 

Source
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: bool

true, if the bot can be invited to groups.

§can_read_all_group_messages: bool

true, if privacy mode is disabled for the bot.

§supports_inline_queries: bool

true, if the bot supports inline queries.

§can_connect_to_business: bool

true, if the bot can be connected to a Telegram Business account to receive its messages.

§has_main_web_app: bool

true, if the bot has a main Web App.

Implementations§

Source§

impl Me

Source

pub fn username(&self) -> &str

Returns the username of the bot.

Examples found in repository?
examples/buttons.rs (line 69)
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}
Source

pub fn mention(&self) -> String

Returns a username mention of this bot.

Source

pub fn tme_url(&self) -> Url

Returns an URL that links to this bot in the form of t.me/<...>.

Examples found in repository?
examples/deep_linking.rs (line 78)
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>§

Source

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?
examples/chat_member_updates.rs (line 60)
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}
Source

pub fn mention(&self) -> Option<String>

Returns a username mention of this user. Returns None if self.username.is_none().

Examples found in repository?
examples/chat_member_updates.rs (line 60)
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}
Source

pub fn url(&self) -> Url

Returns an URL that links to this user in the form of tg://user/?id=<...>.

Source

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().

Source

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.

Source

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.

Source

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.

Source

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 Clone for Me

Source§

fn clone(&self) -> Me

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Me

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Deref for Me

Source§

type Target = User

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<Me as Deref>::Target

Dereferences the value.
Source§

impl<'de> Deserialize<'de> for Me

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Me, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Hash for Me

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Me

Source§

fn eq(&self, other: &Me) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Me

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Me

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> Erasable for T

Source§

const ACK_1_1_0: bool = true

Available on non-enforce_1_1_0_semantics only.
Whether this implementor has acknowledged the 1.1.0 update to unerase’s documented implementation requirements. Read more
Source§

unsafe fn unerase(this: NonNull<Erased>) -> NonNull<T>

Unerase this erased pointer. Read more
Source§

fn erase(this: NonNull<Self>) -> NonNull<Erased>

Turn this erasable pointer into an erased pointer. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,