Compare commits
No commits in common. "4bc1e63da772c5315d5b940eb39a35d3288297ee" and "ac39117cf4de5b82b2bb1e4c1c7829267c1a3d63" have entirely different histories.
4bc1e63da7
...
ac39117cf4
71
JOBot.TClient/ButtonResource.Designer.cs
generated
71
JOBot.TClient/ButtonResource.Designer.cs
generated
@ -1,71 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
// <auto-generated>
|
|
||||||
// This code was generated by a tool.
|
|
||||||
//
|
|
||||||
// Changes to this file may cause incorrect behavior and will be lost if
|
|
||||||
// the code is regenerated.
|
|
||||||
// </auto-generated>
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
namespace JOBot.TClient {
|
|
||||||
using System;
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
|
||||||
/// </summary>
|
|
||||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
|
||||||
// class via a tool like ResGen or Visual Studio.
|
|
||||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
|
||||||
// with the /str option, or rebuild your VS project.
|
|
||||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
|
||||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
|
||||||
public class ButtonResource {
|
|
||||||
|
|
||||||
private static global::System.Resources.ResourceManager resourceMan;
|
|
||||||
|
|
||||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
|
||||||
|
|
||||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
|
||||||
internal ButtonResource() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the cached ResourceManager instance used by this class.
|
|
||||||
/// </summary>
|
|
||||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
|
||||||
public static global::System.Resources.ResourceManager ResourceManager {
|
|
||||||
get {
|
|
||||||
if (object.ReferenceEquals(resourceMan, null)) {
|
|
||||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("JOBot.TClient.ButtonResource", typeof(ButtonResource).Assembly);
|
|
||||||
resourceMan = temp;
|
|
||||||
}
|
|
||||||
return resourceMan;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Overrides the current thread's CurrentUICulture property for all
|
|
||||||
/// resource lookups using this strongly typed resource class.
|
|
||||||
/// </summary>
|
|
||||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
|
||||||
public static global::System.Globalization.CultureInfo Culture {
|
|
||||||
get {
|
|
||||||
return resourceCulture;
|
|
||||||
}
|
|
||||||
set {
|
|
||||||
resourceCulture = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Looks up a localized string similar to Соглашаюсь с условиями использования ✅.
|
|
||||||
/// </summary>
|
|
||||||
public static string EULAAgrement {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("EULAAgrement", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
<?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:element name="root" msdata:IsDataSet="true">
|
|
||||||
|
|
||||||
</xsd:element>
|
|
||||||
</xsd:schema>
|
|
||||||
<resheader name="resmimetype">
|
|
||||||
<value>text/microsoft-resx</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="version">
|
|
||||||
<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>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="writer">
|
|
||||||
<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>
|
|
||||||
</data>
|
|
||||||
</root>
|
|
@ -1,17 +0,0 @@
|
|||||||
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;
|
|
||||||
|
|
||||||
[AcceptNotPrepared]
|
|
||||||
public class EulaAgreementButtonCommand(PrepareUserState prepareUserState) : IAuthorizedTelegramCommand
|
|
||||||
{
|
|
||||||
public async Task ExecuteAsync(Update update, GetUserResponse user, CancellationToken ct)
|
|
||||||
{
|
|
||||||
await prepareUserState.AcceptEula(update, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
using Telegram.Bot;
|
|
||||||
using Telegram.Bot.Types;
|
|
||||||
|
|
||||||
namespace JOBot.TClient.Commands.Commands;
|
|
||||||
|
|
||||||
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,13 +0,0 @@
|
|||||||
using JOBot.Proto;
|
|
||||||
using JOBot.TClient.Services;
|
|
||||||
using Telegram.Bot.Types;
|
|
||||||
|
|
||||||
namespace JOBot.TClient.Commands.Commands;
|
|
||||||
|
|
||||||
public class MenuCommand(MenuService menuService) : IAuthorizedTelegramCommand
|
|
||||||
{
|
|
||||||
public async Task ExecuteAsync(Update update, GetUserResponse user, CancellationToken ct)
|
|
||||||
{
|
|
||||||
await menuService.RenderMenu(update, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
using JOBot.TClient.Statements;
|
|
||||||
using Telegram.Bot.Types;
|
|
||||||
|
|
||||||
namespace JOBot.TClient.Commands.Commands;
|
|
||||||
|
|
||||||
public class StartCommand(PrepareUserState prepareUserState) : ITelegramCommand
|
|
||||||
{
|
|
||||||
public async Task ExecuteAsync(Update update, CancellationToken ct)
|
|
||||||
{
|
|
||||||
await prepareUserState.TryToPrepareUser(update, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
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>
|
|
||||||
Task ITelegramCommand.ExecuteAsync(Update update, CancellationToken ct)
|
|
||||||
{
|
|
||||||
throw new UnauthorizedAccessException("You do not have permission to access this command.");
|
|
||||||
}
|
|
||||||
}
|
|
22
JOBot.TClient/Commands/StartCommand.cs
Normal file
22
JOBot.TClient/Commands/StartCommand.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using JOBot.TClient.Core.Services;
|
||||||
|
using Telegram.Bot;
|
||||||
|
using Telegram.Bot.Types;
|
||||||
|
|
||||||
|
namespace JOBot.TClient.Commands;
|
||||||
|
|
||||||
|
public class StartCommand(ITelegramBotClient bot, UserService userService) : ITelegramCommand
|
||||||
|
{
|
||||||
|
private const string ReturnMessage = "Привет! Я JOBot, помощник по поиску работы в IT.";
|
||||||
|
public async Task ExecuteAsync(Update update, CancellationToken ct)
|
||||||
|
{
|
||||||
|
await userService.RegisterAsync(
|
||||||
|
update.Message!.Chat.Id,
|
||||||
|
update.Message.Chat.Username);
|
||||||
|
|
||||||
|
await bot.SendMessage(chatId: update.Message.Chat.Id,
|
||||||
|
"Продолжая, вы принимаете политику конфиденциальности и правила сервиса" +
|
||||||
|
"\nhttps://hh.ru/article/personal_data?backurl=%2F&role=applicant" +
|
||||||
|
"\nhttps://hh.ru/account/agreement?backurl=%2Faccount%2Fsignup%3Fbackurl%3D%252F%26role%3Dapplicant&role=applicant",
|
||||||
|
cancellationToken: ct);
|
||||||
|
}
|
||||||
|
}
|
@ -1,22 +1,17 @@
|
|||||||
using JOBot.TClient.Commands;
|
using JOBot.TClient.Commands;
|
||||||
using JOBot.TClient.Commands.Buttons;
|
|
||||||
using JOBot.TClient.Commands.Commands;
|
|
||||||
using JOBot.TClient.Infrastructure.Attributes.Authorization;
|
|
||||||
using JOBot.TClient.Infrastructure.Extensions;
|
|
||||||
using JOBot.TClient.Services;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace JOBot.TClient.Core.HostedServices;
|
||||||
|
|
||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
namespace JOBot.TClient.Core.HostedServices;
|
|
||||||
|
|
||||||
public sealed class BotBackgroundService(
|
public sealed class BotBackgroundService(
|
||||||
ITelegramBotClient botClient,
|
ITelegramBotClient botClient,
|
||||||
IServiceProvider services,
|
IServiceProvider services,
|
||||||
ILogger<BotBackgroundService> logger,
|
ILogger<BotBackgroundService> logger)
|
||||||
UserService userService)
|
|
||||||
: BackgroundService
|
: BackgroundService
|
||||||
{
|
{
|
||||||
protected override Task ExecuteAsync(CancellationToken stoppingToken)
|
protected override Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
@ -34,48 +29,11 @@ public sealed class BotBackgroundService(
|
|||||||
using var scope = services.CreateScope();
|
using var scope = services.CreateScope();
|
||||||
var commands = new Dictionary<string, ITelegramCommand>
|
var commands = new Dictionary<string, ITelegramCommand>
|
||||||
{
|
{
|
||||||
//Commands
|
["/start"] = scope.ServiceProvider.GetRequiredService<StartCommand>()
|
||||||
["/start"] = scope.ServiceProvider.GetRequiredService<StartCommand>(),
|
|
||||||
["/menu"] = scope.ServiceProvider.GetRequiredService<MenuCommand>(),
|
|
||||||
["/info"] = scope.ServiceProvider.GetRequiredService<InfoCommand>(),
|
|
||||||
|
|
||||||
//Buttons
|
|
||||||
[ButtonResource.EULAAgrement] = scope.ServiceProvider.GetRequiredService<EulaAgreementButtonCommand>(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (update.Message is { Text: { } text, From: not null })
|
if (update.Message?.Text is { } text && commands.TryGetValue(text, out var command))
|
||||||
{
|
await command.ExecuteAsync(update, ct);
|
||||||
var user = await userService.GetUser(update, ct); //Проверка существования пользователя
|
|
||||||
|
|
||||||
if (user == null)
|
|
||||||
{
|
|
||||||
await commands["/start"].ExecuteAsync(update, ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (commands.TryGetValue(text, out var command))
|
|
||||||
{
|
|
||||||
if (command is IAuthorizedTelegramCommand authorizedTelegramCommand)
|
|
||||||
{
|
|
||||||
var attribute = Attribute.GetCustomAttribute(
|
|
||||||
command.GetType(),
|
|
||||||
typeof(AcceptNotPreparedAttribute));
|
|
||||||
if (!user.IsPrepared() && attribute is not AcceptNotPreparedAttribute)
|
|
||||||
{
|
|
||||||
await commands["/start"].ExecuteAsync(update, ct);
|
|
||||||
//заставляем пользователя завершить регистрацию
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await authorizedTelegramCommand.ExecuteAsync(update, user, ct);
|
|
||||||
}
|
|
||||||
else await command.ExecuteAsync(update, ct);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await bot.SendMessage(update.Message.From.Id, TextResource.CommandNotFound, cancellationToken: ct);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task HandleErrorAsync(ITelegramBotClient bot, Exception ex, CancellationToken ct)
|
private Task HandleErrorAsync(ITelegramBotClient bot, Exception ex, CancellationToken ct)
|
||||||
|
18
JOBot.TClient/Core/Services/UserService.cs
Normal file
18
JOBot.TClient/Core/Services/UserService.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using User = JOBot.Proto.User;
|
||||||
|
|
||||||
|
namespace JOBot.TClient.Core.Services;
|
||||||
|
|
||||||
|
public class UserService(User.UserClient client)
|
||||||
|
{
|
||||||
|
public async Task<bool> RegisterAsync(long userId, string? username)
|
||||||
|
{
|
||||||
|
|
||||||
|
var response = await client.RegisterAsync(new()
|
||||||
|
{
|
||||||
|
UserId = userId,
|
||||||
|
Username = username
|
||||||
|
});
|
||||||
|
|
||||||
|
return response.Success;
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,8 @@
|
|||||||
using Grpc.Core;
|
using Grpc.Core;
|
||||||
using Grpc.Net.Client;
|
using Grpc.Net.Client;
|
||||||
using JOBot.Proto;
|
using JOBot.Proto;
|
||||||
using JOBot.TClient.Commands.Buttons;
|
using JOBot.TClient.Commands;
|
||||||
using JOBot.TClient.Commands.Commands;
|
using JOBot.TClient.Core.Services;
|
||||||
using JOBot.TClient.Core.HostedServices;
|
|
||||||
using JOBot.TClient.Services;
|
|
||||||
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;
|
||||||
@ -22,31 +19,15 @@ public static class DependencyInjection
|
|||||||
services.AddScoped<ChannelBase, GrpcChannel>(_ => GrpcChannel.ForAddress(config.GetValue<string>("BackendHost")
|
services.AddScoped<ChannelBase, GrpcChannel>(_ => GrpcChannel.ForAddress(config.GetValue<string>("BackendHost")
|
||||||
?? throw new MissingFieldException("Host is not defined")));
|
?? throw new MissingFieldException("Host is not defined")));
|
||||||
|
|
||||||
#region Commands
|
//Commands
|
||||||
services.AddScoped<StartCommand>();
|
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.AddSingleton<UserService>();
|
||||||
services.AddScoped<PrepareUserService>();
|
|
||||||
services.AddScoped<MenuService>();
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region States
|
//gRPC Clients
|
||||||
services.AddScoped<PrepareUserState>();
|
services.AddScoped<User.UserClient>();
|
||||||
#endregion
|
|
||||||
|
|
||||||
// Bot service
|
// Telegram Bot
|
||||||
services.AddHostedService<BotBackgroundService>();
|
|
||||||
services.AddSingleton<ITelegramBotClient>(_ =>
|
services.AddSingleton<ITelegramBotClient>(_ =>
|
||||||
new TelegramBotClient(config.GetValue<string>("TelegramToken")
|
new TelegramBotClient(config.GetValue<string>("TelegramToken")
|
||||||
?? throw new MissingFieldException("TelegramToken is not set")));
|
?? throw new MissingFieldException("TelegramToken is not set")));
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
namespace JOBot.TClient.Infrastructure.Attributes.Authorization;
|
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
|
|
||||||
public class AcceptNotPreparedAttribute : Attribute;
|
|
@ -1,17 +0,0 @@
|
|||||||
using Telegram.Bot;
|
|
||||||
using Telegram.Bot.Types;
|
|
||||||
|
|
||||||
namespace JOBot.TClient.Infrastructure.Exceptions;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 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,
|
|
||||||
TextResource.FallbackMessage);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
using JOBot.Proto;
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
@ -8,19 +8,18 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Google.Protobuf" Version="3.30.2"/>
|
<PackageReference Include="Google.Protobuf" Version="3.30.2" />
|
||||||
<PackageReference Include="Grpc.Net.Client" Version="2.71.0"/>
|
<PackageReference Include="Grpc.Net.Client" Version="2.71.0" />
|
||||||
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.71.0"/>
|
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.71.0" />
|
||||||
<PackageReference Include="Grpc.Tools" Version="2.71.0">
|
<PackageReference Include="Grpc.Tools" Version="2.71.0">
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0"/>
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.4" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.4"/>
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.4" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.4"/>
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.4" />
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.4"/>
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.4" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.4"/>
|
<PackageReference Include="Telegram.Bot" Version="22.5.1" />
|
||||||
<PackageReference Include="Telegram.Bot" Version="22.5.1"/>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -34,27 +33,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Update="ButtonResource.Designer.cs">
|
<Folder Include="Infrastucture\" />
|
||||||
<DesignTime>True</DesignTime>
|
|
||||||
<AutoGen>True</AutoGen>
|
|
||||||
<DependentUpon>ButtonResource.resx</DependentUpon>
|
|
||||||
</Compile>
|
|
||||||
<Compile Update="TextResource.Designer.cs">
|
|
||||||
<DesignTime>True</DesignTime>
|
|
||||||
<AutoGen>True</AutoGen>
|
|
||||||
<DependentUpon>TextResource.resx</DependentUpon>
|
|
||||||
</Compile>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<EmbeddedResource Update="TextResource.resx">
|
|
||||||
<Generator>PublicResXFileCodeGenerator</Generator>
|
|
||||||
<LastGenOutput>TextResource.Designer.cs</LastGenOutput>
|
|
||||||
</EmbeddedResource>
|
|
||||||
<EmbeddedResource Update="ButtonResource.resx">
|
|
||||||
<Generator>PublicResXFileCodeGenerator</Generator>
|
|
||||||
<LastGenOutput>ButtonResource.Designer.cs</LastGenOutput>
|
|
||||||
</EmbeddedResource>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
using JOBot.TClient;
|
using JOBot.Proto;
|
||||||
|
using JOBot.TClient;
|
||||||
|
using JOBot.TClient.Commands;
|
||||||
|
using JOBot.TClient.Core.HostedServices;
|
||||||
|
using JOBot.TClient.Core.Services;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
var host = Host.CreateDefaultBuilder(args)
|
var host = Host.CreateDefaultBuilder(args)
|
||||||
@ -7,6 +12,12 @@ var host = Host.CreateDefaultBuilder(args)
|
|||||||
// Настройка DI
|
// Настройка DI
|
||||||
services.ConfigureServices(context.Configuration);
|
services.ConfigureServices(context.Configuration);
|
||||||
|
|
||||||
|
// Фоновый сервис для бота
|
||||||
|
services.AddHostedService<BotBackgroundService>();
|
||||||
|
|
||||||
|
services.AddScoped<StartCommand>();
|
||||||
|
services.AddSingleton<UserService>();
|
||||||
|
services.AddGrpcClient<User.UserClient>(o => o.Address = new Uri("http://backend:5001"));
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
using Telegram.Bot;
|
|
||||||
using Telegram.Bot.Types;
|
|
||||||
using User = JOBot.Proto.User;
|
|
||||||
|
|
||||||
namespace JOBot.TClient.Services;
|
|
||||||
|
|
||||||
public class MenuService(ITelegramBotClient bot)
|
|
||||||
{
|
|
||||||
public Task RenderMenu(Update update, CancellationToken ct = default)
|
|
||||||
{
|
|
||||||
ArgumentNullException.ThrowIfNull(update.Message?.From);
|
|
||||||
|
|
||||||
bot.SendMessage(update.Message.From.Id,"PrepareUser stage is done.", cancellationToken: ct);
|
|
||||||
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,86 +0,0 @@
|
|||||||
using JOBot.Proto;
|
|
||||||
using JOBot.TClient.Infrastructure.Exceptions;
|
|
||||||
using Telegram.Bot;
|
|
||||||
using Telegram.Bot.Types;
|
|
||||||
using User = JOBot.Proto.User;
|
|
||||||
|
|
||||||
namespace JOBot.TClient.Services;
|
|
||||||
|
|
||||||
public class PrepareUserService(ITelegramBotClient bot, User.UserClient userClient) : UserService(bot, userClient)
|
|
||||||
{
|
|
||||||
private readonly ITelegramBotClient _bot = bot;
|
|
||||||
private readonly User.UserClient _userClient = userClient;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get or register user on system
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="update">Telegram Update object</param>
|
|
||||||
/// <param name="ct">Cancellation Token</param>
|
|
||||||
/// <returns>RPC User Response</returns>
|
|
||||||
/// <exception cref="FallbackException">If something in server logic went wrong</exception>
|
|
||||||
/// <exception cref="ArgumentNullException">If update.Message is null</exception>
|
|
||||||
public async Task<GetUserResponse> RegisterUser(Update update, CancellationToken ct = default)
|
|
||||||
{
|
|
||||||
ArgumentNullException.ThrowIfNull(update.Message?.From);
|
|
||||||
|
|
||||||
var result = await _userClient.RegisterAsync(new RegisterRequest
|
|
||||||
{
|
|
||||||
UserId = update.Message.From.Id,
|
|
||||||
Username = update.Message.From.Username,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!result.Success)
|
|
||||||
{
|
|
||||||
await _bot.SendMessage(chatId: update.Message.Chat.Id,
|
|
||||||
TextResource.FallbackMessage,
|
|
||||||
cancellationToken: ct);
|
|
||||||
|
|
||||||
throw new FallbackException(TextResource.FallbackMessage, update.Message, _bot);
|
|
||||||
}
|
|
||||||
|
|
||||||
var user = await _userClient.GetUserAsync(new GetUserRequest()
|
|
||||||
{
|
|
||||||
UserId = update.Message.From.Id,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (user == null)
|
|
||||||
throw new FallbackException(TextResource.FallbackMessage, update.Message, _bot);
|
|
||||||
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get Eula Agreement from user
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="update">Telegram Update object</param>
|
|
||||||
/// <param name="ct">Cancellation Token</param>
|
|
||||||
/// <exception cref="ArgumentNullException">If update.Message is null</exception>
|
|
||||||
public async Task AskForEulaAgreement(Update update, CancellationToken ct = default)
|
|
||||||
{
|
|
||||||
ArgumentNullException.ThrowIfNull(update.Message?.From);
|
|
||||||
|
|
||||||
await _bot.SendMessage(
|
|
||||||
update.Message.From.Id,
|
|
||||||
TextResource.EULA,
|
|
||||||
replyMarkup: new[] { ButtonResource.EULAAgrement }, cancellationToken: ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Accept EULA for user
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="update">Telegram update object</param>
|
|
||||||
/// <param name="ct">Cancellation Token</param>
|
|
||||||
/// <exception cref="FallbackException">If something in server logic went wrong</exception>
|
|
||||||
public async Task AcceptEula(Update update, CancellationToken ct = default)
|
|
||||||
{
|
|
||||||
ArgumentNullException.ThrowIfNull(update.Message?.From);
|
|
||||||
var result = await _userClient.AcceptEulaAsync(new()
|
|
||||||
{
|
|
||||||
EulaAccepted = true,
|
|
||||||
UserId = update.Message.From.Id,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!result.Success)
|
|
||||||
throw new FallbackException(TextResource.FallbackMessage, update.Message, _bot);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
using Grpc.Core;
|
|
||||||
using JOBot.Proto;
|
|
||||||
using JOBot.TClient.Infrastructure.Exceptions;
|
|
||||||
using Telegram.Bot;
|
|
||||||
using Telegram.Bot.Types;
|
|
||||||
using User = JOBot.Proto.User;
|
|
||||||
|
|
||||||
namespace JOBot.TClient.Services;
|
|
||||||
|
|
||||||
public class UserService(ITelegramBotClient bot, User.UserClient userClient)
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Get user
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="update">Telegram Update object</param>
|
|
||||||
/// <param name="ct">Cancellation Token</param>
|
|
||||||
/// <returns>RPC User Response or null if user not exists</returns>
|
|
||||||
/// <exception cref="FallbackException">If something in server logic went wrong</exception>
|
|
||||||
/// <exception cref="ArgumentNullException">If update.Message is null</exception>
|
|
||||||
public async Task<GetUserResponse?> GetUser(Update update, CancellationToken ct = default)
|
|
||||||
{
|
|
||||||
ArgumentNullException.ThrowIfNull(update.Message?.From);
|
|
||||||
|
|
||||||
GetUserResponse? user;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
user = await userClient.GetUserAsync(new GetUserRequest() //Получаем пользователя
|
|
||||||
{
|
|
||||||
UserId = update.Message.From.Id,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
catch (RpcException e) //Пользователь не найден?
|
|
||||||
{
|
|
||||||
if (e.StatusCode != StatusCode.NotFound)
|
|
||||||
throw new FallbackException(TextResource.FallbackMessage, update.Message, bot);
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
using JOBot.TClient.Services;
|
|
||||||
using Telegram.Bot.Types;
|
|
||||||
using User = JOBot.Proto.User;
|
|
||||||
|
|
||||||
namespace JOBot.TClient.Statements;
|
|
||||||
|
|
||||||
public class PrepareUserState(PrepareUserService prepareUserService, MenuService menuService)
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Try to prepare user if is not registered
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="update">Update telegram object</param>
|
|
||||||
/// <param name="ct">Cancellation token</param>
|
|
||||||
public async Task TryToPrepareUser(Update update, CancellationToken ct = default)
|
|
||||||
{
|
|
||||||
var user = await prepareUserService.GetUser(update, ct) ?? await prepareUserService.RegisterUser(update, ct);
|
|
||||||
|
|
||||||
if (!user.Eula)
|
|
||||||
{
|
|
||||||
await prepareUserService.AskForEulaAgreement(update, ct);
|
|
||||||
return; //interrupt while eula isn't accepted
|
|
||||||
}
|
|
||||||
|
|
||||||
await OnUserEulaValidStage(update, ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Signal for accepted eula
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="update"></param>
|
|
||||||
/// <param name="ct"></param>
|
|
||||||
public async Task AcceptEula(Update update, CancellationToken ct = default)
|
|
||||||
{
|
|
||||||
await prepareUserService.AcceptEula(update, ct: ct);
|
|
||||||
await OnUserEulaValidStage(update, ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Continue prepare stage
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="update"></param>
|
|
||||||
/// <param name="ct"></param>
|
|
||||||
private async Task OnUserEulaValidStage(Update update, CancellationToken ct = default)
|
|
||||||
{
|
|
||||||
await menuService.RenderMenu(update, ct); //boilerplate
|
|
||||||
}
|
|
||||||
}
|
|
99
JOBot.TClient/TextResource.Designer.cs
generated
99
JOBot.TClient/TextResource.Designer.cs
generated
@ -1,99 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
// <auto-generated>
|
|
||||||
// This code was generated by a tool.
|
|
||||||
//
|
|
||||||
// Changes to this file may cause incorrect behavior and will be lost if
|
|
||||||
// the code is regenerated.
|
|
||||||
// </auto-generated>
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
namespace JOBot.TClient {
|
|
||||||
using System;
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
|
||||||
/// </summary>
|
|
||||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
|
||||||
// class via a tool like ResGen or Visual Studio.
|
|
||||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
|
||||||
// with the /str option, or rebuild your VS project.
|
|
||||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
|
||||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
|
||||||
public class TextResource {
|
|
||||||
|
|
||||||
private static global::System.Resources.ResourceManager resourceMan;
|
|
||||||
|
|
||||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
|
||||||
|
|
||||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
|
||||||
internal TextResource() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the cached ResourceManager instance used by this class.
|
|
||||||
/// </summary>
|
|
||||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
|
||||||
public static global::System.Resources.ResourceManager ResourceManager {
|
|
||||||
get {
|
|
||||||
if (object.ReferenceEquals(resourceMan, null)) {
|
|
||||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("JOBot.TClient.TextResource", typeof(TextResource).Assembly);
|
|
||||||
resourceMan = temp;
|
|
||||||
}
|
|
||||||
return resourceMan;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Overrides the current thread's CurrentUICulture property for all
|
|
||||||
/// resource lookups using this strongly typed resource class.
|
|
||||||
/// </summary>
|
|
||||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
|
||||||
public static global::System.Globalization.CultureInfo Culture {
|
|
||||||
get {
|
|
||||||
return resourceCulture;
|
|
||||||
}
|
|
||||||
set {
|
|
||||||
resourceCulture = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Looks up a localized string similar to Команда не найдена, попробуйте что-то другое.
|
|
||||||
/// </summary>
|
|
||||||
public static string CommandNotFound {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("CommandNotFound", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Looks up a localized string similar to Продолжая, вы принимаете политику конфиденциальности и правила сервиса \nhttps://hh.ru/article/personal_data?backurl=%2F&role=applicant
|
|
||||||
///\nhttps://hh.ru/account/agreement?backurl=%2Faccount%2Fsignup%3Fbackurl%3D%252F%26role%3Dapplicant&role=applicant".
|
|
||||||
/// </summary>
|
|
||||||
public static string EULA {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("EULA", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Looks up a localized string similar to Something went REALLY wrong. Service can't continue process..
|
|
||||||
/// </summary>
|
|
||||||
public static string FallbackMessage {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("FallbackMessage", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Looks up a localized string similar to Это бот для упрощения поиска работы на HH.ru.
|
|
||||||
/// </summary>
|
|
||||||
public static string Info {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("Info", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
<?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:element name="root" msdata:IsDataSet="true">
|
|
||||||
|
|
||||||
</xsd:element>
|
|
||||||
</xsd:schema>
|
|
||||||
<resheader name="resmimetype">
|
|
||||||
<value>text/microsoft-resx</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="version">
|
|
||||||
<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>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="writer">
|
|
||||||
<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>Продолжая, вы принимаете политику конфиденциальности и правила сервиса \nhttps://hh.ru/article/personal_data?backurl=%2F&role=applicant
|
|
||||||
\nhttps://hh.ru/account/agreement?backurl=%2Faccount%2Fsignup%3Fbackurl%3D%252F%26role%3Dapplicant&role=applicant"</value>
|
|
||||||
</data>
|
|
||||||
<data name="FallbackMessage" xml:space="preserve">
|
|
||||||
<value>Something went REALLY wrong. Service can't continue process.</value>
|
|
||||||
</data>
|
|
||||||
<data name="CommandNotFound" xml:space="preserve">
|
|
||||||
<value>Команда не найдена, попробуйте что-то другое</value>
|
|
||||||
</data>
|
|
||||||
<data name="Info" xml:space="preserve">
|
|
||||||
<value>Это бот для упрощения поиска работы на HH.ru</value>
|
|
||||||
</data>
|
|
||||||
</root>
|
|
Loading…
x
Reference in New Issue
Block a user