feat: added auth for telegram stage
This commit is contained in:
@@ -12,6 +12,7 @@ public class EulaAgreementButtonCommand(PrepareUserState prepareUserState) : IAu
|
||||
{
|
||||
public async Task ExecuteAsync(Update update, GetUserResponse user, CancellationToken ct)
|
||||
{
|
||||
await prepareUserState.AcceptEula(update, ct);
|
||||
if (!user.Eula)
|
||||
await prepareUserState.AcceptEula(user, update, ct);
|
||||
}
|
||||
}
|
||||
@@ -6,12 +6,10 @@ namespace JOBot.TClient.Services;
|
||||
|
||||
public class MenuService(ITelegramBotClient bot)
|
||||
{
|
||||
public Task RenderMenu(Update update, CancellationToken ct = default)
|
||||
public async 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;
|
||||
await bot.SendMessage(update.Message.From.Id,"PrepareUser stage is done.", cancellationToken: ct);
|
||||
}
|
||||
}
|
||||
@@ -83,4 +83,19 @@ public class PrepareUserService(ITelegramBotClient bot, User.UserClient userClie
|
||||
if (!result.Success)
|
||||
throw new FallbackException(TextResource.FallbackMessage, update.Message, _bot);
|
||||
}
|
||||
|
||||
public async Task Auth(Update update, CancellationToken ct = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(update.Message?.From);
|
||||
|
||||
var url = await _userClient.GetHeadHunterAuthHookAsync(new GetHeadHunterAuthHookRequest()
|
||||
{
|
||||
UserId = update.Message.From.Id
|
||||
});
|
||||
|
||||
await _bot.SendMessage(
|
||||
update.Message.From.Id,
|
||||
string.Format(TextResource.AskForAuth, [url]),
|
||||
cancellationToken: ct);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using JOBot.Proto;
|
||||
using JOBot.TClient.Services;
|
||||
using Telegram.Bot.Types;
|
||||
using User = JOBot.Proto.User;
|
||||
@@ -21,27 +22,33 @@ public class PrepareUserState(PrepareUserService prepareUserService, MenuService
|
||||
return; //interrupt while eula isn't accepted
|
||||
}
|
||||
|
||||
await OnUserEulaValidStage(update, ct);
|
||||
await OnUserEulaValidStage(user, update, ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Signal for accepted eula
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="update"></param>
|
||||
/// <param name="ct"></param>
|
||||
public async Task AcceptEula(Update update, CancellationToken ct = default)
|
||||
public async Task AcceptEula(GetUserResponse user, Update update, CancellationToken ct = default)
|
||||
{
|
||||
await prepareUserService.AcceptEula(update, ct: ct);
|
||||
await OnUserEulaValidStage(update, ct);
|
||||
await OnUserEulaValidStage(user, update, ct);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Continue prepare stage
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="update"></param>
|
||||
/// <param name="ct"></param>
|
||||
private async Task OnUserEulaValidStage(Update update, CancellationToken ct = default)
|
||||
private async Task OnUserEulaValidStage(GetUserResponse user, Update update, CancellationToken ct = default)
|
||||
{
|
||||
if (!user.IsLogged)
|
||||
{
|
||||
prepareUserService.Auth(update, ct);
|
||||
}
|
||||
await menuService.RenderMenu(update, ct); //boilerplate
|
||||
}
|
||||
}
|
||||
9
JOBot.TClient/TextResource.Designer.cs
generated
9
JOBot.TClient/TextResource.Designer.cs
generated
@@ -59,6 +59,15 @@ namespace JOBot.TClient {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Авторизируйтесь на сайте HeadHunter для получения доступа к резюме и вакансиям {0}.
|
||||
/// </summary>
|
||||
public static string AskForAuth {
|
||||
get {
|
||||
return ResourceManager.GetString("AskForAuth", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Команда не найдена, попробуйте что-то другое.
|
||||
/// </summary>
|
||||
|
||||
@@ -34,4 +34,7 @@ https://hh.ru/account/agreement?backurl=%2Faccount%2Fsignup%3Fbackurl%3D%252F%26
|
||||
<data name="Info" xml:space="preserve">
|
||||
<value>Это бот для упрощения поиска работы на HH.ru</value>
|
||||
</data>
|
||||
<data name="AskForAuth" xml:space="preserve">
|
||||
<value>Авторизируйтесь на сайте HeadHunter для получения доступа к резюме и вакансиям {0}</value>
|
||||
</data>
|
||||
</root>
|
||||
Reference in New Issue
Block a user