Files
BotPages/Demo/Pages/DetailsPage.cs

60 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
};
}