diff --git a/src/CasaBot/CasaBotApp/BotHandler.cs b/src/CasaBot/CasaBotApp/BotHandler.cs index 6b65e30..c6fdf50 100644 --- a/src/CasaBot/CasaBotApp/BotHandler.cs +++ b/src/CasaBot/CasaBotApp/BotHandler.cs @@ -32,7 +32,7 @@ public class BotHandler { _logger.LogInformation("Starting bot..."); _bot = new TelegramBotClient(_botConfiguration.Token, cancellationToken: cancellationToken); - // var me = await _bot.GetMe(); + _bot.OnError += OnError; _bot.OnMessage += OnMessage; @@ -69,11 +69,7 @@ public class BotHandler await using var stream = File.OpenRead(@"C:\Users\GuillermoMarcel\Pictures\prueba.jpeg"); var inputFile = InputFile.FromStream(stream, "gorda.jpeg"); - // var message = await _bot.SendPhotoAsync(new ChatId(id), new InputOnlineFile(stream, "prueba.jpeg")); - // await _bot.SendDocument(new ChatId(id), document: inputFile, caption: "imagen de prueba"); - // await _bot.SendPhoto(new ChatId(id), - // "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/6.png", "Wild charizard"); - + await _bot.SendPhoto(new ChatId(id), inputFile, "mi gorda"); } @@ -84,7 +80,7 @@ public class BotHandler return Task.CompletedTask; } -// method that handle messages received by the bot: + private async Task OnMessage(Message msg, UpdateType type) { if (_bot is null) diff --git a/src/CasaBot/CasaBotApp/Program.cs b/src/CasaBot/CasaBotApp/Program.cs index cc95872..bfdbc70 100644 --- a/src/CasaBot/CasaBotApp/Program.cs +++ b/src/CasaBot/CasaBotApp/Program.cs @@ -27,11 +27,6 @@ serviceCollection.AddSingleton(); var serviceProvider = serviceCollection.BuildServiceProvider(); - -// var url = "https://api.telegram.org/bot/getMe"; - -// var token = ; - var botHandler = serviceProvider.GetService(); if (botHandler is null) { @@ -43,23 +38,15 @@ using var cts = new CancellationTokenSource(); botHandler.Start(cts.Token); -// call the bot handler to send a message every minute to the subscribers _ = SendMessageToSubscribers(cts.Token); -// var bot = new TelegramBotClient(token, cancellationToken: cts.Token); -// var me = await bot.GetMe(); -// -// bot.OnError += OnError; -// bot.OnMessage += OnMessage; -// bot.OnUpdate += OnUpdate; -// Console.WriteLine($"bot is running... Press Enter to terminate"); Console.ReadLine(); cts.Cancel(); // stop the bot return; -//async method to send a message to the subscribers every two minutes with the current time + async Task SendMessageToSubscribers(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested)