feat: added auth hook using RabbitMQ on client for login continue
This commit is contained in:
parent
d2280cdc5b
commit
f115760713
@ -31,4 +31,8 @@
|
||||
<Folder Include="Data\Migrations\"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\JOBot.Infrastructure\JOBot.Infrastructure.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -3,6 +3,7 @@ using System.Text.Json;
|
||||
using JOBot.Backend.DAL.Context;
|
||||
using JOBot.Backend.DTOs.HeadHunterHook;
|
||||
using JOBot.Backend.Infrastructure.Config;
|
||||
using JOBot.Infrastructure.Config;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using RabbitMQ.Client;
|
||||
|
@ -2,6 +2,7 @@ using JOBot.Backend.DAL.Context;
|
||||
using JOBot.Backend.Infrastructure.Config;
|
||||
using JOBot.Backend.Services;
|
||||
using JOBot.Backend.Services.gRPC;
|
||||
using JOBot.Infrastructure.Config;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using RabbitMQ.Client;
|
||||
|
||||
@ -22,8 +23,13 @@ public class Startup(IConfiguration configuration)
|
||||
{
|
||||
HostName = "jobot-rabbitmq"
|
||||
}.CreateConnectionAsync();
|
||||
await using var channel = await rabbitMqConnection.CreateChannelAsync();
|
||||
await channel.QueueDeclareAsync(RabbitQueues.AuthQueue, false, false, false);
|
||||
var channel = await rabbitMqConnection.CreateChannelAsync();
|
||||
await channel.QueueDeclareAsync(
|
||||
RabbitQueues.AuthQueue,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
arguments: null);
|
||||
services.AddSingleton(channel);
|
||||
|
||||
services.AddDbContext<AppDbContext>(options =>
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace JOBot.Backend.Infrastructure.Config;
|
||||
namespace JOBot.Infrastructure.Config;
|
||||
|
||||
public static class RabbitQueues
|
||||
{
|
9
JOBot.Infrastructure/JOBot.Infrastructure.csproj
Normal file
9
JOBot.Infrastructure/JOBot.Infrastructure.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
@ -64,4 +64,8 @@
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\JOBot.Infrastructure\JOBot.Infrastructure.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
26
JOBot.TClient/Queues/AuthQueue.cs
Normal file
26
JOBot.TClient/Queues/AuthQueue.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System.Text;
|
||||
using JOBot.Infrastructure.Config;
|
||||
using JOBot.TClient.Services;
|
||||
using RabbitMQ.Client;
|
||||
using RabbitMQ.Client.Events;
|
||||
|
||||
namespace JOBot.TClient.Queues;
|
||||
|
||||
public class AuthQueue
|
||||
{
|
||||
private readonly PrepareUserService _prepareUserService;
|
||||
public AuthQueue(
|
||||
IChannel channel, PrepareUserService prepareUserService)
|
||||
{
|
||||
_prepareUserService = prepareUserService;
|
||||
|
||||
var consumer = new AsyncEventingBasicConsumer(channel);
|
||||
consumer.ReceivedAsync += OnDataReceivedAsync;
|
||||
channel.BasicConsumeAsync(RabbitQueues.AuthQueue, autoAck: true, consumer: consumer);
|
||||
}
|
||||
|
||||
private async Task OnDataReceivedAsync(object sender, BasicDeliverEventArgs eventArgs)
|
||||
{
|
||||
await _prepareUserService.SelectCv(Convert.ToInt64(Encoding.UTF8.GetString(eventArgs.Body.ToArray())));
|
||||
}
|
||||
}
|
@ -99,11 +99,22 @@ public class PrepareUserService(ITelegramBotClient bot, User.UserClient userClie
|
||||
cancellationToken: ct);
|
||||
}
|
||||
|
||||
public async Task AuthHookReceived(long userId, CancellationToken ct = default)
|
||||
{
|
||||
await _bot.SendMessage(userId, "Авторизация завершена успешно!", cancellationToken: ct);
|
||||
await SelectCv(userId, ct);
|
||||
}
|
||||
|
||||
public async Task SelectCv(Update update, CancellationToken ct = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(update.Message?.From);
|
||||
|
||||
await _bot.SendMessage(update.Message.From.Id, "Давайте выберем одно из доступных резюме:",
|
||||
await SelectCv(update.Message.From.Id, ct);
|
||||
}
|
||||
|
||||
public async Task SelectCv(long userId, CancellationToken ct = default)
|
||||
{
|
||||
await _bot.SendMessage(userId, "Давайте выберем одно из доступных резюме:",
|
||||
cancellationToken: ct); //TODO: https://git.lisoveliy.su/Lisoveliy/JOBot/issues/9
|
||||
}
|
||||
}
|
@ -1,19 +1,23 @@
|
||||
using Grpc.Core;
|
||||
using Grpc.Net.Client;
|
||||
using JOBot.Infrastructure.Config;
|
||||
using JOBot.Proto;
|
||||
using JOBot.TClient.Commands.Buttons;
|
||||
using JOBot.TClient.Commands.Commands;
|
||||
using JOBot.TClient.Core.HostedServices;
|
||||
using JOBot.TClient.Queues;
|
||||
using JOBot.TClient.Services;
|
||||
using JOBot.TClient.Statements;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using RabbitMQ.Client;
|
||||
using RabbitMQ.Client.Events;
|
||||
using Telegram.Bot;
|
||||
|
||||
namespace JOBot.TClient;
|
||||
|
||||
public static class DependencyInjection
|
||||
public static class Startup
|
||||
{
|
||||
public static IServiceCollection ConfigureServices(this IServiceCollection services, IConfiguration config)
|
||||
{
|
||||
@ -53,6 +57,23 @@ public static class DependencyInjection
|
||||
|
||||
#endregion
|
||||
|
||||
#region RabbitMQ Clients
|
||||
|
||||
var factory = new ConnectionFactory { HostName = "localhost" };
|
||||
using var connection = factory.CreateConnectionAsync().Result;
|
||||
var channel = connection.CreateChannelAsync().Result;
|
||||
|
||||
channel.QueueDeclareAsync(
|
||||
RabbitQueues.AuthQueue,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
arguments: null).Wait();
|
||||
|
||||
services.AddSingleton<AuthQueue>();
|
||||
|
||||
#endregion
|
||||
|
||||
// Bot service
|
||||
services.AddHostedService<BotBackgroundService>();
|
||||
services.AddSingleton<ITelegramBotClient>(_ =>
|
14
JOBot.sln
14
JOBot.sln
@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JOBot.Backend", "JOBot.Back
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JOBot.TClient", "JOBot.TClient\JOBot.TClient.csproj", "{4526BCB1-DAD3-430C-BD7C-9C114DFE9A2A}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JOBot.Infrastructure", "JOBot.Infrastructure\JOBot.Infrastructure.csproj", "{32006B71-E6F7-4264-A8B4-AC3A6B77CC54}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -41,6 +43,18 @@ Global
|
||||
{4526BCB1-DAD3-430C-BD7C-9C114DFE9A2A}.Release|x64.Build.0 = Release|Any CPU
|
||||
{4526BCB1-DAD3-430C-BD7C-9C114DFE9A2A}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{4526BCB1-DAD3-430C-BD7C-9C114DFE9A2A}.Release|x86.Build.0 = Release|Any CPU
|
||||
{32006B71-E6F7-4264-A8B4-AC3A6B77CC54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{32006B71-E6F7-4264-A8B4-AC3A6B77CC54}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{32006B71-E6F7-4264-A8B4-AC3A6B77CC54}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{32006B71-E6F7-4264-A8B4-AC3A6B77CC54}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{32006B71-E6F7-4264-A8B4-AC3A6B77CC54}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{32006B71-E6F7-4264-A8B4-AC3A6B77CC54}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{32006B71-E6F7-4264-A8B4-AC3A6B77CC54}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{32006B71-E6F7-4264-A8B4-AC3A6B77CC54}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{32006B71-E6F7-4264-A8B4-AC3A6B77CC54}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{32006B71-E6F7-4264-A8B4-AC3A6B77CC54}.Release|x64.Build.0 = Release|Any CPU
|
||||
{32006B71-E6F7-4264-A8B4-AC3A6B77CC54}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{32006B71-E6F7-4264-A8B4-AC3A6B77CC54}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
Loading…
x
Reference in New Issue
Block a user