Skip to main content

Message

Struct Message 

Source
#[non_exhaustive]
pub struct Message {
Show 119 fields pub message_id: i64, pub receiver_user: Option<User>, pub ephemeral_message_id: Option<i64>, pub message_thread_id: Option<i64>, pub direct_messages_topic: Option<DirectMessagesTopic>, pub from: Option<User>, pub sender_chat: Option<Chat>, pub sender_boost_count: Option<u32>, pub sender_business_bot: Option<User>, pub sender_tag: Option<String>, pub date: i64, pub business_connection_id: Option<String>, pub chat: Chat, pub forward_origin: Option<MessageOrigin>, pub is_topic_message: Option<bool>, pub is_automatic_forward: Option<bool>, pub reply_to_message: Option<Box<Message>>, pub external_reply: Option<ExternalReplyInfo>, pub quote: Option<TextQuote>, pub reply_to_story: Option<Story>, pub reply_to_checklist_task_id: Option<i64>, pub reply_to_poll_option_id: Option<String>, pub via_bot: Option<User>, pub edit_date: Option<i64>, pub has_protected_content: Option<bool>, pub is_from_offline: Option<bool>, pub is_paid_post: Option<bool>, pub media_group_id: Option<String>, pub author_signature: Option<String>, pub paid_star_count: Option<i64>, pub text: Option<String>, pub rich_message: Option<RichMessage>, pub entities: Option<Vec<MessageEntity>>, pub link_preview_options: Option<LinkPreviewOptions>, pub suggested_post_info: Option<SuggestedPostInfo>, pub effect_id: Option<String>, pub animation: Option<Animation>, pub audio: Option<Audio>, pub document: Option<Document>, pub paid_media: Option<PaidMediaInfo>, pub photo: Option<Vec<PhotoSize>>, pub live_photo: Option<LivePhoto>, pub sticker: Option<Sticker>, pub story: Option<Story>, pub video: Option<Video>, pub video_note: Option<VideoNote>, pub voice: Option<Voice>, pub caption: Option<String>, pub caption_entities: Option<Vec<MessageEntity>>, pub show_caption_above_media: Option<bool>, pub has_media_spoiler: Option<bool>, pub checklist: Option<Checklist>, pub contact: Option<Contact>, pub dice: Option<Dice>, pub game: Option<Game>, pub poll: Option<Poll>, pub venue: Option<Venue>, pub location: Option<Location>, pub new_chat_members: Option<Vec<User>>, pub left_chat_member: Option<User>, pub chat_owner_left: Option<ChatOwnerLeft>, pub chat_owner_changed: Option<ChatOwnerChanged>, pub new_chat_title: Option<String>, pub new_chat_photo: Option<Vec<PhotoSize>>, pub delete_chat_photo: Option<bool>, pub group_chat_created: Option<bool>, pub supergroup_chat_created: Option<bool>, pub channel_chat_created: Option<bool>, pub community_chat_added: Option<CommunityChatAdded>, pub community_chat_removed: Option<CommunityChatRemoved>, pub message_auto_delete_timer_changed: Option<MessageAutoDeleteTimerChanged>, pub migrate_to_chat_id: Option<i64>, pub migrate_from_chat_id: Option<i64>, pub pinned_message: Option<Box<Message>>, pub reply_markup: Option<InlineKeyboardMarkup>, pub invoice: Option<Invoice>, pub successful_payment: Option<SuccessfulPayment>, pub refunded_payment: Option<RefundedPayment>, pub web_app_data: Option<WebAppData>, pub forum_topic_created: Option<ForumTopicCreated>, pub forum_topic_edited: Option<ForumTopicEdited>, pub forum_topic_closed: Option<ForumTopicClosed>, pub forum_topic_reopened: Option<ForumTopicReopened>, pub general_forum_topic_hidden: Option<GeneralForumTopicHidden>, pub general_forum_topic_unhidden: Option<GeneralForumTopicUnhidden>, pub users_shared: Option<UsersShared>, pub chat_shared: Option<ChatShared>, pub connected_website: Option<String>, pub write_access_allowed: Option<WriteAccessAllowed>, pub passport_data: Option<PassportData>, pub proximity_alert_triggered: Option<ProximityAlertTriggered>, pub boost_added: Option<ChatBoostAdded>, pub chat_background_set: Option<ChatBackground>, pub gift: Option<GiftInfo>, pub unique_gift: Option<UniqueGiftInfo>, pub gift_upgrade_sent: Option<GiftInfo>, pub giveaway_created: Option<GiveawayCreated>, pub giveaway: Option<Giveaway>, pub giveaway_winners: Option<GiveawayWinners>, pub giveaway_completed: Option<GiveawayCompleted>, pub video_chat_scheduled: Option<VideoChatScheduled>, pub video_chat_started: Option<VideoChatStarted>, pub video_chat_ended: Option<VideoChatEnded>, pub video_chat_participants_invited: Option<VideoChatParticipantsInvited>, pub managed_bot_created: Option<ManagedBotCreated>, pub poll_option_added: Option<PollOptionAdded>, pub poll_option_deleted: Option<PollOptionDeleted>, pub checklist_tasks_done: Option<ChecklistTasksDone>, pub checklist_tasks_added: Option<ChecklistTasksAdded>, pub direct_message_price_changed: Option<DirectMessagePriceChanged>, pub paid_message_price_changed: Option<PaidMessagePriceChanged>, pub suggested_post_approved: Option<SuggestedPostApproved>, pub suggested_post_approval_failed: Option<SuggestedPostApprovalFailed>, pub suggested_post_declined: Option<SuggestedPostDeclined>, pub suggested_post_paid: Option<SuggestedPostPaid>, pub suggested_post_refunded: Option<SuggestedPostRefunded>, pub guest_bot_caller_user: Option<User>, pub guest_bot_caller_chat: Option<Chat>, pub guest_query_id: Option<String>,
}
Expand description

A Telegram message.

Only fields that were actually sent will be Some. Consult the official Bot API documentation for field availability rules.

This is the largest and most frequently extended object in the Bot API, so it is #[non_exhaustive]. Construct one with Default::default and assign the fields you need; every future field Telegram adds then arrives as a non-breaking change rather than a major version bump.

let mut msg = Message::default();
msg.message_id = 1;
msg.text = Some("hello".to_owned());

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§message_id: i64

Unique message identifier inside this chat; 0 for ephemeral messages. In specific instances (e.g. a video sent to a large chat), the server might schedule the message instead of sending it immediately — in that case this field is also 0 until the message is actually sent.

§receiver_user: Option<User>

For ephemeral messages — the user who received the message.

§ephemeral_message_id: Option<i64>

For ephemeral messages — identifier of the message inside this chat. The identifier may be reused for another ephemeral message once this one is deleted or expires.

§message_thread_id: Option<i64>

Optional — unique identifier of a message thread to which the message belongs.

§direct_messages_topic: Option<DirectMessagesTopic>

Information about the direct messages chat topic that contains the message.

§from: Option<User>

Sender of the message; empty for messages sent to channels.

§sender_chat: Option<Chat>

Sender of the message; empty for messages sent to channels or on behalf of a chat.

§sender_boost_count: Option<u32>

For supergroup messages — boost count of the sender.

§sender_business_bot: Option<User>

The bot that actually sent the message on behalf of the business account.

§sender_tag: Option<String>

Tag or custom title of the sender; for supergroups only (Bot API 9.5).

§date: i64

Date the message was sent, as a Unix timestamp.

§business_connection_id: Option<String>

Unique identifier of the business connection from which the message was received.

§chat: Chat

Conversation the message belongs to.

§forward_origin: Option<MessageOrigin>

Information about the original message for forwarded messages.

§is_topic_message: Option<bool>

true if the message is sent to a forum topic.

§is_automatic_forward: Option<bool>

true if the message is a channel post automatically forwarded to the connected discussion group.

§reply_to_message: Option<Box<Message>>

For replies in the same chat and message thread, the original message. The nested Message never carries its own reply_to_message, even if it is itself a reply. May be omitted for replies to an ephemeral message.

§external_reply: Option<ExternalReplyInfo>

Information about the message that is being replied to from another chat or topic.

§quote: Option<TextQuote>

For replies that quote part of the original message, the quoted part.

§reply_to_story: Option<Story>

For replies to a story, the original story.

§reply_to_checklist_task_id: Option<i64>

Identifier of the checklist task being replied to.

§reply_to_poll_option_id: Option<String>

Persistent identifier of the poll option being replied to.

§via_bot: Option<User>

Bot through which the message was sent.

§edit_date: Option<i64>

Date the message was last edited, as a Unix timestamp.

§has_protected_content: Option<bool>

true if the message can’t be forwarded.

§is_from_offline: Option<bool>

true if the message was sent by an implicit action.

§is_paid_post: Option<bool>

true if the message is a paid post.

Paid posts must not be deleted for 24 hours after sending and cannot be edited.

§media_group_id: Option<String>

The unique identifier of a media message group this message belongs to.

§author_signature: Option<String>

Signature of the post author for messages in channels.

§paid_star_count: Option<i64>

Number of Telegram Stars paid by the sender to send this message.

§text: Option<String>

Actual UTF-8 text of the message (0–4096 characters).

§rich_message: Option<RichMessage>

Rich formatted message content.

§entities: Option<Vec<MessageEntity>>

Special entities like usernames, URLs, bot commands, etc.

§link_preview_options: Option<LinkPreviewOptions>

Options used for link preview generation.

§suggested_post_info: Option<SuggestedPostInfo>

Information about a suggested post; present when the message is a suggested post in a channel direct messages chat.

§effect_id: Option<String>

Unique identifier of the message effect added to the message.

§animation: Option<Animation>

Animation attached to the message.

§audio: Option<Audio>

Audio file attached to the message.

§document: Option<Document>

Document attached to the message.

§paid_media: Option<PaidMediaInfo>

Paid media attached to the message.

§photo: Option<Vec<PhotoSize>>

Photo attached to the message (array of sizes).

§live_photo: Option<LivePhoto>

Live photo attached to the message.

§sticker: Option<Sticker>

Sticker attached to the message.

§story: Option<Story>

Story attached to the message.

§video: Option<Video>

Video attached to the message.

§video_note: Option<VideoNote>

Video note attached to the message.

§voice: Option<Voice>

Voice note attached to the message.

§caption: Option<String>

Caption for the animation, audio, document, paid media, photo, video or voice.

§caption_entities: Option<Vec<MessageEntity>>

Special entities in the caption.

§show_caption_above_media: Option<bool>

true if the caption must be shown above the message media.

§has_media_spoiler: Option<bool>

true if the message media is covered by a spoiler animation.

§checklist: Option<Checklist>

Checklist attached to the message.

§contact: Option<Contact>

Contact shared in the message.

§dice: Option<Dice>

Dice result in the message.

§game: Option<Game>

Game in the message.

§poll: Option<Poll>

Poll in the message.

§venue: Option<Venue>

Venue in the message.

§location: Option<Location>

Location in the message.

§new_chat_members: Option<Vec<User>>

New members that joined the group.

§left_chat_member: Option<User>

A member that left the group.

§chat_owner_left: Option<ChatOwnerLeft>

Service message: chat owner has left.

§chat_owner_changed: Option<ChatOwnerChanged>

Service message: chat owner has changed.

§new_chat_title: Option<String>

New chat title (service message).

§new_chat_photo: Option<Vec<PhotoSize>>

New chat photo (service message).

§delete_chat_photo: Option<bool>

true if the chat photo was deleted (service message).

§group_chat_created: Option<bool>

true if the group was created (service message).

§supergroup_chat_created: Option<bool>

true if the supergroup was created (service message).

§channel_chat_created: Option<bool>

true if the channel was created (service message).

§community_chat_added: Option<CommunityChatAdded>

Service message: chat added to a Community.

§community_chat_removed: Option<CommunityChatRemoved>

Service message: chat removed from a Community.

§message_auto_delete_timer_changed: Option<MessageAutoDeleteTimerChanged>

Auto-delete timer changed (service message).

§migrate_to_chat_id: Option<i64>

The group has been migrated to a supergroup with this ID.

§migrate_from_chat_id: Option<i64>

The supergroup has been migrated from a group with this ID.

§pinned_message: Option<Box<Message>>

The pinned message (service message).

§reply_markup: Option<InlineKeyboardMarkup>

Inline keyboard attached to the message.

§invoice: Option<Invoice>

Invoice for a payment (service message).

§successful_payment: Option<SuccessfulPayment>

Successful payment information (service message).

§refunded_payment: Option<RefundedPayment>

Refunded payment information (service message).

§web_app_data: Option<WebAppData>

Data from the Web App.

§forum_topic_created: Option<ForumTopicCreated>

Forum topic created (service message).

§forum_topic_edited: Option<ForumTopicEdited>

Forum topic edited (service message).

§forum_topic_closed: Option<ForumTopicClosed>

Forum topic closed (service message).

§forum_topic_reopened: Option<ForumTopicReopened>

Forum topic reopened (service message).

§general_forum_topic_hidden: Option<GeneralForumTopicHidden>

General forum topic hidden (service message).

§general_forum_topic_unhidden: Option<GeneralForumTopicUnhidden>

General forum topic unhidden (service message).

§users_shared: Option<UsersShared>

Users were shared with the bot (service message).

§chat_shared: Option<ChatShared>

A chat was shared with the bot (service message).

§connected_website: Option<String>

Domain of the website the user logged in on via Telegram Login.

§write_access_allowed: Option<WriteAccessAllowed>

The user allowed the bot to write to them (service message).

§passport_data: Option<PassportData>

Telegram Passport data shared with the bot.

§proximity_alert_triggered: Option<ProximityAlertTriggered>

A user came within another user’s proximity radius (service message).

§boost_added: Option<ChatBoostAdded>

The chat was boosted (service message).

§chat_background_set: Option<ChatBackground>

The chat background was changed (service message).

§gift: Option<GiftInfo>

A regular gift was sent or received (service message).

§unique_gift: Option<UniqueGiftInfo>

A unique gift was sent or received (service message).

§gift_upgrade_sent: Option<GiftInfo>

A gift upgrade was sent as a separate service message.

§giveaway_created: Option<GiveawayCreated>

A scheduled giveaway was created (service message).

§giveaway: Option<Giveaway>

The message is a scheduled giveaway.

§giveaway_winners: Option<GiveawayWinners>

Giveaway winners were selected (service message).

§giveaway_completed: Option<GiveawayCompleted>

A giveaway without public winners completed (service message).

§video_chat_scheduled: Option<VideoChatScheduled>

A video chat was scheduled (service message).

§video_chat_started: Option<VideoChatStarted>

A video chat started (service message).

§video_chat_ended: Option<VideoChatEnded>

A video chat ended (service message).

§video_chat_participants_invited: Option<VideoChatParticipantsInvited>

New participants were invited to a video chat (service message).

§managed_bot_created: Option<ManagedBotCreated>

Service message: a new managed bot was created (Bot API 9.6).

§poll_option_added: Option<PollOptionAdded>

Service message: an option was added to a poll (Bot API 9.6).

§poll_option_deleted: Option<PollOptionDeleted>

Service message: an option was deleted from a poll (Bot API 9.6).

§checklist_tasks_done: Option<ChecklistTasksDone>

Service message: tasks in a checklist were marked done or not done.

§checklist_tasks_added: Option<ChecklistTasksAdded>

Service message: tasks were added to a checklist.

§direct_message_price_changed: Option<DirectMessagePriceChanged>

Service message: the price for paid messages in the direct messages chat changed.

§paid_message_price_changed: Option<PaidMessagePriceChanged>

Service message: the price for paid messages in the chat changed.

§suggested_post_approved: Option<SuggestedPostApproved>

Service message: a suggested post was approved.

§suggested_post_approval_failed: Option<SuggestedPostApprovalFailed>

Service message: approval of a suggested post has failed.

§suggested_post_declined: Option<SuggestedPostDeclined>

Service message: a suggested post was declined.

§suggested_post_paid: Option<SuggestedPostPaid>

Service message: payment for a suggested post was received.

§suggested_post_refunded: Option<SuggestedPostRefunded>

Service message: payment for a suggested post was refunded.

§guest_bot_caller_user: Option<User>

For a message sent by a guest bot, the user whose original message triggered the bot’s response.

§guest_bot_caller_chat: Option<Chat>

For a message sent by a guest bot, the chat whose original message triggered the bot’s response.

§guest_query_id: Option<String>

The unique identifier for the guest query.

Use with answerGuestQuery to send a response. If non-empty, the message belongs to a chat of the corresponding business account independent from any potential bot chat sharing the same identifier.

Implementations§

Source§

impl Message

Source

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

Returns the effective text of the message — text or caption.

Source

pub fn is_command(&self) -> bool

Returns true if the message is a command (text starts with /).

Source

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

Extracts the command string (e.g. "start" from /start@bot), if present.

Trait Implementations§

Source§

impl Clone for Message

Source§

fn clone(&self) -> Message

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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
Source§

impl Default for Message

Source§

fn default() -> Message

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Message

Source§

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

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

impl Serialize for Message

Source§

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

Serialize this value into the given Serde serializer. 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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