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\"/>
|
<Folder Include="Data\Migrations\"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\JOBot.Infrastructure\JOBot.Infrastructure.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
@ -3,6 +3,7 @@ using System.Text.Json;
|
|||||||
using JOBot.Backend.DAL.Context;
|
using JOBot.Backend.DAL.Context;
|
||||||
using JOBot.Backend.DTOs.HeadHunterHook;
|
using JOBot.Backend.DTOs.HeadHunterHook;
|
||||||
using JOBot.Backend.Infrastructure.Config;
|
using JOBot.Backend.Infrastructure.Config;
|
||||||
|
using JOBot.Infrastructure.Config;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using RabbitMQ.Client;
|
using RabbitMQ.Client;
|
||||||
|
@ -2,6 +2,7 @@ using JOBot.Backend.DAL.Context;
|
|||||||
using JOBot.Backend.Infrastructure.Config;
|
using JOBot.Backend.Infrastructure.Config;
|
||||||
using JOBot.Backend.Services;
|
using JOBot.Backend.Services;
|
||||||
using JOBot.Backend.Services.gRPC;
|
using JOBot.Backend.Services.gRPC;
|
||||||
|
using JOBot.Infrastructure.Config;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using RabbitMQ.Client;
|
using RabbitMQ.Client;
|
||||||
|
|
||||||
@ -22,8 +23,13 @@ public class Startup(IConfiguration configuration)
|
|||||||
{
|
{
|
||||||
HostName = "jobot-rabbitmq"
|
HostName = "jobot-rabbitmq"
|
||||||
}.CreateConnectionAsync();
|
}.CreateConnectionAsync();
|
||||||
await using var channel = await rabbitMqConnection.CreateChannelAsync();
|
var channel = await rabbitMqConnection.CreateChannelAsync();
|
||||||
await channel.QueueDeclareAsync(RabbitQueues.AuthQueue, false, false, false);
|
await channel.QueueDeclareAsync(
|
||||||
|
RabbitQueues.AuthQueue,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
arguments: null);
|
||||||
services.AddSingleton(channel);
|
services.AddSingleton(channel);
|
||||||
|
|
||||||
services.AddDbContext<AppDbContext>(options =>
|
services.AddDbContext<AppDbContext>(options =>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
namespace JOBot.Backend.Infrastructure.Config;
|
namespace JOBot.Infrastructure.Config;
|
||||||
|
|
||||||
public static class RabbitQueues
|
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>
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\JOBot.Infrastructure\JOBot.Infrastructure.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</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);
|
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)
|
public async Task SelectCv(Update update, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(update.Message?.From);
|
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
|
cancellationToken: ct); //TODO: https://git.lisoveliy.su/Lisoveliy/JOBot/issues/9
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,19 +1,23 @@
|
|||||||
using Grpc.Core;
|
using Grpc.Core;
|
||||||
using Grpc.Net.Client;
|
using Grpc.Net.Client;
|
||||||
|
using JOBot.Infrastructure.Config;
|
||||||
using JOBot.Proto;
|
using JOBot.Proto;
|
||||||
using JOBot.TClient.Commands.Buttons;
|
using JOBot.TClient.Commands.Buttons;
|
||||||
using JOBot.TClient.Commands.Commands;
|
using JOBot.TClient.Commands.Commands;
|
||||||
using JOBot.TClient.Core.HostedServices;
|
using JOBot.TClient.Core.HostedServices;
|
||||||
|
using JOBot.TClient.Queues;
|
||||||
using JOBot.TClient.Services;
|
using JOBot.TClient.Services;
|
||||||
using JOBot.TClient.Statements;
|
using JOBot.TClient.Statements;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using RabbitMQ.Client;
|
||||||
|
using RabbitMQ.Client.Events;
|
||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
|
|
||||||
namespace JOBot.TClient;
|
namespace JOBot.TClient;
|
||||||
|
|
||||||
public static class DependencyInjection
|
public static class Startup
|
||||||
{
|
{
|
||||||
public static IServiceCollection ConfigureServices(this IServiceCollection services, IConfiguration config)
|
public static IServiceCollection ConfigureServices(this IServiceCollection services, IConfiguration config)
|
||||||
{
|
{
|
||||||
@ -53,6 +57,23 @@ public static class DependencyInjection
|
|||||||
|
|
||||||
#endregion
|
#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
|
// Bot service
|
||||||
services.AddHostedService<BotBackgroundService>();
|
services.AddHostedService<BotBackgroundService>();
|
||||||
services.AddSingleton<ITelegramBotClient>(_ =>
|
services.AddSingleton<ITelegramBotClient>(_ =>
|
14
JOBot.sln
14
JOBot.sln
@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JOBot.Backend", "JOBot.Back
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JOBot.TClient", "JOBot.TClient\JOBot.TClient.csproj", "{4526BCB1-DAD3-430C-BD7C-9C114DFE9A2A}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JOBot.TClient", "JOBot.TClient\JOBot.TClient.csproj", "{4526BCB1-DAD3-430C-BD7C-9C114DFE9A2A}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JOBot.Infrastructure", "JOBot.Infrastructure\JOBot.Infrastructure.csproj", "{32006B71-E6F7-4264-A8B4-AC3A6B77CC54}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
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|x64.Build.0 = Release|Any CPU
|
||||||
{4526BCB1-DAD3-430C-BD7C-9C114DFE9A2A}.Release|x86.ActiveCfg = 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
|
{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
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user