tg_flows/types/login_url.rs
1use serde::{Deserialize, Serialize};
2
3/// This object represents a parameter of the inline keyboard button used to
4/// automatically authorize a user.
5///
6/// Serves as a great replacement for the [Telegram Login Widget] when the user
7/// is coming from Telegram. All the user needs to do is tap/click a button and
8/// confirm that they want to log in:
9///
10/// <div align="center">
11/// <img src="https://core.telegram.org/file/811140015/1734/8VZFkwWXalM.97872/6127fa62d8a0bf2b3c" width=300 />
12/// </div>
13///
14/// [Telegram Login Widget]: https://core.telegram.org/widgets/login
15#[serde_with_macros::skip_serializing_none]
16#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
17pub struct LoginUrl {
18 /// An HTTPS URL to be opened with user authorization data added to the
19 /// query string when the button is pressed. If the user refuses to
20 /// provide authorization data, the original URL without information
21 /// about the user will be opened. The data added is the same as
22 /// described in [Receiving authorization data].
23 ///
24 /// [Receiving authorization data]: https://core.telegram.org/widgets/login#receiving-authorization-data
25 ///
26 /// NOTE: You must always check the hash of the received data to verify the
27 /// authentication and the integrity of the data as described in [Checking
28 /// authorization].
29 ///
30 /// [Checking authorization]: https://core.telegram.org/widgets/login#checking-authorization
31 pub url: url::Url,
32 /// New text of the button in forwarded messages.
33 pub forward_text: Option<String>,
34 /// Username of a bot, which will be used for user authorization. See
35 /// [Setting up a bot] for more details. If not specified, the current bot's
36 /// username will be assumed. The url's domain must be the same as the
37 /// domain linked with the bot. See [Linking your domain to the bot] for
38 /// more details.
39 ///
40 /// [Setting up a bot]: https://core.telegram.org/widgets/login#setting-up-a-bot
41 /// [Linking your domain to the bot]: https://core.telegram.org/widgets/login#linking-your-domain-to-the-bot
42 pub bot_username: Option<String>,
43 /// Pass `true` to request the permission for your bot to send messages to
44 /// the user.
45 pub request_write_access: Option<bool>,
46}
47
48impl LoginUrl {
49 #[must_use]
50 pub fn url(mut self, val: url::Url) -> Self {
51 self.url = val;
52 self
53 }
54
55 pub fn forward_text<S>(mut self, val: S) -> Self
56 where
57 S: Into<String>,
58 {
59 self.forward_text = Some(val.into());
60 self
61 }
62
63 pub fn bot_username<S>(mut self, val: S) -> Self
64 where
65 S: Into<String>,
66 {
67 self.bot_username = Some(val.into());
68 self
69 }
70
71 #[must_use]
72 pub fn request_write_access(mut self, val: bool) -> Self {
73 self.request_write_access = Some(val);
74 self
75 }
76}