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

source

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

source

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

source

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.

source

pub fn silent(&self) -> bool

Whether the message should notify people with sound or not.

source

pub fn post(&self) -> bool

Whether this message is a post in a broadcast channel or not.

source

pub fn from_scheduled(&self) -> bool

Whether this message was originated from a previously-scheduled message or not.

source

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.

source

pub fn pinned(&self) -> bool

Whether this message is currently pinned or not.

source

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.

source

pub fn sender(&self) -> Option<Chat>

The sender of this message, if any.

source

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.

source

pub fn forward_header(&self) -> Option<MessageFwdHeader>

If this message was forwarded from a previous message, return the header with information about that forward.

source

pub fn via_bot_id(&self) -> Option<i64>

If this message was sent @via some inline bot, return the bot’s user identifier.

source

pub fn reply_header(&self) -> Option<MessageReplyHeader>

If this message is replying to a previous message, return the header with information about that reply.

source

pub fn date(&self) -> DateTime<Utc>

The date when this message was produced.

source

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.

source

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.

source

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.

source

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.

source

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

source

pub fn forward_count(&self) -> Option<i32>

How many times has this message been forwarded, when applicable.

source

pub fn reply_count(&self) -> Option<i32>

How many replies does this message have, when applicable.

source

pub fn reaction_count(&self) -> Option<i32>

How many reactions does this message have, when applicable.

source

pub fn edit_date(&self) -> Option<DateTime<Utc>>

The date when this message was last edited.

source

pub fn post_author(&self) -> Option<&str>

If this message was sent to a channel, return the name used by the author to post it.

source

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.

source

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.

source

pub fn action(&self) -> Option<&MessageAction>

If this message is a service message, return the service action that occured.

source

pub fn reply_to_message_id(&self) -> Option<i32>

If this message is replying to another message, return the replied message ID.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub async fn pin(&self) -> Result<(), InvocationError>

Pin this message in the chat.

Shorthand for Client::pin_message.

source

pub async fn unpin(&self) -> Result<(), InvocationError>

Unpin this message from the chat.

Shorthand for Client::unpin_message.

source

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.

source

pub async fn download_media<P: AsRef<Path>>( &self, path: P ) -> Result<bool, Error>

Download the message media in this message if applicable.

Returns true if there was media to download, or false otherwise.

Shorthand for Client::download_media.

source

pub fn photo(&self) -> Option<Photo>

Get photo attached to the message if any.

Trait Implementations§

source§

impl Clone for Message

source§

fn clone(&self) -> Message

Returns a copy 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 Message

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.