diff --git a/src/types/inline_keyboard_button.rs b/src/types/inline_keyboard_button.rs index add4988a..7c7cd018 100644 --- a/src/types/inline_keyboard_button.rs +++ b/src/types/inline_keyboard_button.rs @@ -13,31 +13,6 @@ pub struct InlineKeyboardButton { pub kind: InlineKeyboardButtonKind, } -impl InlineKeyboardButton { - pub fn new(text: S, kind: InlineKeyboardButtonKind) -> Self - where - S: Into, - { - Self { - text: text.into(), - kind, - } - } - - pub fn text(mut self, val: S) -> Self - where - S: Into, - { - self.text = val.into(); - self - } - - pub fn kind(mut self, val: InlineKeyboardButtonKind) -> Self { - self.kind = val; - self - } -} - #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub enum InlineKeyboardButtonKind { @@ -113,16 +88,17 @@ pub enum InlineKeyboardButtonKind { Pay(True), } -/// Build buttons. -/// -/// # Examples -/// ``` -/// use teloxide_core::types::InlineKeyboardButton; -/// -/// let url = url::Url::parse("https://example.com").unwrap(); -/// let url_button = InlineKeyboardButton::url("Text".to_string(), url); -/// ``` impl InlineKeyboardButton { + pub fn new(text: S, kind: InlineKeyboardButtonKind) -> Self + where + S: Into, + { + Self { + text: text.into(), + kind, + } + } + pub fn url(text: T, url: reqwest::Url) -> InlineKeyboardButton where T: Into, @@ -133,6 +109,16 @@ impl InlineKeyboardButton { } } + pub fn login(text: T, url: LoginUrl) -> InlineKeyboardButton + where + T: Into, + { + InlineKeyboardButton { + text: text.into(), + kind: InlineKeyboardButtonKind::LoginUrl(url), + } + } + pub fn callback(text: T, callback_data: C) -> InlineKeyboardButton where T: Into, @@ -144,6 +130,16 @@ impl InlineKeyboardButton { } } + pub fn web_app(text: T, info: WebAppInfo) -> InlineKeyboardButton + where + T: Into, + { + InlineKeyboardButton { + text: text.into(), + kind: InlineKeyboardButtonKind::WebApp(info), + } + } + pub fn switch_inline_query(text: T, switch_inline_query: Q) -> InlineKeyboardButton where T: Into, @@ -170,4 +166,37 @@ impl InlineKeyboardButton { ), } } + + pub fn callback_game(text: T, game: CallbackGame) -> InlineKeyboardButton + where + T: Into, + { + InlineKeyboardButton { + text: text.into(), + kind: InlineKeyboardButtonKind::CallbackGame(game), + } + } + + pub fn pay(text: T) -> InlineKeyboardButton + where + T: Into, + { + InlineKeyboardButton { + text: text.into(), + kind: InlineKeyboardButtonKind::Pay(True), + } + } + + pub fn text(mut self, val: S) -> Self + where + S: Into, + { + self.text = val.into(); + self + } + + pub fn kind(mut self, val: InlineKeyboardButtonKind) -> Self { + self.kind = val; + self + } }