pub struct InputMessage { /* private fields */ }
Expand description

Construct and send rich text messages with various options.

Implementations§

source§

impl InputMessage

source

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.

source

pub fn clear_draft(self, clear_draft: bool) -> Self

Whether the draft in this chat, if any, should be cleared.

source

pub fn fmt_entities(self, entities: Vec<MessageEntity>) -> Self

The formatting entities within the message (such as bold, italics, etc.).

Whether the link preview be shown for the message.

This has no effect when sending media, which cannot contain a link preview.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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(())
}
source

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.

source

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()),
   }
);
source

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.

source

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.

source

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.

source

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.

source

pub fn text<T: AsRef<str>>(s: T) -> Self

Builds a new message using the given plaintext as the message contents.

Trait Implementations§

source§

impl Default for InputMessage

source§

fn default() -> InputMessage

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

impl From<&str> for InputMessage

source§

fn from(text: &str) -> Self

Converts to this type from the input type.
source§

impl From<String> for InputMessage

source§

fn from(text: String) -> Self

Converts to this type from the input type.

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