Skip to main content

IncomingMessage

Struct IncomingMessage 

Source
pub struct IncomingMessage {
    pub raw: Message,
    pub client: Option<Client>,
}
Expand description

A new or edited message.

Fields§

§raw: Message

The underlying TL message object.

§client: Option<Client>

An embedded client reference, populated for messages received via stream_updates() and returned from send/search/history APIs. When present, the clientless action methods (reply, respond, edit, delete, pin, unpin, react, …) can be called without passing a &Client argument.

Implementations§

Source§

impl IncomingMessage

Source

pub fn download_location(&self) -> Option<InputFileLocation>

Get the download location for the media in this message, if any.

Source§

impl IncomingMessage

Source

pub fn from_raw(raw: Message) -> Self

Source

pub fn with_client(self, client: Client) -> Self

Attach a Client so the clientless action methods work.

Returns self for chaining:

let msg = IncomingMessage::from_raw(raw).with_client(client);
Source

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

The message text (or caption for media messages).

Source

pub fn id(&self) -> i32

Unique message ID within the chat.

Source

pub fn peer_id(&self) -> Option<&Peer>

The peer (chat) this message belongs to.

Source

pub fn sender_id(&self) -> Option<&Peer>

The sender peer, if available (not set for anonymous channel posts).

Source

pub fn outgoing(&self) -> bool

true if the message was sent by the logged-in account.

Source

pub fn date(&self) -> i32

Unix timestamp when the message was sent.

Source

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

Unix timestamp of the last edit, if the message has been edited.

Source

pub fn mentioned(&self) -> bool

true if the logged-in user was mentioned in this message.

Source

pub fn silent(&self) -> bool

true if the message was sent silently (no notification).

Source

pub fn post(&self) -> bool

true if this is a channel post (no sender).

Source

pub fn pinned(&self) -> bool

true if this message is currently pinned.

Source

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

Number of times the message has been forwarded (channels only).

Source

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

View count for channel posts.

Source

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

Reply count (number of replies in a thread).

Source

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

ID of the message this one is replying to.

Source

pub async fn reply_to_message( &self, client: &Client, ) -> Result<Option<IncomingMessage>, Error>

Fetch the message that this one is replying to.

Returns None if this message is not a reply or if the peer is unknown. Unlike reply_to_message_id this actually performs an API call to retrieve the full message object.

Source

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

The message’s send time as a chrono::DateTime<chrono::Utc>.

This is a typed wrapper around the raw date() Unix timestamp.

Source

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

The last edit time as a chrono::DateTime<chrono::Utc>, if edited.

Source

pub fn media(&self) -> Option<&MessageMedia>

The media attached to this message, if any.

Source

pub fn entities(&self) -> Option<&Vec<MessageEntity>>

Formatting entities (bold, italic, code, links, etc).

Source

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

Group ID for album messages (multiple media in one).

Source

pub fn from_scheduled(&self) -> bool

true if this message was sent from a scheduled one.

Source

pub fn edit_hide(&self) -> bool

true if the edit date is hidden from recipients.

Source

pub fn media_unread(&self) -> bool

true if the media in this message has not been read yet.

Source

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

ID of the bot that sent this message via inline mode, if any.

Source

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

Signature of the post author in a channel, if set.

Source

pub fn reaction_count(&self) -> i32

Number of reactions on this message, if any.

Source

pub fn restriction_reason(&self) -> Option<&Vec<RestrictionReason>>

Restriction reasons (why this message is unavailable in some regions).

Source

pub fn reply_markup(&self) -> Option<&ReplyMarkup>

Reply markup (inline keyboards, etc).

Source

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

Forward info header, if this message was forwarded.

Source

pub fn noforwards(&self) -> bool

true if forwarding this message is restricted.

Source

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

Reconstruct Markdown from the message text and its formatting entities.

Returns plain text if there are no entities.

Source

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

Reconstruct HTML from the message text and its formatting entities.

Returns plain text if there are no entities.

Source

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

Service message action (e.g. “user joined”, “call started”).
Returns None for regular text/media messages.

Source

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

Extract a Photo from the message media, if present.

Shorthand for Photo::from_media(msg.media()?).

Source

pub fn document(&self) -> Option<Document>

Extract a Document from the message media, if present.

Shorthand for Document::from_media(msg.media()?).

Source

pub async fn reply( &self, text: impl Into<String>, ) -> Result<IncomingMessage, Error>

Reply to this message (clientless: requires an embedded client).

Returns the sent message so you can chain further operations on it.

Source

pub async fn reply_with( &self, client: &Client, text: impl Into<String>, ) -> Result<IncomingMessage, Error>

Reply to this message with a plain string.

Returns the sent message so you can chain further operations on it.

Source

pub async fn reply_ex( &self, msg: InputMessage, ) -> Result<IncomingMessage, Error>

Reply with a full InputMessage (clientless).

Source

pub async fn reply_ex_with( &self, client: &Client, msg: InputMessage, ) -> Result<IncomingMessage, Error>

Reply with a full InputMessage.

Source

pub async fn respond( &self, text: impl Into<String>, ) -> Result<IncomingMessage, Error>

Send to the same chat without quoting (clientless).

Source

pub async fn respond_with( &self, client: &Client, text: impl Into<String>, ) -> Result<IncomingMessage, Error>

Send to the same chat without quoting.

Source

pub async fn respond_ex( &self, msg: InputMessage, ) -> Result<IncomingMessage, Error>

Full [InputMessage] to the same chat without quoting (clientless).

Source

pub async fn respond_ex_with( &self, client: &Client, msg: InputMessage, ) -> Result<IncomingMessage, Error>

Full [InputMessage] to the same chat without quoting.

Source

pub async fn edit(&self, new_text: impl Into<String>) -> Result<(), Error>

Edit this message (clientless).

Source

pub async fn edit_with( &self, client: &Client, new_text: impl Into<String>, ) -> Result<(), Error>

Edit this message.

Source

pub async fn delete(&self) -> Result<(), Error>

Delete this message (clientless).

Source

pub async fn delete_with(&self, client: &Client) -> Result<(), Error>

Delete this message.

Source

pub async fn mark_as_read(&self) -> Result<(), Error>

Mark this message (and all before it) as read (clientless).

Source

pub async fn mark_as_read_with(&self, client: &Client) -> Result<(), Error>

Mark this message (and all before it) as read.

Source

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

Pin this message silently (clientless).

Source

pub async fn pin_with(&self, client: &Client) -> Result<(), Error>

Pin this message silently.

Source

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

Unpin this message (clientless).

Source

pub async fn unpin_with(&self, client: &Client) -> Result<(), Error>

Unpin this message.

Source

pub async fn forward_to( &self, destination: impl Into<PeerRef>, ) -> Result<IncomingMessage, Error>

Forward this message to another chat (clientless).

Returns the forwarded message in the destination chat.

Source

pub async fn forward_to_with( &self, client: &Client, destination: impl Into<PeerRef>, ) -> Result<IncomingMessage, Error>

Forward this message to another chat.

Returns the forwarded message in the destination chat.

Source

pub async fn refetch(&mut self) -> Result<(), Error>

Re-fetch this message from Telegram (clientless).

Useful to get updated view/forward counts, reactions, edit state, etc. Updates self in place; returns an error if the message was deleted.

Source

pub async fn refetch_with(&mut self, client: &Client) -> Result<(), Error>

Re-fetch this message from Telegram.

Source

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

Download attached media to path (clientless).

Source

pub async fn download_media_with( &self, client: &Client, path: impl AsRef<Path>, ) -> Result<bool, Error>

Download attached media to path. Returns true if media was found.

Source

pub async fn react( &self, reactions: impl Into<InputReactions>, ) -> Result<(), Error>

Send a reaction (clientless).

§Example
use layer_client::reactions::InputReactions;
msg.react(InputReactions::emoticon("👍")).await?;
Source

pub async fn react_with( &self, client: &Client, reactions: impl Into<InputReactions>, ) -> Result<(), Error>

Send a reaction.

Source

pub async fn get_reply(&self) -> Result<Option<IncomingMessage>, Error>

Fetch the message this is a reply to (clientless).

Source

pub async fn get_reply_with( &self, client: &Client, ) -> Result<Option<IncomingMessage>, Error>

Fetch the message this is a reply to.

Source

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

The sender’s bare user-ID, if this is a user message.

Returns None for anonymous channel posts.

Source

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

The chat/channel-ID the sender belongs to (non-user senders).

Source

pub async fn sender_user(&self) -> Result<Option<User>, Error>

Fetch the sender as a typed User (clientless, async).

Returns None if the sender is not a user, or if the user is not in the local peer cache. Performs a network call if needed.

Trait Implementations§

Source§

impl Clone for IncomingMessage

Source§

fn clone(&self) -> IncomingMessage

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 IncomingMessage

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 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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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