diff --git a/Directory.Packages.props b/Directory.Packages.props
index 1c1c502..7ab0600 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -6,6 +6,15 @@
8.0.0
0.16.0
+
+
+
+
+
+
+
+
+
diff --git a/src/Nocr.TelegramClient.AppServices/Matches/TextMatchMatchedHandler.cs b/src/Nocr.TelegramClient.AppServices/Matches/TextMatchMatchedHandler.cs
new file mode 100644
index 0000000..41e4924
--- /dev/null
+++ b/src/Nocr.TelegramClient.AppServices/Matches/TextMatchMatchedHandler.cs
@@ -0,0 +1,26 @@
+using Insight.TelegramBot;
+using Insight.TelegramBot.Models;
+using Nocr.TextMatcher.Async.Api.Contracts;
+using Rebus.Handlers;
+
+namespace Nocr.TelegramClient.AppServices.Matches;
+
+public class TextMatchMatchedHandler : IHandleMessages
+{
+ private readonly IBot _bot;
+
+ public TextMatchMatchedHandler(IBot bot)
+ {
+ _bot = bot ?? throw new ArgumentNullException(nameof(bot));
+ }
+
+ public async Task Handle(TextMatchMatched message)
+ {
+ var textMessage = new TextMessage(58874635)
+ {
+ Text = $"[{message.PublishedDateTime:MM.dd.yyyy HH:mm:ss}] Найдено совпадение.\n @{message.ChatUsername} > {message.Text}"
+ };
+
+ await _bot.SendMessageAsync(textMessage);
+ }
+}
\ No newline at end of file
diff --git a/src/Nocr.TelegramClient.AppServices/Nocr.TelegramClient.AppServices.csproj b/src/Nocr.TelegramClient.AppServices/Nocr.TelegramClient.AppServices.csproj
index cc9779f..d349003 100644
--- a/src/Nocr.TelegramClient.AppServices/Nocr.TelegramClient.AppServices.csproj
+++ b/src/Nocr.TelegramClient.AppServices/Nocr.TelegramClient.AppServices.csproj
@@ -1,9 +1,15 @@
+
+ false
+
+
+
+
diff --git a/src/Nocr.TelegramClient.AppServices/ServiceCollectionExtensions.cs b/src/Nocr.TelegramClient.AppServices/ServiceCollectionExtensions.cs
index 6913c9a..aef691c 100644
--- a/src/Nocr.TelegramClient.AppServices/ServiceCollectionExtensions.cs
+++ b/src/Nocr.TelegramClient.AppServices/ServiceCollectionExtensions.cs
@@ -1,4 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
+using Nocr.TelegramClient.AppServices.Matches;
+using Rebus.Config;
namespace Nocr.TelegramClient.AppServices;
@@ -10,7 +12,8 @@ public static class ServiceCollectionExtensions
throw new ArgumentNullException(nameof(services));
// Add registrations here
-
+ services.AddRebusHandler();
+
return services;
}
}
\ No newline at end of file
diff --git a/src/Nocr.TelegramClient.Core/Options/RebusRabbitMqOptions.cs b/src/Nocr.TelegramClient.Core/Options/RebusRabbitMqOptions.cs
new file mode 100644
index 0000000..f303d40
--- /dev/null
+++ b/src/Nocr.TelegramClient.Core/Options/RebusRabbitMqOptions.cs
@@ -0,0 +1,12 @@
+namespace Nocr.TelegramClient.Core.Options;
+
+public sealed class RebusRabbitMqOptions
+{
+ public string ConnectionString { get; set; }
+
+ public string InputQueueName { get; set; }
+
+ public string DirectExchangeName { get; set; }
+
+ public string TopicsExchangeName { get; set; }
+}
\ No newline at end of file
diff --git a/src/Nocr.TelegramClient.Host/Infrastructure/HostBuilderFactory.cs b/src/Nocr.TelegramClient.Host/Infrastructure/HostBuilderFactory.cs
index 33b7b74..dee0d8f 100644
--- a/src/Nocr.TelegramClient.Host/Infrastructure/HostBuilderFactory.cs
+++ b/src/Nocr.TelegramClient.Host/Infrastructure/HostBuilderFactory.cs
@@ -12,7 +12,7 @@ public class HostBuilderFactory where TStartup : class
if (!string.IsNullOrWhiteSpace(baseDirectory))
configurationBuilder.SetBasePath(baseDirectory);
- configurationBuilder.AddJsonFile("appsettings.protected.json", false);
+ configurationBuilder.AddJsonFile("appsettings.protected.json", true);
})
.ConfigureWebHostDefaults(host => { host.UseStartup(); })
.UseSerilog((ctx, logBuilder) =>
diff --git a/src/Nocr.TelegramClient.Host/Infrastructure/Startup.cs b/src/Nocr.TelegramClient.Host/Infrastructure/Startup.cs
index 1f04501..4eb38e4 100644
--- a/src/Nocr.TelegramClient.Host/Infrastructure/Startup.cs
+++ b/src/Nocr.TelegramClient.Host/Infrastructure/Startup.cs
@@ -5,6 +5,11 @@ using Insight.TelegramBot.Hosting.Polling.ExceptionHandlers;
using Microsoft.Extensions.Options;
using Nocr.TelegramClient.AppServices;
using Nocr.TelegramClient.Core.Dates;
+using Nocr.TelegramClient.Core.Options;
+using Rebus.Bus;
+using Rebus.Config;
+using Rebus.Routing.TypeBased;
+using Rebus.Serialization.Json;
namespace Nocr.TelegramClient.Host.Infrastructure;
@@ -30,9 +35,24 @@ public class Startup
.WithPolling(polling => polling.WithExceptionHandler()));
services.AddTelegramBotHandling(typeof(BotClient).Assembly);
services.AddAppServices();
+
+ services.Configure(Configuration.GetSection(nameof(RebusRabbitMqOptions)));
+ services.AddRebus((builder, ctx) =>
+ builder.Transport(t =>
+ {
+ var rebusOptions = ctx.GetRequiredService>().Value;
+ t.UseRabbitMq(rebusOptions.ConnectionString, rebusOptions.InputQueueName)
+ .DefaultQueueOptions(queue => queue.SetDurable(true))
+ .ExchangeNames(rebusOptions.DirectExchangeName, rebusOptions.TopicsExchangeName);
+ })
+ .Serialization(s => s.UseSystemTextJson())
+ .Logging(l => l.Serilog())
+ .Routing(r => r.TypeBased()));
}
public void Configure(IApplicationBuilder app)
{
+ var bus = app.ApplicationServices.GetRequiredService();
+ bus.Advanced.Topics.Subscribe("nocr.text.matcher.matched").GetAwaiter().GetResult();
}
}
\ No newline at end of file
diff --git a/src/Nocr.TelegramClient.Host/Nocr.TelegramClient.Host.csproj b/src/Nocr.TelegramClient.Host/Nocr.TelegramClient.Host.csproj
index 3de9bfa..3e5111d 100644
--- a/src/Nocr.TelegramClient.Host/Nocr.TelegramClient.Host.csproj
+++ b/src/Nocr.TelegramClient.Host/Nocr.TelegramClient.Host.csproj
@@ -9,15 +9,20 @@
-
-
-
+
+
+
-
- .dockerignore
-
+
+
-
+
+
+
+ .dockerignore
+
+
+
diff --git a/src/Nocr.TelegramClient.Host/appsettings.Development.json b/src/Nocr.TelegramClient.Host/appsettings.Development.json
index fdf6b48..2d26fac 100644
--- a/src/Nocr.TelegramClient.Host/appsettings.Development.json
+++ b/src/Nocr.TelegramClient.Host/appsettings.Development.json
@@ -8,5 +8,8 @@
}
}
]
+ },
+ "RebusRabbitMqOptions": {
+ "ConnectionString": "amqp://admin:admin@localhost:5672/"
}
}
diff --git a/src/Nocr.TelegramClient.Host/appsettings.DockerCompose.json b/src/Nocr.TelegramClient.Host/appsettings.DockerCompose.json
new file mode 100644
index 0000000..c6ccd78
--- /dev/null
+++ b/src/Nocr.TelegramClient.Host/appsettings.DockerCompose.json
@@ -0,0 +1,5 @@
+{
+ "RebusRabbitMqOptions": {
+ "ConnectionString": "amqp://admin:admin@nocr-rabbitmq:5672/"
+ }
+}
\ No newline at end of file
diff --git a/src/Nocr.TelegramClient.Host/appsettings.json b/src/Nocr.TelegramClient.Host/appsettings.json
index ff9ad20..1b0eb19 100644
--- a/src/Nocr.TelegramClient.Host/appsettings.json
+++ b/src/Nocr.TelegramClient.Host/appsettings.json
@@ -8,5 +8,10 @@
"System.Net.Http.HttpClient": "Warning"
}
}
+ },
+ "RebusRabbitMqOptions": {
+ "InputQueueName": "nocr.telegram.client.queue",
+ "DirectExchangeName": "nocr.direct",
+ "TopicsExchangeName": "nocr.topics"
}
}