pub struct IncomingMessage {
pub raw: Message,
pub client: Option<Client>,
}Expand description
A new or edited message.
Fields§
§raw: MessageThe 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
impl IncomingMessage
Sourcepub fn download_location(&self) -> Option<InputFileLocation>
pub fn download_location(&self) -> Option<InputFileLocation>
Get the download location for the media in this message, if any.
Source§impl IncomingMessage
impl IncomingMessage
pub fn from_raw(raw: Message) -> Self
Sourcepub fn with_client(self, client: Client) -> Self
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);Sourcepub fn sender_id(&self) -> Option<&Peer>
pub fn sender_id(&self) -> Option<&Peer>
The sender peer, if available (not set for anonymous channel posts).
Sourcepub fn edit_date(&self) -> Option<i32>
pub fn edit_date(&self) -> Option<i32>
Unix timestamp of the last edit, if the message has been edited.
Sourcepub fn forward_count(&self) -> Option<i32>
pub fn forward_count(&self) -> Option<i32>
Number of times the message has been forwarded (channels only).
Sourcepub fn view_count(&self) -> Option<i32>
pub fn view_count(&self) -> Option<i32>
View count for channel posts.
Sourcepub fn reply_count(&self) -> Option<i32>
pub fn reply_count(&self) -> Option<i32>
Reply count (number of replies in a thread).
Sourcepub fn reply_to_message_id(&self) -> Option<i32>
pub fn reply_to_message_id(&self) -> Option<i32>
ID of the message this one is replying to.
Sourcepub async fn reply_to_message(
&self,
client: &Client,
) -> Result<Option<IncomingMessage>, Error>
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.
Sourcepub fn date_utc(&self) -> Option<DateTime<Utc>>
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.
Sourcepub fn edit_date_utc(&self) -> Option<DateTime<Utc>>
pub fn edit_date_utc(&self) -> Option<DateTime<Utc>>
The last edit time as a chrono::DateTime<chrono::Utc>, if edited.
Sourcepub fn media(&self) -> Option<&MessageMedia>
pub fn media(&self) -> Option<&MessageMedia>
The media attached to this message, if any.
Sourcepub fn entities(&self) -> Option<&Vec<MessageEntity>>
pub fn entities(&self) -> Option<&Vec<MessageEntity>>
Formatting entities (bold, italic, code, links, etc).
Sourcepub fn grouped_id(&self) -> Option<i64>
pub fn grouped_id(&self) -> Option<i64>
Group ID for album messages (multiple media in one).
Sourcepub fn from_scheduled(&self) -> bool
pub fn from_scheduled(&self) -> bool
true if this message was sent from a scheduled one.
Sourcepub fn media_unread(&self) -> bool
pub fn media_unread(&self) -> bool
true if the media in this message has not been read yet.
Sourcepub fn via_bot_id(&self) -> Option<i64>
pub fn via_bot_id(&self) -> Option<i64>
ID of the bot that sent this message via inline mode, if any.
Signature of the post author in a channel, if set.
Sourcepub fn reaction_count(&self) -> i32
pub fn reaction_count(&self) -> i32
Number of reactions on this message, if any.
Sourcepub fn restriction_reason(&self) -> Option<&Vec<RestrictionReason>>
pub fn restriction_reason(&self) -> Option<&Vec<RestrictionReason>>
Restriction reasons (why this message is unavailable in some regions).
Sourcepub fn reply_markup(&self) -> Option<&ReplyMarkup>
pub fn reply_markup(&self) -> Option<&ReplyMarkup>
Reply markup (inline keyboards, etc).
Sourcepub fn forward_header(&self) -> Option<&MessageFwdHeader>
pub fn forward_header(&self) -> Option<&MessageFwdHeader>
Forward info header, if this message was forwarded.
Sourcepub fn noforwards(&self) -> bool
pub fn noforwards(&self) -> bool
true if forwarding this message is restricted.
Sourcepub fn markdown_text(&self) -> Option<String>
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.
Sourcepub fn html_text(&self) -> Option<String>
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.
Sourcepub fn action(&self) -> Option<&MessageAction>
pub fn action(&self) -> Option<&MessageAction>
Service message action (e.g. “user joined”, “call started”).
Returns None for regular text/media messages.
Sourcepub fn photo(&self) -> Option<Photo>
pub fn photo(&self) -> Option<Photo>
Extract a Photo from the message media, if present.
Shorthand for Photo::from_media(msg.media()?).
Sourcepub fn document(&self) -> Option<Document>
pub fn document(&self) -> Option<Document>
Extract a Document from the message media, if present.
Shorthand for Document::from_media(msg.media()?).
Sourcepub async fn reply(
&self,
text: impl Into<String>,
) -> Result<IncomingMessage, Error>
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.
Sourcepub async fn reply_with(
&self,
client: &Client,
text: impl Into<String>,
) -> Result<IncomingMessage, Error>
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.
Sourcepub async fn reply_ex(
&self,
msg: InputMessage,
) -> Result<IncomingMessage, Error>
pub async fn reply_ex( &self, msg: InputMessage, ) -> Result<IncomingMessage, Error>
Reply with a full InputMessage (clientless).
Sourcepub async fn reply_ex_with(
&self,
client: &Client,
msg: InputMessage,
) -> Result<IncomingMessage, Error>
pub async fn reply_ex_with( &self, client: &Client, msg: InputMessage, ) -> Result<IncomingMessage, Error>
Reply with a full InputMessage.
Sourcepub async fn respond(
&self,
text: impl Into<String>,
) -> Result<IncomingMessage, Error>
pub async fn respond( &self, text: impl Into<String>, ) -> Result<IncomingMessage, Error>
Send to the same chat without quoting (clientless).
Sourcepub async fn respond_with(
&self,
client: &Client,
text: impl Into<String>,
) -> Result<IncomingMessage, Error>
pub async fn respond_with( &self, client: &Client, text: impl Into<String>, ) -> Result<IncomingMessage, Error>
Send to the same chat without quoting.
Sourcepub async fn respond_ex(
&self,
msg: InputMessage,
) -> Result<IncomingMessage, Error>
pub async fn respond_ex( &self, msg: InputMessage, ) -> Result<IncomingMessage, Error>
Full [InputMessage] to the same chat without quoting (clientless).
Sourcepub async fn respond_ex_with(
&self,
client: &Client,
msg: InputMessage,
) -> Result<IncomingMessage, Error>
pub async fn respond_ex_with( &self, client: &Client, msg: InputMessage, ) -> Result<IncomingMessage, Error>
Full [InputMessage] to the same chat without quoting.
Sourcepub async fn edit(&self, new_text: impl Into<String>) -> Result<(), Error>
pub async fn edit(&self, new_text: impl Into<String>) -> Result<(), Error>
Edit this message (clientless).
Sourcepub async fn edit_with(
&self,
client: &Client,
new_text: impl Into<String>,
) -> Result<(), Error>
pub async fn edit_with( &self, client: &Client, new_text: impl Into<String>, ) -> Result<(), Error>
Edit this message.
Sourcepub async fn mark_as_read(&self) -> Result<(), Error>
pub async fn mark_as_read(&self) -> Result<(), Error>
Mark this message (and all before it) as read (clientless).
Sourcepub async fn mark_as_read_with(&self, client: &Client) -> Result<(), Error>
pub async fn mark_as_read_with(&self, client: &Client) -> Result<(), Error>
Mark this message (and all before it) as read.
Sourcepub async fn forward_to(
&self,
destination: impl Into<PeerRef>,
) -> Result<IncomingMessage, Error>
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.
Sourcepub async fn forward_to_with(
&self,
client: &Client,
destination: impl Into<PeerRef>,
) -> Result<IncomingMessage, Error>
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.
Sourcepub async fn refetch(&mut self) -> Result<(), Error>
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.
Sourcepub async fn refetch_with(&mut self, client: &Client) -> Result<(), Error>
pub async fn refetch_with(&mut self, client: &Client) -> Result<(), Error>
Re-fetch this message from Telegram.
Sourcepub async fn download_media(
&self,
path: impl AsRef<Path>,
) -> Result<bool, Error>
pub async fn download_media( &self, path: impl AsRef<Path>, ) -> Result<bool, Error>
Download attached media to path (clientless).
Sourcepub async fn download_media_with(
&self,
client: &Client,
path: impl AsRef<Path>,
) -> Result<bool, Error>
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.
Sourcepub async fn react(
&self,
reactions: impl Into<InputReactions>,
) -> Result<(), Error>
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?;Sourcepub async fn react_with(
&self,
client: &Client,
reactions: impl Into<InputReactions>,
) -> Result<(), Error>
pub async fn react_with( &self, client: &Client, reactions: impl Into<InputReactions>, ) -> Result<(), Error>
Send a reaction.
Sourcepub async fn get_reply(&self) -> Result<Option<IncomingMessage>, Error>
pub async fn get_reply(&self) -> Result<Option<IncomingMessage>, Error>
Fetch the message this is a reply to (clientless).
Sourcepub async fn get_reply_with(
&self,
client: &Client,
) -> Result<Option<IncomingMessage>, Error>
pub async fn get_reply_with( &self, client: &Client, ) -> Result<Option<IncomingMessage>, Error>
Fetch the message this is a reply to.
Sourcepub fn sender_user_id(&self) -> Option<i64>
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.
Sourcepub fn sender_chat_id(&self) -> Option<i64>
pub fn sender_chat_id(&self) -> Option<i64>
The chat/channel-ID the sender belongs to (non-user senders).
Trait Implementations§
Source§impl Clone for IncomingMessage
impl Clone for IncomingMessage
Source§fn clone(&self) -> IncomingMessage
fn clone(&self) -> IncomingMessage
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for IncomingMessage
impl !RefUnwindSafe for IncomingMessage
impl Send for IncomingMessage
impl Sync for IncomingMessage
impl Unpin for IncomingMessage
impl UnsafeUnpin for IncomingMessage
impl !UnwindSafe for IncomingMessage
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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