mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-08 19:33:53 +01:00
refactored, fixed compiling errors and added docs
This commit is contained in:
parent
5099403fa6
commit
8f18b5ba02
7 changed files with 128 additions and 33 deletions
|
@ -3,9 +3,16 @@
|
||||||
/// selected the bot‘s message and tapped ’Reply'). This can be
|
/// selected the bot‘s message and tapped ’Reply'). This can be
|
||||||
/// extremely useful if you want to create user-friendly step-by-step
|
/// extremely useful if you want to create user-friendly step-by-step
|
||||||
/// interfaces without having to sacrifice privacy mod
|
/// interfaces without having to sacrifice privacy mod
|
||||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Hash, PartialEq, Eq, Clone)]
|
||||||
pub struct ForceReply {
|
pub struct ForceReply {
|
||||||
pub force_reply: True,
|
/// Shows reply interface to the user, as if they manually selected the
|
||||||
#[serde(skip_serializing_if = "Not::not")]
|
/// bot‘s message and tapped ’Reply'
|
||||||
pub selective: bool,
|
pub force_reply: bool,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
/// Optional. Use this parameter if you want to force reply from specific
|
||||||
|
/// users only. Targets: 1) users that are @mentioned in the text of the
|
||||||
|
/// [`Message`] object; 2) if the bot's message is a reply
|
||||||
|
/// (has reply_to_message_id), sender of the original message.
|
||||||
|
pub selective: Option<bool>,
|
||||||
}
|
}
|
|
@ -1,19 +1,39 @@
|
||||||
/// This object represents one button of an inline keyboard.
|
/// This object represents one button of an inline keyboard.
|
||||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Hash, PartialEq, Eq, Clone)]
|
||||||
pub struct InlineKeyboardButton {
|
pub struct InlineKeyboardButton {
|
||||||
|
/// Label text on the button
|
||||||
pub text: String,
|
pub text: String,
|
||||||
|
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub kind: InlineKeyboardButtonKind,
|
pub kind: InlineKeyboardButtonKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize, Clone)]
|
#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize, Eq, Hash, Deserialize)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum InlineKeyboardButtonKind {
|
pub enum InlineKeyboardButtonKind {
|
||||||
#[serde(rename = "url")]
|
/// HTTP or tg:// url to be opened when button is pressed
|
||||||
Url(String),
|
Url(String),
|
||||||
// TODO(knsd): Url?
|
/// Data to be sent in a callback query to the bot when button is pressed,
|
||||||
#[serde(rename = "callback_data")]
|
/// 1-64 bytes
|
||||||
CallbackData(String), // TODO(knsd) Validate size?
|
CallbackData(String),
|
||||||
// SwitchInlineQuery(String),
|
/// If set, pressing the button will prompt the user to select one of their
|
||||||
// SwitchInlineQueryCurrentChat(String),
|
/// chats, open that chat and insert the bot‘s username and the specified
|
||||||
// CallbackGame(CallbackGame),
|
/// inline query in the input field. Can be empty, in which case just the
|
||||||
|
/// bot’s username will be inserted.
|
||||||
|
///
|
||||||
|
/// Note: This offers an easy way for users to start using your bot in
|
||||||
|
/// inline mode when they are currently in a private chat with it.
|
||||||
|
/// Especially useful when combined with switch_pm… actions – in this case
|
||||||
|
/// the user will be automatically returned to the chat they switched from,
|
||||||
|
/// skipping the chat selection screen.
|
||||||
|
SwitchInlineQuery(String),
|
||||||
|
/// Optional. If set, pressing the button will insert the bot‘s username and
|
||||||
|
/// the specified inline query in the current chat's input field. Can be
|
||||||
|
/// empty, in which case only the bot’s username will be inserted.
|
||||||
|
///
|
||||||
|
///This offers a quick way for the user to open your bot in inline mode in
|
||||||
|
/// the same chat – good for selecting something from multiple options.
|
||||||
|
SwitchInlineQueryCurrentChat(String),
|
||||||
|
// CallbackGame(CallbackGame), TODO: разобраться, что с этим делать
|
||||||
|
// TODO: add LoginUrl, pay
|
||||||
}
|
}
|
|
@ -1,5 +1,13 @@
|
||||||
/// This object represents an inline keyboard that appears right next to the message it belongs to.
|
use crate::core::types::InlineKeyboardButton;
|
||||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
|
|
||||||
|
/// This object represents an inline keyboard that appears right next to the
|
||||||
|
/// message it belongs to.
|
||||||
|
///
|
||||||
|
/// *Note*: This will only work in Telegram versions released after
|
||||||
|
/// 9 April, 2016. Older clients will display unsupported message.
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Hash, PartialEq, Eq, Clone)]
|
||||||
pub struct InlineKeyboardMarkup {
|
pub struct InlineKeyboardMarkup {
|
||||||
|
/// Array of button rows, each represented by an Array of
|
||||||
|
/// [`InlineKeyboardButton`] objects
|
||||||
pub inline_keyboard: Vec<Vec<InlineKeyboardButton>>,
|
pub inline_keyboard: Vec<Vec<InlineKeyboardButton>>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,19 @@
|
||||||
/// This object represents one button of the reply keyboard.
|
/// This object represents one button of the reply keyboard. For simple text
|
||||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
|
/// buttons String can be used instead of this object to specify text of the
|
||||||
|
/// button. Optional fields are mutually exclusive.
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Hash, PartialEq, Eq, Clone)]
|
||||||
pub struct KeyboardButton {
|
pub struct KeyboardButton {
|
||||||
|
/// Text of the button. If none of the optional fields are used, it will
|
||||||
|
/// be sent as a message when the button is pressed
|
||||||
pub text: String,
|
pub text: String,
|
||||||
#[serde(skip_serializing_if = "Not::not")]
|
|
||||||
pub request_contact: bool,
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
#[serde(skip_serializing_if = "Not::not")]
|
/// Optional. If True, the user's phone number will be sent as a contact
|
||||||
pub request_location: bool,
|
/// when the button is pressed. Available in private chats only
|
||||||
|
pub request_contact: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
/// Optional. If True, the user's current location will be sent when the
|
||||||
|
/// button is pressed. Available in private chats only
|
||||||
|
pub request_location: Option<bool>,
|
||||||
}
|
}
|
|
@ -29,6 +29,13 @@ pub use self::{
|
||||||
successful_payment::SuccessfulPayment,
|
successful_payment::SuccessfulPayment,
|
||||||
user::User,
|
user::User,
|
||||||
video::Video,
|
video::Video,
|
||||||
|
reply_markup::ReplyMarkup,
|
||||||
|
force_reply::ForceReply,
|
||||||
|
inline_keyboard_button::InlineKeyboardButton,
|
||||||
|
inline_keyboard_markup::InlineKeyboardMarkup,
|
||||||
|
reply_keyboard_remove::ReplyKeyboardRemove,
|
||||||
|
reply_keyboard_markup::ReplyKeyboardMarkup,
|
||||||
|
keyboard_button::KeyboardButton,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod answer_pre_checkout_query;
|
mod answer_pre_checkout_query;
|
||||||
|
@ -39,9 +46,13 @@ mod chat_member;
|
||||||
mod chat_permissions;
|
mod chat_permissions;
|
||||||
mod chat_photo;
|
mod chat_photo;
|
||||||
mod document;
|
mod document;
|
||||||
|
mod force_reply;
|
||||||
|
mod inline_keyboard_markup;
|
||||||
|
mod inline_keyboard_button;
|
||||||
mod input_file;
|
mod input_file;
|
||||||
mod input_media;
|
mod input_media;
|
||||||
mod invoice;
|
mod invoice;
|
||||||
|
mod keyboard_button;
|
||||||
mod label_price;
|
mod label_price;
|
||||||
mod message;
|
mod message;
|
||||||
mod message_entity;
|
mod message_entity;
|
||||||
|
@ -51,6 +62,9 @@ mod parse_mode;
|
||||||
mod photo_size;
|
mod photo_size;
|
||||||
mod pre_checkout_query;
|
mod pre_checkout_query;
|
||||||
mod response_parameters;
|
mod response_parameters;
|
||||||
|
mod reply_markup;
|
||||||
|
mod reply_keyboard_markup;
|
||||||
|
mod reply_keyboard_remove;
|
||||||
mod send_invoice;
|
mod send_invoice;
|
||||||
mod shipping_address;
|
mod shipping_address;
|
||||||
mod shipping_option;
|
mod shipping_option;
|
||||||
|
|
|
@ -1,11 +1,35 @@
|
||||||
|
use crate::core::types::KeyboardButton;
|
||||||
|
|
||||||
/// This object represents a custom keyboard with reply options.
|
/// This object represents a custom keyboard with reply options.
|
||||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Hash, PartialEq, Eq, Clone)]
|
||||||
pub struct ReplyKeyboardMarkup {
|
pub struct ReplyKeyboardMarkup {
|
||||||
|
/// Array of button rows, each represented by an Array of [`KeyboardButton`]
|
||||||
|
/// objects
|
||||||
pub keyboard: Vec<Vec<KeyboardButton>>,
|
pub keyboard: Vec<Vec<KeyboardButton>>,
|
||||||
#[serde(skip_serializing_if = "Not::not")]
|
|
||||||
pub resize_keyboard: bool,
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
#[serde(skip_serializing_if = "Not::not")]
|
/// Optional. Requests clients to resize the keyboard vertically for optimal
|
||||||
pub one_time_keyboard: bool,
|
/// fit (e.g., make the keyboard smaller if there are just two rows of
|
||||||
#[serde(skip_serializing_if = "Not::not")]
|
/// buttons). Defaults to false, in which case the custom keyboard is always
|
||||||
pub selective: bool,
|
/// of the same height as the app's standard keyboard.
|
||||||
|
pub resize_keyboard: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
/// Optional. 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 chat – the user
|
||||||
|
/// can press a special button in the input field to see the custom keyboard
|
||||||
|
/// again. Defaults to false.
|
||||||
|
pub one_time_keyboard: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
/// Optional. Use this parameter if you want to show the keyboard to
|
||||||
|
/// specific users only. Targets: 1) users that are @mentioned in the text
|
||||||
|
/// of the [`Message`] object; 2) if the bot's message is a reply
|
||||||
|
/// (has reply_to_message_id), sender of the original message.
|
||||||
|
///
|
||||||
|
/// Example: A user requests to change the bot‘s language, bot replies to
|
||||||
|
/// the request with a keyboard to select the new language. Other users in
|
||||||
|
/// the group don’t see the keyboard.
|
||||||
|
pub selective: Option<bool>,
|
||||||
}
|
}
|
|
@ -2,10 +2,22 @@
|
||||||
/// the current custom keyboard and display the default letter-keyboard.
|
/// the current custom keyboard and display the default letter-keyboard.
|
||||||
/// By default, custom keyboards are displayed until a new keyboard is sent
|
/// By default, custom keyboards are displayed until a new keyboard is sent
|
||||||
/// by a bot. An exception is made for one-time keyboards that are hidden
|
/// by a bot. An exception is made for one-time keyboards that are hidden
|
||||||
/// immediately after the user presses a button (see ReplyKeyboardMarkup).
|
/// immediately after the user presses a button (see [`ReplyKeyboardMarkup`]).
|
||||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Hash, PartialEq, Eq, Clone)]
|
||||||
pub struct ReplyKeyboardRemove {
|
pub struct ReplyKeyboardRemove {
|
||||||
pub remove_keyboard: True,
|
/// equests clients to remove the custom keyboard (user will not be able to
|
||||||
#[serde(skip_serializing_if = "Not::not")]
|
/// summon this keyboard; if you want to hide the keyboard from sight but
|
||||||
pub selective: bool,
|
/// keep it accessible, use one_time_keyboard in ReplyKeyboardMarkup)
|
||||||
|
pub remove_keyboard: bool,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
/// Optional. Use this parameter if you want to show the keyboard to
|
||||||
|
/// specific users only. Targets: 1) users that are @mentioned in the text
|
||||||
|
/// of the [`Message`] object; 2) if the bot's message is a reply
|
||||||
|
/// (has reply_to_message_id), sender of the original message.
|
||||||
|
///
|
||||||
|
/// Example: A user requests to change the bot‘s language, bot replies to
|
||||||
|
/// the request with a keyboard to select the new language. Other users in
|
||||||
|
/// the group don’t see the keyboard.
|
||||||
|
pub selective: Option<bool>,
|
||||||
}
|
}
|
Loading…
Reference in a new issue