diff --git a/BotNet.CommandHandlers/BotUpdate/Message/MessageUpdateHandler.cs b/BotNet.CommandHandlers/BotUpdate/Message/MessageUpdateHandler.cs index 75d4524..20b5745 100644 --- a/BotNet.CommandHandlers/BotUpdate/Message/MessageUpdateHandler.cs +++ b/BotNet.CommandHandlers/BotUpdate/Message/MessageUpdateHandler.cs @@ -44,16 +44,17 @@ await _commandQueue.DispatchAsync( // Handle Social Link (better preview) if ((update.Message.Text ?? update.Message.Caption) is { } textOrCaption) { - IEnumerable betterLinks = SocialLinkEmbedFixer.GetPossibleUrls(textOrCaption); + IEnumerable possibleUrls = SocialLinkEmbedFixer.GetPossibleUrls(textOrCaption); - if (betterLinks.Any()) { + if (possibleUrls.Any()) { // Fire and forget Task _ = Task.Run(async () => { try { - foreach (Uri betterLink in betterLinks) { + foreach (Uri url in possibleUrls) { + Uri fixedUrl = SocialLinkEmbedFixer.Fix(url); await _telegramBotClient.SendTextMessageAsync( chatId: update.Message.Chat.Id, - text: $"Preview: {betterLink.OriginalString}", + text: $"Preview: {fixedUrl.OriginalString}", replyToMessageId: update.Message.MessageId, cancellationToken: cancellationToken ); diff --git a/BotNet.Services/SocialLink/SocialLinkEmbedFixer.cs b/BotNet.Services/SocialLink/SocialLinkEmbedFixer.cs index d75fd3e..a307724 100644 --- a/BotNet.Services/SocialLink/SocialLinkEmbedFixer.cs +++ b/BotNet.Services/SocialLink/SocialLinkEmbedFixer.cs @@ -4,6 +4,12 @@ namespace BotNet.Services.SocialLink { public partial class SocialLinkEmbedFixer { + + /// + /// Fixes the given URI by replacing specific host names with new host names. + /// + /// The original URI to be fixed. + /// A new URI with the host names replaced. public static Uri Fix(Uri link) { string url = link.ToString(); string newUrl = link.Host switch { @@ -18,6 +24,11 @@ public static Uri Fix(Uri link) { return new Uri(newUrl); } + /// + /// Extracts possible URLs from the given message that match Twitter and Instagram patterns. + /// + /// The message to search for URLs. + /// An enumerable collection of URLs. public static IEnumerable GetPossibleUrls(string message) { MatchCollection twitterMatches = TwitterRegex().Matches(message); foreach (Match match in twitterMatches) {