Struct grammers_client::types::input_message::InputMessage
source · pub struct InputMessage { /* private fields */ }
Expand description
Construct and send rich text messages with various options.
Implementations§
source§impl InputMessage
impl InputMessage
sourcepub fn background(self, background: bool) -> Self
pub fn background(self, background: bool) -> Self
Whether to “send this message as a background message”.
This description is taken from https://core.telegram.org/method/messages.sendMessage.
sourcepub fn clear_draft(self, clear_draft: bool) -> Self
pub fn clear_draft(self, clear_draft: bool) -> Self
Whether the draft in this chat, if any, should be cleared.
sourcepub fn fmt_entities(self, entities: Vec<MessageEntity>) -> Self
pub fn fmt_entities(self, entities: Vec<MessageEntity>) -> Self
The formatting entities within the message (such as bold, italics, etc.).
sourcepub fn link_preview(self, link_preview: bool) -> Self
pub fn link_preview(self, link_preview: bool) -> Self
Whether the link preview be shown for the message.
This has no effect when sending media, which cannot contain a link preview.
sourcepub fn reply_markup<RM: ReplyMarkup>(self, markup: &RM) -> Self
pub fn reply_markup<RM: ReplyMarkup>(self, markup: &RM) -> Self
Defines the suggested reply markup for the message (such as adding inline buttons). This will be displayed below the message.
Only bot accounts can make use of the reply markup feature (a user attempting to send a message with a reply markup will result in the markup being ignored by Telegram).
The user is free to ignore the markup and continue sending usual text messages.
See crate::reply_markup
for the different available markups along with how
they behave.
sourcepub fn reply_to(self, reply_to: Option<i32>) -> Self
pub fn reply_to(self, reply_to: Option<i32>) -> Self
The message identifier to which this message should reply to, if any.
Otherwise, this message will not be a reply to any other.
sourcepub fn schedule_date(self, schedule_date: Option<SystemTime>) -> Self
pub fn schedule_date(self, schedule_date: Option<SystemTime>) -> Self
If set to a distant enough future time, the message won’t be sent immediately, and instead it will be scheduled to be automatically sent at a later time.
This scheduling is done server-side, and may not be accurate to the second.
Bot accounts cannot schedule messages.
sourcepub fn schedule_once_online(self) -> Self
pub fn schedule_once_online(self) -> Self
Schedule the message to be sent once the person comes online.
This only works in private chats, and only if the person has their last seen visible.
Bot accounts cannot schedule messages.
sourcepub fn silent(self, silent: bool) -> Self
pub fn silent(self, silent: bool) -> Self
Whether the message should notify people or not.
Defaults to false
, which means it will notify them. Set it to true
to alter this behaviour.
sourcepub fn photo(self, file: Uploaded) -> Self
pub fn photo(self, file: Uploaded) -> Self
Include the uploaded file as a photo in the message.
The Telegram server will compress the image and convert it to JPEG format if necessary.
The text will be the caption of the photo, which may be empty for no caption.
sourcepub fn photo_url(self, url: impl Into<String>) -> Self
pub fn photo_url(self, url: impl Into<String>) -> Self
Include an external photo in the message.
The Telegram server will download and compress the image and convert it to JPEG format if necessary.
The text will be the caption of the photo, which may be empty for no caption.
sourcepub fn document(self, file: Uploaded) -> Self
pub fn document(self, file: Uploaded) -> Self
Include the uploaded file as a document in the message.
You can use this to send videos, stickers, audios, or uncompressed photos.
The text will be the caption of the document, which may be empty for no caption.
sourcepub fn thumbnail(self, thumb: Uploaded) -> Self
pub fn thumbnail(self, thumb: Uploaded) -> Self
Include the video file with thumb in the message.
The text will be the caption of the document, which may be empty for no caption.
Examples
async fn f(client: &mut grammers_client::Client) -> Result<(), Box<dyn std::error::Error>> {
use grammers_client::{InputMessage};
let video = client.upload_file("video.mp4").await?;
let thumb = client.upload_file("thumb.png").await?;
let message = InputMessage::text("").document(video).thumbnail(thumb);
Ok(())
}
sourcepub fn document_url(self, url: impl Into<String>) -> Self
pub fn document_url(self, url: impl Into<String>) -> Self
Include an external file as a document in the message.
You can use this to send videos, stickers, audios, or uncompressed photos.
The Telegram server will be the one that downloads and includes the document as media.
The text will be the caption of the document, which may be empty for no caption.
sourcepub fn attribute(self, attr: Attribute) -> Self
pub fn attribute(self, attr: Attribute) -> Self
Add additional attributes to the message.
This must be called after setting a file.
Examples
use std::time::Duration;
use grammers_client::{types::Attribute, InputMessage};
let message = InputMessage::text("").document(audio).attribute(
Attribute::Audio {
duration: Duration::new(123, 0),
title: Some("Hello".to_string()),
performer: Some("World".to_string()),
}
);
sourcepub fn copy_media(self, media: &Media) -> Self
pub fn copy_media(self, media: &Media) -> Self
Copy media from an existing message.
You can use this to send media from another message without re-uploading it.
sourcepub fn file(self, file: Uploaded) -> Self
pub fn file(self, file: Uploaded) -> Self
Include the uploaded file as a document file in the message.
You can use this to send any type of media as a simple document file.
The text will be the caption of the file, which may be empty for no caption.
sourcepub fn media_ttl(self, seconds: i32) -> Self
pub fn media_ttl(self, seconds: i32) -> Self
Change the media’s Time To Live (TTL).
For example, this enables you to send a photo
that can only be viewed for a certain
amount of seconds before it expires.
Not all media supports this feature.
This method should be called before setting any media, else it won’t have any effect.
sourcepub fn mime_type(self, mime_type: &str) -> Self
pub fn mime_type(self, mime_type: &str) -> Self
Change the media’s mime type.
This method will override the mime type that would otherwise be automatically inferred from the extension of the used file
If no mime type is set and it cannot be inferred, the mime type will be “application/octet-stream”.
This method should be called before setting any media, else it won’t have any effect.