feat: add subscription and photo sending to bot handler

This commit is contained in:
Guillermo Marcel 2025-02-13 19:12:46 -03:00
parent 2bbbc32322
commit c3fb8b9c6f

View File

@ -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)