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: ReplyMarkupImplementations§
Source§impl ReplyMarkup
impl ReplyMarkup
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?;Creates a ReplyMarkup::from_buttons with a single row.
Creates a ReplyMarkup::from_buttons with a single column.
Sourcepub fn from_keys(keys: &[Vec<Key>]) -> Self
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?;Sourcepub fn from_keys_row(keys: &[Key]) -> Self
pub fn from_keys_row(keys: &[Key]) -> Self
Creates a ReplyMarkup::from_keys with a single row.
Sourcepub fn from_keys_col(keys: &[Key]) -> Self
pub fn from_keys_col(keys: &[Key]) -> Self
Creates a ReplyMarkup::from_keys with a single column.
Sourcepub fn hide() -> Self
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?;Sourcepub fn force_reply() -> Self
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?;Sourcepub fn fit_size(self) -> Self
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.
Sourcepub fn single_use(self) -> Self
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.
Sourcepub fn selective(self) -> Self
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.