diff --git a/src/CasaBot/CasaBotApp/BotHandler.cs b/src/CasaBot/CasaBotApp/BotHandler.cs
index 901bacb..1054684 100644
--- a/src/CasaBot/CasaBotApp/BotHandler.cs
+++ b/src/CasaBot/CasaBotApp/BotHandler.cs
@@ -73,7 +73,11 @@ public class BotHandler : IUpdateHandler
_logger.LogInformation("User {Id} subscribed to receive messages", id);
}
- public async Task Update(string message)
+ ///
+ /// Send text message to all subscribers
+ ///
+ ///
+ public async Task UpdateText(string message)
{
if (_subscribers.Count == 0)
{
@@ -99,7 +103,10 @@ public class BotHandler : IUpdateHandler
}
-
+ ///
+ /// Send photo to all subscribers
+ ///
+ ///
public async Task UpdatePhoto(string path)
{
@@ -116,20 +123,12 @@ public class BotHandler : IUpdateHandler
}
}
- public async Task SendVideo(long chatId, string path)
- {
- _logger.LogInformation("Sending video to {ChatId}", chatId);
- await using var stream = File.OpenRead(path);
- var send = new SendVideoFile(chatId.ToString(), stream);
- var response = await _bot.HandleAsync(send);
- if (!response.Ok)
- {
- _logger.LogError("Error sending video.");
- }
- _logger.LogInformation("Video sent to {ChatId}", chatId);
- stream.Close();
- }
+
+ ///
+ /// Send photos to all subscribers
+ ///
+ ///
public async Task UpdatePhotos(string[] paths)
{
if (_subscribers.Count == 0)
@@ -205,6 +204,19 @@ public class BotHandler : IUpdateHandler
///
///
public async Task SendPhotos(long chatId, string[] paths)
+ {
+ var groups = paths.Select((x, i) => (x, i))
+ .GroupBy(x => x.i / 10)
+ .Select(x => x.Select(y => y.x).ToArray())
+ .ToArray();
+
+ foreach(var group in groups)
+ {
+ await SendPhotosInt(chatId, group);
+ }
+ }
+
+ private async Task SendPhotosInt(long chatId, string[] paths)
{
var streams = paths.Select(File.OpenRead).ToArray();
var photos = streams.Select(stream => new PhotoFile(stream)
@@ -226,6 +238,38 @@ public class BotHandler : IUpdateHandler
}
}
+ ///
+ /// Send Text Message to a specific chat
+ ///
+ ///
+ ///
+ public async Task SendText(long chatId, string textMessage)
+ {
+ var response = await SndTxt(chatId, textMessage);
+ if (!response.Ok)
+ {
+ _logger.LogError("Error sending message to {ChatId}", chatId);
+ }
+ }
+
+ ///
+ /// Send single video to a specific chat
+ ///
+ ///
+ ///
+ public async Task SendVideo(long chatId, string path)
+ {
+ _logger.LogInformation("Sending video to {ChatId}", chatId);
+ await using var stream = File.OpenRead(path);
+ var send = new SendVideoFile(chatId.ToString(), stream);
+ var response = await _bot.HandleAsync(send);
+ if (!response.Ok)
+ {
+ _logger.LogError("Error sending video.");
+ }
+ _logger.LogInformation("Video sent to {ChatId}", chatId);
+ stream.Close();
+ }
private async Task OnMessage(TextMessage msg)
@@ -306,4 +350,5 @@ public class BotHandler : IUpdateHandler
}
}
+
}
\ No newline at end of file
diff --git a/src/CasaBot/CasaBotApp/appsettings.Docker.json b/src/CasaBot/CasaBotApp/appsettings.Docker.json
index 7a559bd..37242d2 100644
--- a/src/CasaBot/CasaBotApp/appsettings.Docker.json
+++ b/src/CasaBot/CasaBotApp/appsettings.Docker.json
@@ -33,5 +33,7 @@
"DetectionFolder": "./media/detections/",
"RunDry": false
}
- }
+ },
+ "RemoveOriginalFiles": true,
+ "RemoveDetectionFiles": false
}
\ No newline at end of file