This commit is contained in:
@@ -1,39 +1,36 @@
|
||||
using BotPages.Core;
|
||||
using BotPages.Core.Abstractions;
|
||||
using BotPages.Core.Messaging;
|
||||
|
||||
namespace Demo.Pages
|
||||
namespace Demo.Pages;
|
||||
|
||||
/// <summary>
|
||||
/// Страница загрузки файлов.
|
||||
/// </summary>
|
||||
public sealed class FilesPage : Page
|
||||
{
|
||||
public sealed class FilesPage : Page
|
||||
public override Task OnEnter(PageContext ctx, CancellationToken ct)
|
||||
=> new MessageBuilder(ctx)
|
||||
.Text("Пришлите файлы для заявки 📎", MessageFormat.Markdown)
|
||||
.Reply("Пропустить")
|
||||
.SendAsync(ct);
|
||||
|
||||
public override async Task OnFile(PageContext ctx, List<FileDescriptor> files, CancellationToken ct)
|
||||
{
|
||||
public static string Id => nameof(FilesPage);
|
||||
|
||||
public override Task<PageResult> EnterAsync(UpdateContext ctx, CancellationToken ct)
|
||||
foreach (var file in files)
|
||||
{
|
||||
var actions = new[]
|
||||
{
|
||||
new PageAction { Label = "⬅️ Назад", Value = "back", Placement = ActionPlacement.Reply, Row = 0 }
|
||||
};
|
||||
|
||||
return Task.FromResult(
|
||||
PageResultBuilder.Empty()
|
||||
.WithText("📂 Здесь можно загрузить или отправить файл.")
|
||||
.WithKeyboard(actions)
|
||||
.Build()
|
||||
);
|
||||
await ctx.SendFileAsync(file, $"Файл '{file.Name}' получен и отправлен обратно.", ct);
|
||||
}
|
||||
|
||||
public override async Task<PageResult> HandleAsync(UpdateContext ctx, CancellationToken ct)
|
||||
{
|
||||
if (ctx.Text == "⬅️ Назад")
|
||||
return PageResultBuilder.Empty().WithNavigate(nameof(MainPage)).Build();
|
||||
|
||||
if (ctx.IncomingFiles?.Count > 0)
|
||||
{
|
||||
await ctx.Client.SendFilesAsync(ctx.Chat.Id, ctx.IncomingFiles, ct);
|
||||
return PageResultBuilder.Empty().WithText("Файл получен и отправлен обратно.").Build();
|
||||
}
|
||||
|
||||
return PageResultBuilder.Empty().WithText("Пришлите файл или нажмите 'Назад'.").Build();
|
||||
}
|
||||
await new MessageBuilder(ctx)
|
||||
.Text($"Получено файлов: {files.Count}", MessageFormat.Plain)
|
||||
.Inline("Далее", "next")
|
||||
.SendAsync(ct);
|
||||
}
|
||||
|
||||
public override Task OnButton(PageContext ctx, string payload, CancellationToken ct)
|
||||
=> ctx.Navigation.GoToAsync<ConfirmPage>(ctx, ct);
|
||||
|
||||
public override Task OnText(PageContext ctx, string text, CancellationToken ct)
|
||||
=> ctx.Navigation.GoToAsync<ConfirmPage>(ctx, ct);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user