diff --git a/src/CasaBot/CasaBotApp/BotHandler.cs b/src/CasaBot/CasaBotApp/BotHandler.cs index c6fdf50..6f2d724 100644 --- a/src/CasaBot/CasaBotApp/BotHandler.cs +++ b/src/CasaBot/CasaBotApp/BotHandler.cs @@ -58,7 +58,40 @@ public class BotHandler _bot.SendMessage(subscriber, message); } } + + public void Subscribe(long id) + { + if (_subscribers.Any(s => s.Identifier == id)) + { + _logger.LogWarning("User {Id} is already subscribed", id); + return; + } + _subscribers.Add(new ChatId(id)); + _logger.LogInformation("User {Id} subscribed to receive messages", id); + } + + public async Task UpdatePhoto(string path) + { + if (_bot is null) + { + _logger.LogWarning("Bot is not initialized yet"); + return; + } + + if (_subscribers.Count == 0) + { + _logger.LogWarning("No subscribers to send message to"); + return; + } + + foreach (var subscriber in _subscribers) + { + await using var stream = File.OpenRead(path); + var inputFile = InputFile.FromStream(stream, Path.GetFileName(path)); + await _bot.SendPhoto(subscriber, inputFile, "Detected object"); + } + } private async Task SendImageTest(long id) { if (_bot is null)