chore: cleanup
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root"
|
||||
xmlns="">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
|
||||
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
@@ -13,10 +14,14 @@
|
||||
<value>1.3</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
|
||||
PublicKeyToken=b77a5c561934e089
|
||||
</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
|
||||
PublicKeyToken=b77a5c561934e089
|
||||
</value>
|
||||
</resheader>
|
||||
<data name="EULAAgrement" xml:space="preserve">
|
||||
<value>Соглашаюсь с условиями использования ✅</value>
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
using JOBot.Proto;
|
||||
using JOBot.TClient.Infrastructure.Attributes.Authorization;
|
||||
using JOBot.TClient.Services;
|
||||
using JOBot.TClient.Statements;
|
||||
using Telegram.Bot.Types;
|
||||
using Telegram.Bot.Types.Enums;
|
||||
|
||||
namespace JOBot.TClient.Commands.Buttons;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ public class InfoCommand(ITelegramBotClient bot) : ITelegramCommand
|
||||
public async Task ExecuteAsync(Update update, CancellationToken ct)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(update.Message?.From);
|
||||
|
||||
|
||||
await bot.SendMessage(update.Message.From.Id, TextResource.Info, cancellationToken: ct);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,18 @@
|
||||
using JOBot.Proto;
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace JOBot.TClient.Commands;
|
||||
|
||||
public interface IAuthorizedTelegramCommand : ITelegramCommand
|
||||
{
|
||||
public Task ExecuteAsync(Update update, GetUserResponse user, CancellationToken ct);
|
||||
|
||||
/// <exception cref="UnauthorizedAccessException">Throws if you try to use ITelegramCommand.ExecuteAsync
|
||||
/// instead of IAuthorizedTelegramCommand.ExecuteAsync</exception>
|
||||
/// <exception cref="UnauthorizedAccessException">
|
||||
/// Throws if you try to use ITelegramCommand.ExecuteAsync
|
||||
/// instead of IAuthorizedTelegramCommand.ExecuteAsync
|
||||
/// </exception>
|
||||
Task ITelegramCommand.ExecuteAsync(Update update, CancellationToken ct)
|
||||
{
|
||||
throw new UnauthorizedAccessException("You do not have permission to access this command.");
|
||||
}
|
||||
|
||||
public Task ExecuteAsync(Update update, GetUserResponse user, CancellationToken ct);
|
||||
}
|
||||
@@ -5,10 +5,10 @@ using JOBot.TClient.Infrastructure.Attributes.Authorization;
|
||||
using JOBot.TClient.Infrastructure.Extensions;
|
||||
using JOBot.TClient.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Types;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace JOBot.TClient.Core.HostedServices;
|
||||
|
||||
@@ -22,8 +22,8 @@ public sealed class BotBackgroundService(
|
||||
protected override Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
botClient.StartReceiving(
|
||||
updateHandler: HandleUpdateAsync,
|
||||
errorHandler: HandleErrorAsync,
|
||||
HandleUpdateAsync,
|
||||
HandleErrorAsync,
|
||||
cancellationToken: stoppingToken);
|
||||
|
||||
return Task.CompletedTask;
|
||||
@@ -40,7 +40,7 @@ public sealed class BotBackgroundService(
|
||||
["/info"] = scope.ServiceProvider.GetRequiredService<InfoCommand>(),
|
||||
|
||||
//Buttons
|
||||
[ButtonResource.EULAAgrement] = scope.ServiceProvider.GetRequiredService<EulaAgreementButtonCommand>(),
|
||||
[ButtonResource.EULAAgrement] = scope.ServiceProvider.GetRequiredService<EulaAgreementButtonCommand>()
|
||||
};
|
||||
|
||||
if (update.Message is { Text: { } text, From: not null })
|
||||
@@ -69,7 +69,10 @@ public sealed class BotBackgroundService(
|
||||
|
||||
await authorizedTelegramCommand.ExecuteAsync(update, user, ct);
|
||||
}
|
||||
else await command.ExecuteAsync(update, ct);
|
||||
else
|
||||
{
|
||||
await command.ExecuteAsync(update, ct);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -18,39 +18,47 @@ public static class DependencyInjection
|
||||
public static IServiceCollection ConfigureServices(this IServiceCollection services, IConfiguration config)
|
||||
{
|
||||
services.AddSingleton(config);
|
||||
|
||||
services.AddScoped<ChannelBase, GrpcChannel>(_ => GrpcChannel.ForAddress(config.GetValue<string>("BackendHost")
|
||||
?? throw new MissingFieldException("Host is not defined")));
|
||||
|
||||
|
||||
services.AddScoped<ChannelBase, GrpcChannel>(_ => GrpcChannel.ForAddress(config.GetValue<string>("BackendHost")
|
||||
?? throw new MissingFieldException("Host is not defined")));
|
||||
|
||||
#region Commands
|
||||
|
||||
services.AddScoped<StartCommand>();
|
||||
services.AddScoped<MenuCommand>();
|
||||
services.AddScoped<InfoCommand>();
|
||||
|
||||
|
||||
//buttons
|
||||
services.AddScoped<EulaAgreementButtonCommand>();
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region gRPC Clients
|
||||
|
||||
services.AddGrpcClient<User.UserClient>(o => o.Address = new Uri("http://backend:5001"));
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Services
|
||||
|
||||
services.AddSingleton<UserService>();
|
||||
services.AddScoped<PrepareUserService>();
|
||||
services.AddScoped<MenuService>();
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region States
|
||||
|
||||
services.AddScoped<PrepareUserState>();
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
// Bot service
|
||||
services.AddHostedService<BotBackgroundService>();
|
||||
services.AddSingleton<ITelegramBotClient>(_ =>
|
||||
new TelegramBotClient(config.GetValue<string>("TelegramToken")
|
||||
services.AddSingleton<ITelegramBotClient>(_ =>
|
||||
new TelegramBotClient(config.GetValue<string>("TelegramToken")
|
||||
?? throw new MissingFieldException("TelegramToken is not set")));
|
||||
|
||||
|
||||
services.AddLogging(builder => builder.AddConsole());
|
||||
return services;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace JOBot.TClient.Infrastructure.Attributes.Authorization;
|
||||
|
||||
/// <summary>
|
||||
///Атрибут допуска к команде пользователя не завершившего стадию PrepareUser
|
||||
/// Атрибут допуска к команде пользователя не завершившего стадию PrepareUser
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
|
||||
public class AcceptNotPreparedAttribute : Attribute;
|
||||
@@ -4,14 +4,14 @@ using Telegram.Bot.Types;
|
||||
namespace JOBot.TClient.Infrastructure.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// Exception for fallback
|
||||
/// WARNING: Don't create new exception without throwing it
|
||||
/// Exception for fallback
|
||||
/// WARNING: Don't create new exception without throwing it
|
||||
/// </summary>
|
||||
public class FallbackException : Exception
|
||||
{
|
||||
public FallbackException(string message, Message botMessage, ITelegramBotClient botClient) : base(message)
|
||||
{
|
||||
botClient.SendMessage(chatId: botMessage.Chat.Id,
|
||||
botClient.SendMessage(botMessage.Chat.Id,
|
||||
TextResource.FallbackMessage);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,9 @@ namespace JOBot.TClient.Infrastructure.Extensions;
|
||||
|
||||
public static class GRpcModelsExtensions
|
||||
{
|
||||
public static bool IsPrepared(this GetUserResponse user) => user is { Eula: true, IsLogged: true } &&
|
||||
!string.IsNullOrEmpty(user.CVUrl);
|
||||
public static bool IsPrepared(this GetUserResponse user)
|
||||
{
|
||||
return user is { Eula: true, IsLogged: true } &&
|
||||
!string.IsNullOrEmpty(user.CVUrl);
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.4"/>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.4"/>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.4"/>
|
||||
<PackageReference Include="RabbitMQ.Client" Version="7.1.2" />
|
||||
<PackageReference Include="RabbitMQ.Client" Version="7.1.2"/>
|
||||
<PackageReference Include="Telegram.Bot" Version="22.5.1"/>
|
||||
</ItemGroup>
|
||||
|
||||
@@ -59,9 +59,9 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -6,7 +6,6 @@ var host = Host.CreateDefaultBuilder(args)
|
||||
{
|
||||
// Настройка DI
|
||||
services.ConfigureServices(context.Configuration);
|
||||
|
||||
})
|
||||
.Build();
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Types;
|
||||
using User = JOBot.Proto.User;
|
||||
|
||||
namespace JOBot.TClient.Services;
|
||||
|
||||
@@ -9,7 +8,7 @@ public class MenuService(ITelegramBotClient bot)
|
||||
public async Task RenderMenu(Update update, CancellationToken ct = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(update.Message?.From);
|
||||
|
||||
await bot.SendMessage(update.Message.From.Id,"PrepareUser stage is done.", cancellationToken: ct);
|
||||
|
||||
await bot.SendMessage(update.Message.From.Id, "PrepareUser stage is done.", cancellationToken: ct);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ public class PrepareUserService(ITelegramBotClient bot, User.UserClient userClie
|
||||
private readonly User.UserClient _userClient = userClient;
|
||||
|
||||
/// <summary>
|
||||
/// Get or register user on system
|
||||
/// Get or register user on system
|
||||
/// </summary>
|
||||
/// <param name="update">Telegram Update object</param>
|
||||
/// <param name="ct">Cancellation Token</param>
|
||||
@@ -26,21 +26,21 @@ public class PrepareUserService(ITelegramBotClient bot, User.UserClient userClie
|
||||
var result = await _userClient.RegisterAsync(new RegisterRequest
|
||||
{
|
||||
UserId = update.Message.From.Id,
|
||||
Username = update.Message.From.Username,
|
||||
Username = update.Message.From.Username
|
||||
});
|
||||
|
||||
if (!result.Success)
|
||||
{
|
||||
await _bot.SendMessage(chatId: update.Message.Chat.Id,
|
||||
await _bot.SendMessage(update.Message.Chat.Id,
|
||||
TextResource.FallbackMessage,
|
||||
cancellationToken: ct);
|
||||
|
||||
throw new FallbackException(TextResource.FallbackMessage, update.Message, _bot);
|
||||
}
|
||||
|
||||
var user = await _userClient.GetUserAsync(new GetUserRequest()
|
||||
var user = await _userClient.GetUserAsync(new GetUserRequest
|
||||
{
|
||||
UserId = update.Message.From.Id,
|
||||
UserId = update.Message.From.Id
|
||||
});
|
||||
|
||||
if (user == null)
|
||||
@@ -50,7 +50,7 @@ public class PrepareUserService(ITelegramBotClient bot, User.UserClient userClie
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Eula Agreement from user
|
||||
/// Get Eula Agreement from user
|
||||
/// </summary>
|
||||
/// <param name="update">Telegram Update object</param>
|
||||
/// <param name="ct">Cancellation Token</param>
|
||||
@@ -66,7 +66,7 @@ public class PrepareUserService(ITelegramBotClient bot, User.UserClient userClie
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Accept EULA for user
|
||||
/// Accept EULA for user
|
||||
/// </summary>
|
||||
/// <param name="update">Telegram update object</param>
|
||||
/// <param name="ct">Cancellation Token</param>
|
||||
@@ -74,10 +74,10 @@ public class PrepareUserService(ITelegramBotClient bot, User.UserClient userClie
|
||||
public async Task AcceptEula(Update update, CancellationToken ct = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(update.Message?.From);
|
||||
var result = await _userClient.AcceptEulaAsync(new()
|
||||
var result = await _userClient.AcceptEulaAsync(new AcceptEulaRequest
|
||||
{
|
||||
EulaAccepted = true,
|
||||
UserId = update.Message.From.Id,
|
||||
UserId = update.Message.From.Id
|
||||
});
|
||||
|
||||
if (!result.Success)
|
||||
@@ -87,22 +87,23 @@ public class PrepareUserService(ITelegramBotClient bot, User.UserClient userClie
|
||||
public async Task Auth(Update update, CancellationToken ct = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(update.Message?.From);
|
||||
|
||||
var url = await _userClient.GetHeadHunterAuthHookAsync(new GetHeadHunterAuthHookRequest()
|
||||
|
||||
var url = await _userClient.GetHeadHunterAuthHookAsync(new GetHeadHunterAuthHookRequest
|
||||
{
|
||||
UserId = update.Message.From.Id
|
||||
});
|
||||
|
||||
await _bot.SendMessage(
|
||||
update.Message.From.Id,
|
||||
string.Format(TextResource.AskForAuth, [url.RegistrationUrl]),
|
||||
update.Message.From.Id,
|
||||
string.Format(TextResource.AskForAuth, [url.RegistrationUrl]),
|
||||
cancellationToken: ct);
|
||||
}
|
||||
|
||||
public async Task SelectCv(Update update, CancellationToken ct = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(update.Message?.From);
|
||||
|
||||
await _bot.SendMessage(update.Message.From.Id, "Давайте выберем одно из доступных резюме:", cancellationToken: ct); //TODO: https://git.lisoveliy.su/Lisoveliy/JOBot/issues/9
|
||||
|
||||
await _bot.SendMessage(update.Message.From.Id, "Давайте выберем одно из доступных резюме:",
|
||||
cancellationToken: ct); //TODO: https://git.lisoveliy.su/Lisoveliy/JOBot/issues/9
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ namespace JOBot.TClient.Services;
|
||||
public class UserService(ITelegramBotClient bot, User.UserClient userClient)
|
||||
{
|
||||
/// <summary>
|
||||
/// Get user
|
||||
/// Get user
|
||||
/// </summary>
|
||||
/// <param name="update">Telegram Update object</param>
|
||||
/// <param name="ct">Cancellation Token</param>
|
||||
@@ -26,7 +26,7 @@ public class UserService(ITelegramBotClient bot, User.UserClient userClient)
|
||||
{
|
||||
user = await userClient.GetUserAsync(new GetUserRequest() //Получаем пользователя
|
||||
{
|
||||
UserId = update.Message.From.Id,
|
||||
UserId = update.Message.From.Id
|
||||
});
|
||||
}
|
||||
catch (RpcException e) //Пользователь не найден?
|
||||
@@ -36,6 +36,7 @@ public class UserService(ITelegramBotClient bot, User.UserClient userClient)
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ namespace JOBot.TClient.Statements;
|
||||
public class PrepareUserState(PrepareUserService prepareUserService, MenuService menuService)
|
||||
{
|
||||
/// <summary>
|
||||
/// Try to prepare user if is not registered
|
||||
/// Try to prepare user if is not registered
|
||||
/// </summary>
|
||||
/// <param name="update">Update telegram object</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
@@ -20,24 +20,24 @@ public class PrepareUserState(PrepareUserService prepareUserService, MenuService
|
||||
await prepareUserService.AskForEulaAgreement(update, ct);
|
||||
return; //interrupt while eula isn't accepted
|
||||
}
|
||||
|
||||
|
||||
await OnUserEulaValidStage(user, update, ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Signal for accepted eula
|
||||
/// Signal for accepted eula
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="update"></param>
|
||||
/// <param name="ct"></param>
|
||||
public async Task AcceptEula(GetUserResponse user, Update update, CancellationToken ct = default)
|
||||
{
|
||||
await prepareUserService.AcceptEula(update, ct: ct);
|
||||
await prepareUserService.AcceptEula(update, ct);
|
||||
await OnUserEulaValidStage(user, update, ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check user logged
|
||||
/// Check user logged
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="update"></param>
|
||||
@@ -49,21 +49,19 @@ public class PrepareUserState(PrepareUserService prepareUserService, MenuService
|
||||
await prepareUserService.Auth(update, ct);
|
||||
return;
|
||||
}
|
||||
|
||||
await OnAuthStage(user, update, ct);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Check user selected CV
|
||||
/// Check user selected CV
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="update"></param>
|
||||
/// <param name="ct"></param>
|
||||
private async Task OnAuthStage(GetUserResponse user, Update update, CancellationToken ct = default)
|
||||
{
|
||||
if (string.IsNullOrEmpty(user.CVUrl))
|
||||
{
|
||||
await prepareUserService.SelectCv(update, ct);
|
||||
}
|
||||
if (string.IsNullOrEmpty(user.CVUrl)) await prepareUserService.SelectCv(update, ct);
|
||||
await menuService.RenderMenu(update, ct); //boilerplate
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root"
|
||||
xmlns="">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
|
||||
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
@@ -13,10 +14,14 @@
|
||||
<value>1.3</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
|
||||
PublicKeyToken=b77a5c561934e089
|
||||
</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
|
||||
PublicKeyToken=b77a5c561934e089
|
||||
</value>
|
||||
</resheader>
|
||||
<data name="EULA" xml:space="preserve">
|
||||
<value>Продолжая, вы принимаете политику конфиденциальности и правила сервиса
|
||||
|
||||
Reference in New Issue
Block a user