Убраны старые api
This commit is contained in:
@@ -14,66 +14,4 @@ public static class PageContextAdapterExtensions
|
||||
/// </summary>
|
||||
public static Task<string?> SendAsync(this PageContext ctx, SendRequest request, CancellationToken ct = default)
|
||||
=> ctx.Adapter.SendAsync(request, ct);
|
||||
|
||||
/// <summary>
|
||||
/// Удобная оболочка: отправить текстовое сообщение.
|
||||
/// </summary>
|
||||
public static Task<string?> SendTextAsync(this PageContext ctx,
|
||||
string text,
|
||||
MessageFormat format = MessageFormat.Plain,
|
||||
IEnumerable<IEnumerable<InlineButton>>? inline = null,
|
||||
IEnumerable<IEnumerable<ReplyButton>>? reply = null,
|
||||
string? messageId = null,
|
||||
object? adapterOptions = null,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
var bag = adapterOptions switch
|
||||
{
|
||||
null => null,
|
||||
AdapterOptionsBag b => b,
|
||||
_ => throw new ArgumentException("adapterOptions must be an AdapterOptionsBag or null. Use MessageBuilder extensions to set adapter options.", nameof(adapterOptions))
|
||||
};
|
||||
|
||||
return ctx.SendAsync(new SendRequest
|
||||
{
|
||||
ChatId = ctx.Update.Chat.Id,
|
||||
Text = text,
|
||||
TextFormat = format,
|
||||
Inline = inline,
|
||||
Reply = reply,
|
||||
MessageId = messageId,
|
||||
AdapterOptions = bag
|
||||
}, ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удобная оболочка: отправить файл.
|
||||
/// </summary>
|
||||
public static Task<string?> SendFileAsync(this PageContext ctx,
|
||||
FileDescriptor file,
|
||||
string? caption = null,
|
||||
MessageFormat? captionFormat = null,
|
||||
IEnumerable<IEnumerable<InlineButton>>? inline = null,
|
||||
IEnumerable<IEnumerable<ReplyButton>>? reply = null,
|
||||
object? adapterOptions = null,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
var bag = adapterOptions switch
|
||||
{
|
||||
null => null,
|
||||
AdapterOptionsBag b => b,
|
||||
_ => throw new ArgumentException("adapterOptions must be an AdapterOptionsBag or null. Use MessageBuilder extensions to set adapter options.", nameof(adapterOptions))
|
||||
};
|
||||
|
||||
return ctx.SendAsync(new SendRequest
|
||||
{
|
||||
ChatId = ctx.Update.Chat.Id,
|
||||
File = file,
|
||||
Caption = caption,
|
||||
CaptionFormat = captionFormat,
|
||||
Inline = inline,
|
||||
Reply = reply,
|
||||
AdapterOptions = bag
|
||||
}, ct);
|
||||
}
|
||||
}
|
||||
@@ -25,10 +25,10 @@ public sealed class MessageBuilder
|
||||
/// <summary>
|
||||
/// Установить опции для конкретного адаптера. Ключ адаптера определяется адаптером (напр., "telegram").
|
||||
/// </summary>
|
||||
public MessageBuilder WithAdapterOption<T>(string adapterKey, T options)
|
||||
public MessageBuilder WithAdapterOption<T>(string adapterType, T options)
|
||||
{
|
||||
if (_adapterOptions is null) _adapterOptions = new AdapterOptionsBag();
|
||||
_adapterOptions.Set(adapterKey, options);
|
||||
_adapterOptions.Set(adapterType, options);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -141,13 +141,35 @@ public sealed class MessageBuilder
|
||||
// Текст
|
||||
if (!string.IsNullOrWhiteSpace(_text))
|
||||
{
|
||||
messageId = await _ctx.SendTextAsync(_text, _format, _inline, reply, _editMessageId, _adapterOptions, ct);
|
||||
var req = new SendRequest
|
||||
{
|
||||
ChatId = _ctx.Update.Chat.Id,
|
||||
Text = _text,
|
||||
TextFormat = _format,
|
||||
Inline = _inline,
|
||||
Reply = reply,
|
||||
MessageId = _editMessageId,
|
||||
AdapterOptions = _adapterOptions
|
||||
};
|
||||
|
||||
messageId = await _ctx.SendAsync(req, ct);
|
||||
}
|
||||
|
||||
// Файлы
|
||||
foreach (var (file, caption, captionFormat) in _files)
|
||||
{
|
||||
var res = await _ctx.SendFileAsync(file, caption, captionFormat, _inline, reply, _adapterOptions, ct);
|
||||
var req = new SendRequest
|
||||
{
|
||||
ChatId = _ctx.Update.Chat.Id,
|
||||
File = file,
|
||||
Caption = caption,
|
||||
CaptionFormat = captionFormat,
|
||||
Inline = _inline,
|
||||
Reply = reply,
|
||||
AdapterOptions = _adapterOptions
|
||||
};
|
||||
|
||||
var res = await _ctx.SendAsync(req, ct);
|
||||
// сохранить первый возвращённый id сообщения
|
||||
if (messageId is null && res is not null) messageId = res;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user