refactored, fixed compiling errors and added docs

This commit is contained in:
P0lunin 2019-09-11 19:52:53 +03:00
parent 5099403fa6
commit 8f18b5ba02
7 changed files with 128 additions and 33 deletions

View file

@ -3,9 +3,16 @@
/// selected the bots message and tapped Reply'). This can be
/// extremely useful if you want to create user-friendly step-by-step
/// 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 force_reply: True,
#[serde(skip_serializing_if = "Not::not")]
pub selective: bool,
/// Shows reply interface to the user, as if they manually selected the
/// bots message and tapped Reply'
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>,
}

View file

@ -1,19 +1,39 @@
/// 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 {
/// Label text on the button
pub text: String,
#[serde(flatten)]
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 {
#[serde(rename = "url")]
/// HTTP or tg:// url to be opened when button is pressed
Url(String),
// TODO(knsd): Url?
#[serde(rename = "callback_data")]
CallbackData(String), // TODO(knsd) Validate size?
// SwitchInlineQuery(String),
// SwitchInlineQueryCurrentChat(String),
// CallbackGame(CallbackGame),
/// Data to be sent in a callback query to the bot when button is pressed,
/// 1-64 bytes
CallbackData(String),
/// If set, pressing the button will prompt the user to select one of their
/// chats, open that chat and insert the bots username and the specified
/// inline query in the input field. Can be empty, in which case just the
/// bots 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 bots username and
/// the specified inline query in the current chat's input field. Can be
/// empty, in which case only the bots 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
}

View file

@ -1,5 +1,13 @@
/// This object represents an inline keyboard that appears right next to the message it belongs to.
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
use crate::core::types::InlineKeyboardButton;
/// 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 {
/// Array of button rows, each represented by an Array of
/// [`InlineKeyboardButton`] objects
pub inline_keyboard: Vec<Vec<InlineKeyboardButton>>,
}

View file

@ -1,9 +1,19 @@
/// This object represents one button of the reply keyboard.
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
/// This object represents one button of the reply keyboard. For simple text
/// 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 {
/// 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,
#[serde(skip_serializing_if = "Not::not")]
pub request_contact: bool,
#[serde(skip_serializing_if = "Not::not")]
pub request_location: bool,
#[serde(skip_serializing_if = "Option::is_none")]
/// Optional. If True, the user's phone number will be sent as a contact
/// 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>,
}

View file

@ -29,6 +29,13 @@ pub use self::{
successful_payment::SuccessfulPayment,
user::User,
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;
@ -39,9 +46,13 @@ mod chat_member;
mod chat_permissions;
mod chat_photo;
mod document;
mod force_reply;
mod inline_keyboard_markup;
mod inline_keyboard_button;
mod input_file;
mod input_media;
mod invoice;
mod keyboard_button;
mod label_price;
mod message;
mod message_entity;
@ -51,6 +62,9 @@ mod parse_mode;
mod photo_size;
mod pre_checkout_query;
mod response_parameters;
mod reply_markup;
mod reply_keyboard_markup;
mod reply_keyboard_remove;
mod send_invoice;
mod shipping_address;
mod shipping_option;

View file

@ -1,11 +1,35 @@
use crate::core::types::KeyboardButton;
/// 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 {
/// Array of button rows, each represented by an Array of [`KeyboardButton`]
/// objects
pub keyboard: Vec<Vec<KeyboardButton>>,
#[serde(skip_serializing_if = "Not::not")]
pub resize_keyboard: bool,
#[serde(skip_serializing_if = "Not::not")]
pub one_time_keyboard: bool,
#[serde(skip_serializing_if = "Not::not")]
pub selective: bool,
#[serde(skip_serializing_if = "Option::is_none")]
/// Optional. Requests clients to resize the keyboard vertically for optimal
/// fit (e.g., make the keyboard smaller if there are just two rows of
/// buttons). Defaults to false, in which case the custom keyboard is always
/// 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 bots language, bot replies to
/// the request with a keyboard to select the new language. Other users in
/// the group dont see the keyboard.
pub selective: Option<bool>,
}

View file

@ -2,10 +2,22 @@
/// the current custom keyboard and display the default letter-keyboard.
/// 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
/// immediately after the user presses a button (see ReplyKeyboardMarkup).
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
/// immediately after the user presses a button (see [`ReplyKeyboardMarkup`]).
#[derive(Debug, Serialize, Deserialize, Hash, PartialEq, Eq, Clone)]
pub struct ReplyKeyboardRemove {
pub remove_keyboard: True,
#[serde(skip_serializing_if = "Not::not")]
pub selective: bool,
/// equests clients to remove the custom keyboard (user will not be able to
/// summon this keyboard; if you want to hide the keyboard from sight but
/// 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 bots language, bot replies to
/// the request with a keyboard to select the new language. Other users in
/// the group dont see the keyboard.
pub selective: Option<bool>,
}