Compare commits
2 Commits
v0.3.4
...
41986987b1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41986987b1 | ||
| 246a5cb278 |
@@ -17,21 +17,21 @@ public interface IMessengerAdapter
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Отправить текстовое сообщение в чат.
|
/// Отправить текстовое сообщение в чат.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Task<string?> SendTextAsync(string chatId,
|
Task<string?> SendTextAsync(string chatId,
|
||||||
string text,
|
string text,
|
||||||
MessageFormat format = MessageFormat.Plain,
|
MessageFormat format = MessageFormat.Plain,
|
||||||
IEnumerable<IEnumerable<InlineButton>>? inline = null,
|
IEnumerable<IEnumerable<InlineButton>>? inline = null,
|
||||||
IEnumerable<IEnumerable<ReplyButton>>? reply = null,
|
IEnumerable<IEnumerable<ReplyButton>>? reply = null,
|
||||||
string? messageId = null,
|
string? messageId = null,
|
||||||
CancellationToken ct = default
|
CancellationToken ct = default
|
||||||
);
|
);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Отправить файл в чат.
|
/// Отправить файл в чат.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Task SendFileAsync(string chatId,
|
Task SendFileAsync(string chatId,
|
||||||
FileDescriptor file,
|
FileDescriptor file,
|
||||||
string? caption = null,
|
string? caption = null,
|
||||||
MessageFormat? captionFormat = null,
|
MessageFormat? captionFormat = null,
|
||||||
IEnumerable<IEnumerable<InlineButton>>? inline = null,
|
IEnumerable<IEnumerable<InlineButton>>? inline = null,
|
||||||
IEnumerable<IEnumerable<ReplyButton>>? reply = null,
|
IEnumerable<IEnumerable<ReplyButton>>? reply = null,
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using BotPages.Core.Abstractions;
|
namespace BotPages.Core;
|
||||||
|
|
||||||
namespace BotPages.Core;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Данные чата.
|
/// Данные чата.
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using BotPages.Core.Abstractions;
|
using BotPages.Core.Abstractions;
|
||||||
using BotPages.Core.Context;
|
using BotPages.Core.Context;
|
||||||
using BotPages.Core.Messaging;
|
|
||||||
|
|
||||||
namespace BotPages.Core;
|
namespace BotPages.Core;
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ public static class PageContextAdapterExtensions
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Отправить текстовое сообщение.
|
/// Отправить текстовое сообщение.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static Task<string?> SendTextAsync(this PageContext ctx,
|
public static Task<string?> SendTextAsync(this PageContext ctx,
|
||||||
string text,
|
string text,
|
||||||
MessageFormat format = MessageFormat.Plain,
|
MessageFormat format = MessageFormat.Plain,
|
||||||
IEnumerable<IEnumerable<InlineButton>>? inline = null,
|
IEnumerable<IEnumerable<InlineButton>>? inline = null,
|
||||||
IEnumerable<IEnumerable<ReplyButton>>? reply = null,
|
IEnumerable<IEnumerable<ReplyButton>>? reply = null,
|
||||||
@@ -23,17 +23,17 @@ public static class PageContextAdapterExtensions
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Отправить файл.
|
/// Отправить файл.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static Task SendFileAsync(this PageContext ctx,
|
public static Task SendFileAsync(this PageContext ctx,
|
||||||
FileDescriptor file,
|
FileDescriptor file,
|
||||||
string? caption = null,
|
string? caption = null,
|
||||||
MessageFormat? captionFormat = null,
|
MessageFormat? captionFormat = null,
|
||||||
IEnumerable<IEnumerable<InlineButton>>? inline = null,
|
IEnumerable<IEnumerable<InlineButton>>? inline = null,
|
||||||
IEnumerable<IEnumerable<ReplyButton>>? reply = null,
|
IEnumerable<IEnumerable<ReplyButton>>? reply = null,
|
||||||
CancellationToken ct = default
|
CancellationToken ct = default
|
||||||
)
|
)
|
||||||
=> ctx.Adapter.SendFileAsync(chatId: ctx.Update.Chat.Id,
|
=> ctx.Adapter.SendFileAsync(chatId: ctx.Update.Chat.Id,
|
||||||
file: file,
|
file: file,
|
||||||
caption: caption,
|
caption: caption,
|
||||||
captionFormat: captionFormat,
|
captionFormat: captionFormat,
|
||||||
inline: inline,
|
inline: inline,
|
||||||
reply: reply,
|
reply: reply,
|
||||||
|
|||||||
@@ -1,10 +1,4 @@
|
|||||||
using System;
|
namespace BotPages.Core.Routing;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace BotPages.Core.Routing;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обработчик команды: получает контекст страницы, аргументы команды и токен отмены.
|
/// Обработчик команды: получает контекст страницы, аргументы команды и токен отмены.
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ internal sealed class RoutesRegistry
|
|||||||
|
|
||||||
internal void Map(Type? type)
|
internal void Map(Type? type)
|
||||||
{
|
{
|
||||||
foreach(var attr in type.GetCustomAttributes<RouteAttribute>(inherit: true))
|
foreach (var attr in type.GetCustomAttributes<RouteAttribute>(inherit: true))
|
||||||
{
|
{
|
||||||
_routes.Add(attr.Template, type);
|
_routes.Add(attr.Template, type);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ using System.Linq;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
using Telegram.Bot.Exceptions;
|
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
using Telegram.Bot.Types.ReplyMarkups;
|
using Telegram.Bot.Types.ReplyMarkups;
|
||||||
@@ -76,15 +75,6 @@ public sealed class TelegramAdapter : IMessangerAdapterSetup
|
|||||||
errorHandler: async (_, ex, ct2) =>
|
errorHandler: async (_, ex, ct2) =>
|
||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Warn, $"{MessengerType} error.", ex);
|
_logger.Log(LogLevel.Warn, $"{MessengerType} error.", ex);
|
||||||
|
|
||||||
if (ex is ApiRequestException apiEx)
|
|
||||||
{
|
|
||||||
if (apiEx.ErrorCode == 409)
|
|
||||||
{
|
|
||||||
_logger.Log(LogLevel.Critical, $"{MessengerType} остановлен.");
|
|
||||||
await _.Close(ct2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await Task.CompletedTask;
|
await Task.CompletedTask;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -100,11 +90,11 @@ public sealed class TelegramAdapter : IMessangerAdapterSetup
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task<string?> SendTextAsync(string chatId, string text,
|
public async Task<string?> SendTextAsync(string chatId, string text,
|
||||||
MessageFormat format = MessageFormat.Plain,
|
MessageFormat format = MessageFormat.Plain,
|
||||||
IEnumerable<IEnumerable<InlineButton>>? inline = null,
|
IEnumerable<IEnumerable<InlineButton>>? inline = null,
|
||||||
IEnumerable<IEnumerable<ReplyButton>>? reply = null,
|
IEnumerable<IEnumerable<ReplyButton>>? reply = null,
|
||||||
string? messageId = null,
|
string? messageId = null,
|
||||||
CancellationToken ct = default)
|
CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
if (_client is null)
|
if (_client is null)
|
||||||
@@ -203,9 +193,9 @@ public sealed class TelegramAdapter : IMessangerAdapterSetup
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task SendFileAsync(string chatId,
|
public async Task SendFileAsync(string chatId,
|
||||||
FileDescriptor file,
|
FileDescriptor file,
|
||||||
string? caption = null,
|
string? caption = null,
|
||||||
MessageFormat? captionFormat = null,
|
MessageFormat? captionFormat = null,
|
||||||
IEnumerable<IEnumerable<InlineButton>>? inline = null,
|
IEnumerable<IEnumerable<InlineButton>>? inline = null,
|
||||||
IEnumerable<IEnumerable<ReplyButton>>? reply = null,
|
IEnumerable<IEnumerable<ReplyButton>>? reply = null,
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using BotPages.Core;
|
using BotPages.Core;
|
||||||
using BotPages.Core.Abstractions;
|
using BotPages.Core.Abstractions;
|
||||||
using BotPages.Core.Messaging;
|
using BotPages.Core.Messaging;
|
||||||
using BotPages.Core.Routing;
|
|
||||||
|
|
||||||
namespace Demo.Pages;
|
namespace Demo.Pages;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user