Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LoginUrl #212

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions raw/src/types/reply_markup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ impl InlineKeyboardButton {
}
}

/// A login url
pub fn login_url<T: AsRef<str>>(text: T, login_url: LoginUrl) -> Self {
Self {
text: text.as_ref().to_string(),
kind: InlineKeyboardButtonKind::LoginUrl(login_url),
}
}

/// Pressing the button will prompt the user to select one of their chats, open that chat and
/// insert the bot‘s username and the specified inline query in the input field. Can be empty,
/// in which case just the bot’s username will be inserted.
Expand Down Expand Up @@ -289,8 +297,46 @@ pub enum InlineKeyboardButtonKind {
// CallbackGame(CallbackGame),
// #[serde(rename = "pay")]
// Pay,
// #[serde(rename = "login_url")]
// LoginUrl(LoginUrl),
#[serde(rename = "login_url")]
LoginUrl(LoginUrl),
}

/// Allows a user to be directly authorized by clicking the inline button
#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)]
pub struct LoginUrl {
url: String,
#[serde(skip_serializing_if = "Option::is_none")]
forward_text: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
bot_username: Option<String>,
#[serde(skip_serializing_if = "Not::not")]
request_write_access: bool,
}

impl LoginUrl {
pub fn new(url: impl AsRef<str>) -> LoginUrl {
LoginUrl {
url: url.as_ref().to_string(),
forward_text: None,
bot_username: None,
request_write_access: false,
}
}

pub fn forward_text(&mut self, forward_text: impl AsRef<str>) -> &mut LoginUrl {
self.forward_text = Some(forward_text.as_ref().to_string());
self
}

pub fn bot_username(&mut self, bot_username: impl AsRef<str>) -> &mut LoginUrl {
self.bot_username = Some(bot_username.as_ref().to_string());
self
}

pub fn request_write_access(&mut self, request_write_access: bool) -> &mut LoginUrl {
self.request_write_access = request_write_access;
self
}
}

/// Upon receiving a message with this object, Telegram clients will
Expand Down