Struct grammers_client::types::message::Message
source · pub struct Message { /* private fields */ }
Expand description
Represents a Telegram message, which includes text messages, messages with media, and service messages.
This message should be treated as a snapshot in time, that is, if the message is edited while using this object, those changes won’t alter this structure.
Implementations§
source§impl Message
impl Message
sourcepub fn outgoing(&self) -> bool
pub fn outgoing(&self) -> bool
Whether the message is outgoing (i.e. you sent this message to some other chat) or incoming (i.e. someone else sent it to you or the chat).
sourcepub fn mentioned(&self) -> bool
pub fn mentioned(&self) -> bool
Whether you were mentioned in this message or not.
This includes @username mentions, text mentions, and messages replying to one of your previous messages (even if it contains no mention in the message text).
sourcepub fn media_unread(&self) -> bool
pub fn media_unread(&self) -> bool
Whether you have read the media in this message or not.
Most commonly, these are voice notes that you have not played yet.
sourcepub fn from_scheduled(&self) -> bool
pub fn from_scheduled(&self) -> bool
Whether this message was originated from a previously-scheduled message or not.
sourcepub fn edit_hide(&self) -> bool
pub fn edit_hide(&self) -> bool
Whether the edited mark of this message is edited should be hidden (e.g. in GUI clients) or shown.
sourcepub fn id(&self) -> i32
pub fn id(&self) -> i32
The ID of this message.
Message identifiers are counters that start at 1 and grow by 1 for each message produced.
Every channel has its own unique message counter. This counter is the same for all users, but unique to each channel.
Every account has another unique message counter which is used for private conversations and small group chats. This means different accounts will likely have different message identifiers for the same message in a private conversation or small group chat. This also implies that the message identifier alone is enough to uniquely identify the message, without the need to know the chat ID.
You cannot use the message ID of User A when running as User B, unless this message
belongs to a megagroup or broadcast channel. Beware of this when using methods like
Client::delete_messages
, which cannot validate the chat where the message
should be deleted for those cases.
sourcepub fn chat(&self) -> Chat
pub fn chat(&self) -> Chat
The chat where this message was sent to.
This might be the user you’re talking to for private conversations, or the group or channel where the message was sent.
sourcepub fn forward_header(&self) -> Option<MessageFwdHeader>
pub fn forward_header(&self) -> Option<MessageFwdHeader>
If this message was forwarded from a previous message, return the header with information about that forward.
sourcepub fn via_bot_id(&self) -> Option<i64>
pub fn via_bot_id(&self) -> Option<i64>
If this message was sent @via some inline bot, return the bot’s user identifier.
sourcepub fn reply_header(&self) -> Option<MessageReplyHeader>
pub fn reply_header(&self) -> Option<MessageReplyHeader>
If this message is replying to a previous message, return the header with information about that reply.
sourcepub fn text(&self) -> &str
pub fn text(&self) -> &str
The message’s text.
For service messages, this will be the empty strings.
If the message has media, this text is the caption commonly displayed underneath it.
sourcepub fn media(&self) -> Option<Media>
pub fn media(&self) -> Option<Media>
The media displayed by this message, if any.
This not only includes photos or videos, but also contacts, polls, documents, locations and many other types.
sourcepub fn reply_markup(&self) -> Option<ReplyMarkup>
pub fn reply_markup(&self) -> Option<ReplyMarkup>
If the message has a reply markup (which can happen for messages produced by bots), returns said markup.
sourcepub fn fmt_entities(&self) -> Option<&Vec<MessageEntity>>
pub fn fmt_entities(&self) -> Option<&Vec<MessageEntity>>
The formatting entities used to format this message, such as bold, italic, with their offsets and lengths.
sourcepub fn view_count(&self) -> Option<i32>
pub fn view_count(&self) -> Option<i32>
How many views does this message have, when applicable.
The same user account can contribute to increment this counter indefinitedly, however there is a server-side cooldown limitting how fast it can happen (several hours).
sourcepub fn forward_count(&self) -> Option<i32>
pub fn forward_count(&self) -> Option<i32>
How many times has this message been forwarded, when applicable.
sourcepub fn reply_count(&self) -> Option<i32>
pub fn reply_count(&self) -> Option<i32>
How many replies does this message have, when applicable.
sourcepub fn reaction_count(&self) -> Option<i32>
pub fn reaction_count(&self) -> Option<i32>
How many reactions does this message have, when applicable.
If this message was sent to a channel, return the name used by the author to post it.
sourcepub fn grouped_id(&self) -> Option<i64>
pub fn grouped_id(&self) -> Option<i64>
If this message belongs to a group of messages, return the unique identifier for that group.
This applies to albums of media, such as multiple photos grouped together.
Note that there may be messages sent in between the messages forming a group.
sourcepub fn restriction_reason(&self) -> Option<&Vec<RestrictionReason>>
pub fn restriction_reason(&self) -> Option<&Vec<RestrictionReason>>
A list of reasons on why this message is restricted.
The message is not restricted if the return value is None
.
sourcepub fn action(&self) -> Option<&MessageAction>
pub fn action(&self) -> Option<&MessageAction>
If this message is a service message, return the service action that occured.
sourcepub fn reply_to_message_id(&self) -> Option<i32>
pub fn reply_to_message_id(&self) -> Option<i32>
If this message is replying to another message, return the replied message ID.
sourcepub async fn get_reply(&self) -> Result<Option<Self>, InvocationError>
pub async fn get_reply(&self) -> Result<Option<Self>, InvocationError>
Fetch the message that this message is replying to, or None
if this message is not a
reply to a previous message.
Shorthand for Client::get_reply_to_message
.
sourcepub async fn respond<M: Into<InputMessage>>(
&self,
message: M
) -> Result<Self, InvocationError>
pub async fn respond<M: Into<InputMessage>>( &self, message: M ) -> Result<Self, InvocationError>
Respond to this message by sending a new message in the same chat, but without directly replying to it.
Shorthand for Client::send_message
.
sourcepub async fn reply<M: Into<InputMessage>>(
&self,
message: M
) -> Result<Self, InvocationError>
pub async fn reply<M: Into<InputMessage>>( &self, message: M ) -> Result<Self, InvocationError>
Directly reply to this message by sending a new message in the same chat that replies to
it. This methods overrides the reply_to
on the InputMessage
to point to self
.
Shorthand for Client::send_message
.
sourcepub async fn forward_to<C: Into<PackedChat>>(
&self,
chat: C
) -> Result<Self, InvocationError>
pub async fn forward_to<C: Into<PackedChat>>( &self, chat: C ) -> Result<Self, InvocationError>
Forward this message to another (or the same) chat.
Shorthand for Client::forward_messages
. If you need to forward multiple messages
at once, consider using that method instead.
sourcepub async fn edit<M: Into<InputMessage>>(
&self,
new_message: M
) -> Result<(), InvocationError>
pub async fn edit<M: Into<InputMessage>>( &self, new_message: M ) -> Result<(), InvocationError>
Edit this message to change its text or media.
Shorthand for Client::edit_message
.
sourcepub async fn delete(&self) -> Result<(), InvocationError>
pub async fn delete(&self) -> Result<(), InvocationError>
Delete this message for everyone.
Shorthand for Client::delete_messages
. If you need to delete multiple messages
at once, consider using that method instead.
sourcepub async fn mark_as_read(&self) -> Result<(), InvocationError>
pub async fn mark_as_read(&self) -> Result<(), InvocationError>
Mark this message and all messages above it as read.
Unlike Client::mark_as_read
, this method only will mark the chat as read up to
this message, not the entire chat.
sourcepub async fn pin(&self) -> Result<(), InvocationError>
pub async fn pin(&self) -> Result<(), InvocationError>
Pin this message in the chat.
Shorthand for Client::pin_message
.
sourcepub async fn unpin(&self) -> Result<(), InvocationError>
pub async fn unpin(&self) -> Result<(), InvocationError>
Unpin this message from the chat.
Shorthand for Client::unpin_message
.
sourcepub async fn refetch(&self) -> Result<(), InvocationError>
pub async fn refetch(&self) -> Result<(), InvocationError>
Refetch this message, mutating all of its properties in-place.
No changes will be made to the message if it fails to be fetched.
Shorthand for Client::get_messages_by_id
.