Добавьте файлы проекта.

This commit is contained in:
2025-12-02 15:57:42 +03:00
parent cf107b62a3
commit 7f69eab545
44 changed files with 1470 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
using BotPages.Core;
using Telegram.Bot;
using Telegram.Bot.Types;
namespace BotPages.Telegram
{
/// <summary>
/// Утилиты для извлечения контекста из Telegram Update.
/// </summary>
public static class TelegramUpdateMapper
{
/// <summary>
/// Преобразует Telegram Update в универсальный UpdateContext.
/// </summary>
public static UpdateContext Map(ITelegramBotClient bot, INavigationService nav, IStateStore store, Update update)
{
var chat = update.Message?.Chat ?? update.CallbackQuery?.Message?.Chat;
var user = update.Message?.From ?? update.CallbackQuery?.From;
var text = update.Message?.Text ?? update.CallbackQuery?.Data;
var files = new List<FileDescriptor>();
if (update.Message?.Document is { } doc)
{
files.Add(new FileDescriptor(doc.FileId, doc.FileName ?? "file", doc.MimeType ?? "application/octet-stream"));
}
if (update.Message?.Photo is { } photos && photos.Count() > 0)
{
var largest = photos.OrderBy(p => p.FileSize).Last();
files.Add(new FileDescriptor(largest.FileId, "photo.jpg", "image/jpeg"));
}
return new UpdateContext
{
Client = new TelegramClientAdapter(bot),
Chat = new ChatContext { Id = chat!.Id, Title = chat.Title },
User = new UserContext { Id = user!.Id, DisplayName = $"{user.FirstName} {user.LastName}" },
Text = text,
IncomingFiles = files,
RawUpdate = update,
Nav = nav,
State = store
};
}
}
}