Skip to main content

ReplyMarkup

Struct ReplyMarkup 

Source
pub struct ReplyMarkup {
    pub raw: ReplyMarkup,
}
Expand description

Markup to be used as the intended way to reply to the message it is attached to.

Fields§

§raw: ReplyMarkup

Implementations§

Source§

impl ReplyMarkup

Source

pub fn from_buttons(buttons: &[Vec<Button>]) -> Self

Define inline buttons for a message.

These will display right under the message.

You cannot add images to the buttons, but you can use emoji (simply copy-paste them into your code, or use the correct escape sequence, or using any other input methods you like).

You will need to provide a matrix of Button, that is, a vector that contains the rows from top to bottom, where the rows consist of a vector of buttons from left to right.

§Examples
use grammers_client::message::{InputMessage, ReplyMarkup, Button};

let artist = "Krewella";
let markup = ReplyMarkup::from_buttons(&[
    vec![Button::data(format!("Song by {}", artist), b"play")],
    vec![Button::data("Previous", b"prev"), Button::data("Next", b"next")],
]);
client.send_message(peer, InputMessage::new().text("Select song").reply_markup(markup)).await?;
Source

pub fn from_buttons_row(buttons: &[Button]) -> Self

Creates a ReplyMarkup::from_buttons with a single row.

Source

pub fn from_buttons_col(buttons: &[Button]) -> Self

Creates a ReplyMarkup::from_buttons with a single column.

Source

pub fn from_keys(keys: &[Vec<Key>]) -> Self

Define a custom keyboard, replacing the user’s own virtual keyboard.

This will be displayed below the input message field for users, and on mobile devices, this also hides the virtual keyboard (effectively “replacing” it).

You cannot add images to the buttons, but you can use emoji (simply copy-paste them into your code, or use the correct escape sequence, or using any other input methods you like).

You will need to provide a matrix of Key, that is, a vector that contains the rows from top to bottom, where the rows consist of a vector of buttons from left to right.

The return type may continue to be configured before being used.

§Examples
use grammers_client::message::{InputMessage, ReplyMarkup, Key};

let markup = ReplyMarkup::from_keys(&[
    vec![Key::text("Accept")],
    vec![Key::text("Cancel"), Key::text("Try something else")],
]);
client.send_message(peer, InputMessage::new().text("What do you want to do?").reply_markup(markup)).await?;
Source

pub fn from_keys_row(keys: &[Key]) -> Self

Creates a ReplyMarkup::from_keys with a single row.

Source

pub fn from_keys_col(keys: &[Key]) -> Self

Creates a ReplyMarkup::from_keys with a single column.

Source

pub fn hide() -> Self

Hide a previously-sent keyboard.

See the return type for further configuration options.

§Examples
use grammers_client::message::{InputMessage, ReplyMarkup};

let markup = ReplyMarkup::hide();
client.send_message(peer, InputMessage::new().text("Bot keyboards removed.").reply_markup(markup)).await?;
Source

pub fn force_reply() -> Self

“Forces” the user to send a reply.

This will cause the user’s application to automatically select the message for replying to it, although the user is still able to dismiss the reply and send a normal message.

See the return type for further configuration options.

§Examples
use grammers_client::message::{InputMessage, ReplyMarkup};

let markup = ReplyMarkup::force_reply().single_use();
client.send_message(peer, InputMessage::new().text("Reply me!").reply_markup(markup)).await?;
Source

pub fn fit_size(self) -> Self

Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Otherwise, the custom keyboard is always of the same height as the virtual keyboard.

Only has effect on reply markups that use keys.

Source

pub fn single_use(self) -> Self

Requests clients to hide the keyboard as soon as it’s been used.

The keyboard will still be available, but clients will automatically display the usual letter-keyboard in the conversation – the user can press a special button in the input field to see the custom keyboard again.

Only has effect on reply markups that use keys or when forcing the user to reply.

Source

pub fn selective(self) -> Self

Force the markup to only apply to specific users.

The selected user will be either the people @-mentioned in the text of the Message object, or if the bot’s message is a reply, the sender of the original message.

Has no effect on markups that consist of inline buttons.

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

Source§

type Output = T

Should always be Self
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.