public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args, CancellationToken cancellationToken) { _telegramService = new TelegramService(context); _rssService = new RssService(_telegramService.Message); var chatId = _telegramService.Message.Chat.Id; var url = _telegramService.Message.Text.GetTextWithoutCmd(); if (url != null) { await _telegramService.AppendTextAsync($"URL: {url}"); if (url.CheckUrlValid()) { await _telegramService.AppendTextAsync($"Sedang mengecek apakah berisi RSS"); var isValid = await url.IsValidUrlFeed(); if (!isValid) { await _telegramService.AppendTextAsync("Sedang mencari kemungkinan tautan RSS yang valid"); var foundUrl = await url.GetBaseUrl().FindUrlFeed(); Log.Information($"Found URL Feed: {foundUrl}"); if (foundUrl != "") { url = foundUrl; } else { var notfoundRss = $"Kami tidak dapat memvalidasi {url} adalah Link RSS yang valid, " + $"dan mencoba mencari di {url.GetBaseUrl()} tetap tidak dapat menemukan."; await _telegramService.EditAsync(notfoundRss); return; } } var isFeedExist = await _rssService.IsExistRssAsync(url); Log.Information($"Is Url Exist: {isFeedExist}"); if (!isFeedExist) { await _telegramService.AppendTextAsync($"Sedang menyimpan.."); var data = new Dictionary <string, object>() { { "url_feed", url }, { "chat_id", _telegramService.Message.Chat.Id }, { "from_id", _telegramService.Message.From.Id } }; await _rssService.SaveRssSettingAsync(data); await _telegramService.AppendTextAsync("Memastikan Scheduler sudah berjalan"); chatId.RegisterScheduler(); await _telegramService.AppendTextAsync($"Tautan berhasil di simpan"); } else { await _telegramService.AppendTextAsync($"Tautan sudah di simpan"); } } else { await _telegramService.AppendTextAsync("Url tersebut sepertinya tidak valid"); } } else { await _telegramService.SendTextAsync("Apa url Feednya?"); } }
public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args, CancellationToken cancellationToken) { ChatHelper.Init(context); _rssService = new RssService(ChatHelper.Message); var url = ChatHelper.Message.Text.GetTextWithoutCmd(); if (url != null) { await $"Sedang memeriksa {url}".AppendTextAsync(); if (url.CheckUrlValid()) { await $"Sedang memvalidasi {url}".AppendTextAsync(); var isValid = await url.IsValidUrlFeed(); if (!isValid) { await "Sedang mencari kemungkinan RSS yang valid".AppendTextAsync(); var foundUrl = await url.GetBaseUrl().FindUrlFeed(); ConsoleHelper.WriteLine($"Found URL Feed: {foundUrl}"); if (foundUrl != "") { url = foundUrl; } else { var notfoundRss = $"Kami tidak dapat memvalidasi {url} adalah Link RSS yang valid, " + $"dan mencoba mencari di {url.GetBaseUrl()} tetap tidak dapat menemukan."; await notfoundRss.EditAsync(); ChatHelper.Close(); return; } } var isFeedExist = await _rssService.IsExistRssAsync(url); ConsoleHelper.WriteLine($"Is Url Exist: {isFeedExist}"); if (!isFeedExist) { await $"Sedang menyimpan..".SendTextAsync(); var data = new Dictionary <string, object>() { { "url_feed", url }, { "chat_id", ChatHelper.Message.Chat.Id }, { "from_id", ChatHelper.Message.From.Id } }; await _rssService.SaveRssSettingAsync(data); await $"Url: {url} berhasil di simpan".EditAsync(); } else { await $"Url: {url} sudah di simpan".SendTextAsync(); } } else { await "Url tersebut sepertinya tidak valid".SendTextAsync(); } } else { await "Apa url Feednya?".SendTextAsync(); } ChatHelper.Close(); }