feat: added auth hook using RabbitMQ on client for login continue
This commit is contained in:
@@ -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 SelectCv(update.Message.From.Id, ct);
|
||||
}
|
||||
|
||||
await _bot.SendMessage(update.Message.From.Id, "Давайте выберем одно из доступных резюме:",
|
||||
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>(_ =>
|
||||
Reference in New Issue
Block a user