Добавлены новые методы отправки сообщений
This commit is contained in:
16
BotPages.Core/Context/DeleteInfo.cs
Normal file
16
BotPages.Core/Context/DeleteInfo.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace BotPages.Core.Context;
|
||||
|
||||
/// <summary>
|
||||
/// Информация об удалении сообщения.
|
||||
/// </summary>
|
||||
public class DeleteInfo
|
||||
{
|
||||
/// <summary>ID удаленного сообщения.</summary>
|
||||
public required string MessageId { get; init; }
|
||||
|
||||
/// <summary>Дата удаления.</summary>
|
||||
public DateTime DeleteDate { get; init; }
|
||||
|
||||
/// <summary>Удалено ли массово.</summary>
|
||||
public bool IsBulkDelete { get; init; }
|
||||
}
|
||||
16
BotPages.Core/Context/EditInfo.cs
Normal file
16
BotPages.Core/Context/EditInfo.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace BotPages.Core.Context;
|
||||
|
||||
/// <summary>
|
||||
/// Информация о редактировании сообщения.
|
||||
/// </summary>
|
||||
public class EditInfo
|
||||
{
|
||||
/// <summary>Новый текст сообщения.</summary>
|
||||
public string? NewText { get; init; }
|
||||
|
||||
/// <summary>Дата редактирования.</summary>
|
||||
public DateTime EditDate { get; init; }
|
||||
|
||||
/// <summary>Были ли изменены кнопки.</summary>
|
||||
public bool ButtonsChanged { get; init; }
|
||||
}
|
||||
@@ -16,9 +16,14 @@ public sealed class PageContext
|
||||
|
||||
/// <summary>Хранилище состояния.</summary>
|
||||
public required IStateStorage StateStorage { get; init; }
|
||||
|
||||
/// <summary>Сервис навигации.</summary>
|
||||
public required NavigationService Navigation { get; init; }
|
||||
/// <summary>Адаптер мессенджера.</summary>
|
||||
|
||||
/// <summary>Фабрика адаптеров (для получения других адаптеров).</summary>
|
||||
public required IMessengerAdapterFactory AdapterFactory { get; init; }
|
||||
|
||||
/// <summary>Текущий адаптер мессенджера.</summary>
|
||||
public required IMessengerAdapter Adapter { get; init; }
|
||||
|
||||
/// <summary>
|
||||
@@ -26,4 +31,36 @@ public sealed class PageContext
|
||||
/// </summary>
|
||||
public IAlbumBuilder Albums => Adapter.CreateAlbumBuilder(this);
|
||||
|
||||
/// <summary>
|
||||
/// Получить адаптер по ID.
|
||||
/// </summary>
|
||||
public IMessengerAdapter GetAdapter(string adapterId)
|
||||
=> AdapterFactory.Resolve(adapterId);
|
||||
|
||||
/// <summary>
|
||||
/// Попытаться получить адаптер по ID.
|
||||
/// </summary>
|
||||
public bool TryGetAdapter(string adapterId, out IMessengerAdapter? adapter)
|
||||
=> AdapterFactory.TryResolve(adapterId, out adapter);
|
||||
|
||||
/// <summary>
|
||||
/// Получить все адаптеры определенного типа.
|
||||
/// </summary>
|
||||
public IReadOnlyList<IMessengerAdapter> GetAdaptersByType(string adapterType)
|
||||
=> AdapterFactory.GetAdaptersByType(adapterType);
|
||||
|
||||
/// <summary>
|
||||
/// Получить текущий тип адаптера.
|
||||
/// </summary>
|
||||
public string CurrentAdapterType => Update.AdapterType;
|
||||
|
||||
/// <summary>
|
||||
/// Получить текущий ID адаптера.
|
||||
/// </summary>
|
||||
public string CurrentAdapterId => Update.AdapterId;
|
||||
|
||||
/// <summary>
|
||||
/// Получить все адаптеры.
|
||||
/// </summary>
|
||||
public IReadOnlyList<IMessengerAdapter> AllAdapters => AdapterFactory.AllAdapters;
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using BotPages.Core.Abstractions;
|
||||
using BotPages.Core.Messaging;
|
||||
|
||||
namespace BotPages.Core;
|
||||
|
||||
@@ -19,4 +20,108 @@ public static class PageContextAdapterExtensions
|
||||
/// </summary>
|
||||
public static Task DeleteAsync(this PageContext ctx, string chatId, string messageId, CancellationToken ct = default)
|
||||
=> ctx.Adapter.DeleteAsync(chatId, messageId, ct);
|
||||
|
||||
/// <summary>
|
||||
/// Удалить сообщение (используя ChatId из контекста).
|
||||
/// </summary>
|
||||
public static Task DeleteAsync(this PageContext ctx, string messageId, CancellationToken ct = default)
|
||||
=> ctx.Adapter.DeleteAsync(ctx.Update.Chat.Id, messageId, ct);
|
||||
|
||||
/// <summary>
|
||||
/// Удалить несколько сообщений.
|
||||
/// </summary>
|
||||
public static Task<bool> DeleteMultipleAsync(this PageContext ctx, string chatId, IEnumerable<string> messageIds, CancellationToken ct = default)
|
||||
=> ctx.Adapter.DeleteMultipleAsync(chatId, messageIds, ct);
|
||||
|
||||
/// <summary>
|
||||
/// Удалить несколько сообщений (используя ChatId из контекста).
|
||||
/// </summary>
|
||||
public static Task<bool> DeleteMultipleAsync(this PageContext ctx, IEnumerable<string> messageIds, CancellationToken ct = default)
|
||||
=> ctx.Adapter.DeleteMultipleAsync(ctx.Update.Chat.Id, messageIds, ct);
|
||||
|
||||
/// <summary>
|
||||
/// Редактировать текст сообщения.
|
||||
/// </summary>
|
||||
public static Task<string?> EditTextAsync(this PageContext ctx, string chatId, string messageId, string text,
|
||||
MessageFormat? format = null, CancellationToken ct = default)
|
||||
=> ctx.Adapter.EditTextAsync(chatId, messageId, text, format, ct);
|
||||
|
||||
/// <summary>
|
||||
/// Редактировать текст сообщения (используя ChatId из контекста).
|
||||
/// </summary>
|
||||
public static Task<string?> EditTextAsync(this PageContext ctx, string messageId, string text,
|
||||
MessageFormat? format = null, CancellationToken ct = default)
|
||||
=> ctx.Adapter.EditTextAsync(ctx.Update.Chat.Id, messageId, text, format, ct);
|
||||
|
||||
/// <summary>
|
||||
/// Редактировать кнопки сообщения.
|
||||
/// </summary>
|
||||
public static Task<string?> EditButtonsAsync(this PageContext ctx, string chatId, string messageId,
|
||||
IEnumerable<IEnumerable<InlineButton>>? inlineButtons = null, CancellationToken ct = default)
|
||||
=> ctx.Adapter.EditButtonsAsync(chatId, messageId, inlineButtons, ct);
|
||||
|
||||
/// <summary>
|
||||
/// Редактировать кнопки сообщения (используя ChatId из контекста).
|
||||
/// </summary>
|
||||
public static Task<string?> EditButtonsAsync(this PageContext ctx, string messageId,
|
||||
IEnumerable<IEnumerable<InlineButton>>? inlineButtons = null, CancellationToken ct = default)
|
||||
=> ctx.Adapter.EditButtonsAsync(ctx.Update.Chat.Id, messageId, inlineButtons, ct);
|
||||
|
||||
/// <summary>
|
||||
/// Закрепить сообщение.
|
||||
/// </summary>
|
||||
public static Task<bool> PinMessageAsync(this PageContext ctx, string chatId, string messageId,
|
||||
bool disableNotification = false, CancellationToken ct = default)
|
||||
=> ctx.Adapter.PinMessageAsync(chatId, messageId, disableNotification, ct);
|
||||
|
||||
/// <summary>
|
||||
/// Закрепить сообщение (используя ChatId из контекста).
|
||||
/// </summary>
|
||||
public static Task<bool> PinMessageAsync(this PageContext ctx, string messageId,
|
||||
bool disableNotification = false, CancellationToken ct = default)
|
||||
=> ctx.Adapter.PinMessageAsync(ctx.Update.Chat.Id, messageId, disableNotification, ct);
|
||||
|
||||
/// <summary>
|
||||
/// Открепить сообщение.
|
||||
/// </summary>
|
||||
public static Task<bool> UnpinMessageAsync(this PageContext ctx, string chatId, string messageId,
|
||||
CancellationToken ct = default)
|
||||
=> ctx.Adapter.UnpinMessageAsync(chatId, messageId, ct);
|
||||
|
||||
/// <summary>
|
||||
/// Открепить сообщение (используя ChatId из контекста).
|
||||
/// </summary>
|
||||
public static Task<bool> UnpinMessageAsync(this PageContext ctx, string messageId,
|
||||
CancellationToken ct = default)
|
||||
=> ctx.Adapter.UnpinMessageAsync(ctx.Update.Chat.Id, messageId, ct);
|
||||
|
||||
/// <summary>
|
||||
/// Получить информацию о сообщении.
|
||||
/// </summary>
|
||||
public static Task<MessageInfo?> GetMessageInfoAsync(this PageContext ctx, string chatId, string messageId,
|
||||
CancellationToken ct = default)
|
||||
=> ctx.Adapter.GetMessageInfoAsync(chatId, messageId, ct);
|
||||
|
||||
/// <summary>
|
||||
/// Получить информацию о сообщении (используя ChatId из контекста).
|
||||
/// </summary>
|
||||
public static Task<MessageInfo?> GetMessageInfoAsync(this PageContext ctx, string messageId,
|
||||
CancellationToken ct = default)
|
||||
=> ctx.Adapter.GetMessageInfoAsync(ctx.Update.Chat.Id, messageId, ct);
|
||||
|
||||
/// <summary>
|
||||
/// Переслать сообщение.
|
||||
/// </summary>
|
||||
public static Task<string?> ForwardMessageAsync(this PageContext ctx, string fromChatId, string messageId,
|
||||
string toChatId, bool disableNotification = false, CancellationToken ct = default)
|
||||
=> ctx.Adapter.ForwardMessageAsync(fromChatId, messageId, toChatId, disableNotification, ct);
|
||||
|
||||
/// <summary>
|
||||
/// Копировать сообщение.
|
||||
/// </summary>
|
||||
public static Task<string?> CopyMessageAsync(this PageContext ctx, string fromChatId, string messageId,
|
||||
string toChatId, string? caption = null, MessageFormat? captionFormat = null,
|
||||
bool disableNotification = false, CancellationToken ct = default)
|
||||
=> ctx.Adapter.CopyMessageAsync(fromChatId, messageId, toChatId, caption, captionFormat,
|
||||
disableNotification, ct);
|
||||
}
|
||||
16
BotPages.Core/Context/PinInfo.cs
Normal file
16
BotPages.Core/Context/PinInfo.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace BotPages.Core.Context;
|
||||
|
||||
/// <summary>
|
||||
/// Информация о закреплении сообщения.
|
||||
/// </summary>
|
||||
public class PinInfo
|
||||
{
|
||||
/// <summary>ID закрепленного сообщения.</summary>
|
||||
public required string MessageId { get; init; }
|
||||
|
||||
/// <summary>Дата закрепления.</summary>
|
||||
public DateTime PinDate { get; init; }
|
||||
|
||||
/// <summary>Отключено ли уведомление.</summary>
|
||||
public bool NotificationDisabled { get; init; }
|
||||
}
|
||||
@@ -1,25 +1,6 @@
|
||||
namespace BotPages.Core.Context;
|
||||
using BotPages.Core.Abstractions;
|
||||
|
||||
using BotPages.Core.Abstractions;
|
||||
|
||||
/// <summary>
|
||||
/// Тип входящего обновления.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum UpdateKind
|
||||
{
|
||||
/// <summary>Неизвестное сообщение.</summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>Текстовое сообщение.</summary>
|
||||
Text = 1 << 0,
|
||||
|
||||
/// <summary>Файлы (один или несколько).</summary>
|
||||
File = 1 << 1,
|
||||
|
||||
/// <summary>Нажатие кнопки.</summary>
|
||||
Button = 1 << 2,
|
||||
}
|
||||
namespace BotPages.Core.Context;
|
||||
|
||||
/// <summary>
|
||||
/// Контекст входящего обновления от мессенджера.
|
||||
@@ -27,8 +8,11 @@ public enum UpdateKind
|
||||
/// </summary>
|
||||
public sealed class UpdateContext
|
||||
{
|
||||
/// <summary>Тип мессенджера.</summary>
|
||||
public required string MessengerType { get; init; }
|
||||
/// <summary>Идентификатор адаптера, от которого пришло обновление.</summary>
|
||||
public required string AdapterId { get; init; }
|
||||
|
||||
/// <summary>Тип адаптера (определяется адаптером).</summary>
|
||||
public required string AdapterType { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Данные пользователя, от которого пришло обновление.
|
||||
@@ -51,9 +35,34 @@ public sealed class UpdateContext
|
||||
/// </summary>
|
||||
public string? Text { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// ID сообщения, к которому относится обновление.
|
||||
/// </summary>
|
||||
public string? MessageId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// ID сообщения, на которое дан ответ (если есть).
|
||||
/// </summary>
|
||||
public string? ReplyToMessageId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Список файлов, если Kind = File.
|
||||
/// Может содержать один или несколько файлов.
|
||||
/// </summary>
|
||||
public List<FileDescriptor> Files { get; init; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Информация о редактировании (если Kind = Edit).
|
||||
/// </summary>
|
||||
public EditInfo? EditInfo { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Информация об удалении (если Kind = Delete).
|
||||
/// </summary>
|
||||
public DeleteInfo? DeleteInfo { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Информация о закреплении (если Kind = Pin).
|
||||
/// </summary>
|
||||
public PinInfo? PinInfo { get; init; }
|
||||
}
|
||||
|
||||
32
BotPages.Core/Context/UpdateKind.cs
Normal file
32
BotPages.Core/Context/UpdateKind.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
namespace BotPages.Core.Context;
|
||||
|
||||
/// <summary>
|
||||
/// Тип входящего обновления.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum UpdateKind
|
||||
{
|
||||
/// <summary>Неизвестное сообщение.</summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>Текстовое сообщение.</summary>
|
||||
Text = 1 << 0,
|
||||
|
||||
/// <summary>Файлы (один или несколько).</summary>
|
||||
File = 1 << 1,
|
||||
|
||||
/// <summary>Нажатие кнопки.</summary>
|
||||
Button = 1 << 2,
|
||||
|
||||
/// <summary>Редактирование сообщения.</summary>
|
||||
Edit = 1 << 3,
|
||||
|
||||
/// <summary>Удаление сообщения.</summary>
|
||||
Delete = 1 << 4,
|
||||
|
||||
/// <summary>Закрепление сообщения.</summary>
|
||||
Pin = 1 << 5,
|
||||
|
||||
/// <summary>Ответ на сообщение.</summary>
|
||||
Reply = 1 << 6,
|
||||
}
|
||||
Reference in New Issue
Block a user