60 lines
1.8 KiB
C#
60 lines
1.8 KiB
C#
using BotPages.Core;
|
||
using BotPages.Core.Messaging;
|
||
using BotPages.Core.Routing;
|
||
|
||
namespace Demo.Pages;
|
||
|
||
/// <summary>
|
||
/// Страница ввода деталей заявки.
|
||
/// </summary>
|
||
public sealed class DetailsPage : StatefullPage<string>
|
||
{
|
||
[Statefull("Request")]
|
||
private Models.Request Request;
|
||
|
||
public override Task OnEnter(PageContext ctx, string args, CancellationToken ct)
|
||
{
|
||
Request = new()
|
||
{
|
||
Title = args,
|
||
};
|
||
|
||
return new MessageBuilder(ctx)
|
||
.Text($"Заголовок: {args}\nДобавьте детали или нажмите Далее.")
|
||
.Inline(new InlineButton("Далее", "next"), new InlineButton("Назад", "back"))
|
||
.Reply("Отмена")
|
||
.SendAsync(ct);
|
||
}
|
||
|
||
public override async Task OnButton(PageContext ctx, string payload, CancellationToken ct)
|
||
{
|
||
switch (payload)
|
||
{
|
||
case "next":
|
||
await SaveState(ctx, ct);
|
||
await ctx.Navigation.GoToAsync<FilesPage>(ctx, ct);
|
||
break;
|
||
|
||
case "back":
|
||
await ctx.Navigation.GoToAsync<TitlePage>(ctx, ct);
|
||
break;
|
||
}
|
||
}
|
||
|
||
public override async Task OnText(PageContext ctx, string text, CancellationToken ct)
|
||
{
|
||
Request.Details = text;
|
||
await SaveState(ctx, ct);
|
||
await ctx.Navigation.GoToAsync<FilesPage>(ctx, ct);
|
||
}
|
||
|
||
internal static string Command => "/create_request {title?}";
|
||
internal static string CommandDescription => "создание заявки /create_request {title}";
|
||
internal static CommandHandler CommandHandler = async (ctx, args, ct) =>
|
||
{
|
||
string? title = "";
|
||
args?.TryGetValue("title", out title);
|
||
|
||
await ctx.Navigation.GoToAsync<DetailsPage, string>(ctx, title ?? "", ct);
|
||
};
|
||
} |