diff --git a/src/types/message.rs b/src/types/message.rs index bc8138d9..e4621dde 100644 --- a/src/types/message.rs +++ b/src/types/message.rs @@ -796,7 +796,7 @@ mod getters { } impl Message { - pub fn url(&self) -> Option { + pub fn url(&self) -> Option { match &self.chat.kind { ChatKind::NonPrivate { kind: @@ -812,7 +812,7 @@ impl Message { .. }, .. - } => Some(format!("https://t.me/{0}/{1}/", username, self.id)), + } => Some(reqwest::Url::parse(format!("https://t.me/{0}/{1}/", username, self.id).as_str()).unwrap()), _ => None, } } diff --git a/src/types/user.rs b/src/types/user.rs index a065eca0..26455ab2 100644 --- a/src/types/user.rs +++ b/src/types/user.rs @@ -40,8 +40,8 @@ impl User { Some(format!("@{}", self.username.as_ref()?)) } - pub fn url(&self) -> String { - format!("tg://user?id={}", self.id) + pub fn url(&self) -> reqwest::Url { + reqwest::Url::parse(format!("tg://user/?id={}", self.id).as_str()).unwrap() } } diff --git a/src/utils/html.rs b/src/utils/html.rs index d9aefe7d..94d7c8ec 100644 --- a/src/utils/html.rs +++ b/src/utils/html.rs @@ -89,7 +89,7 @@ pub fn escape(s: &str) -> String { pub fn user_mention_or_link(user: &User) -> String { match user.mention() { Some(mention) => mention, - None => link(&user.url(), &user.full_name()), + None => link(user.url().as_str(), &user.full_name()), } } @@ -209,7 +209,7 @@ mod tests { }; assert_eq!( user_mention_or_link(&user_without_username), - r#"Name"# + r#"Name"# ) } } diff --git a/src/utils/markdown.rs b/src/utils/markdown.rs index f39443fd..429db900 100644 --- a/src/utils/markdown.rs +++ b/src/utils/markdown.rs @@ -123,7 +123,7 @@ pub fn escape_code(s: &str) -> String { pub fn user_mention_or_link(user: &User) -> String { match user.mention() { Some(mention) => mention, - None => link(&user.url(), &user.full_name()), + None => link(user.url().as_str(), &user.full_name()), } } @@ -271,7 +271,7 @@ mod tests { }; assert_eq!( user_mention_or_link(&user_without_username), - r#"[Name](tg://user?id=123456789)"# + r#"[Name](tg://user/?id=123456789)"# ) } } diff --git a/src/utils/parsers.rs b/src/utils/parsers.rs index 47501559..dae95d9a 100644 --- a/src/utils/parsers.rs +++ b/src/utils/parsers.rs @@ -54,7 +54,7 @@ where /// use teloxide::utils::parse_command; /// let text = "/ban 5 hours"; /// let (command, args) = parse_command(text).unwrap(); -/// assert_eq!(command, "ban"); +/// assert_eq!(command, "/ban"); /// assert_eq!(args, vec!["5", "hours"]); /// ``` pub fn parse_command(text: &str) -> Option<(&str, Vec<&str>)> {