Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5085958219 | |||
| 634a9292dc | |||
| a94327f0c8 |
@@ -1,4 +1,5 @@
|
||||
using BotPages.Core.Messaging;
|
||||
using BotPages.Core.Context;
|
||||
using BotPages.Core.Messaging;
|
||||
|
||||
namespace BotPages.Core.Abstractions;
|
||||
|
||||
@@ -8,17 +9,19 @@ namespace BotPages.Core.Abstractions;
|
||||
/// </summary>
|
||||
public interface IMessengerAdapter
|
||||
{
|
||||
Capabilities Capabilities { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Отправить текстовое сообщение в чат.
|
||||
/// </summary>
|
||||
Task SendTextAsync(PageContext ctx, string text, MessageFormat format,
|
||||
Task SendTextAsync(string chatId, string text, MessageFormat format,
|
||||
IEnumerable<IEnumerable<InlineButton>>? inline,
|
||||
IEnumerable<IEnumerable<ReplyButton>>? reply, CancellationToken ct);
|
||||
|
||||
/// <summary>
|
||||
/// Отправить файл в чат.
|
||||
/// </summary>
|
||||
Task SendFileAsync(PageContext ctx, FileDescriptor file, string? caption, CancellationToken ct);
|
||||
Task SendFileAsync(string chatId, FileDescriptor file, string? caption, CancellationToken ct);
|
||||
|
||||
/// <summary>
|
||||
/// Создать билдер альбома для отправки медиагруппы.
|
||||
@@ -40,3 +43,17 @@ public interface IMessengerAdapter
|
||||
/// </summary>
|
||||
Task OnLeaveAsync(PageContext ctx, CancellationToken ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Контракт конфигурации адаптера.
|
||||
/// </summary>
|
||||
public interface IMessangerAdapterSetup : IMessengerAdapter
|
||||
{
|
||||
/// <summary>
|
||||
/// Запуск работы адаптера
|
||||
/// </summary>
|
||||
/// <param name="onUpdate"></param>
|
||||
/// <param name="ct"></param>
|
||||
/// <returns></returns>
|
||||
Task StartAdapterAsync(Func<UpdateContext, Task> onUpdate, CancellationToken ct);
|
||||
}
|
||||
@@ -4,16 +4,35 @@ namespace BotPages.Core.Abstractions;
|
||||
|
||||
/// <summary>
|
||||
/// Фабрика адаптеров мессенджеров.
|
||||
/// Используется для разрешения конкретного <see cref="IMessengerAdapter"/> по типу мессенджера.
|
||||
/// Используется для разрешения конкретного <see cref="IMessangerAdapterSetup"/> по типу мессенджера.
|
||||
/// </summary>
|
||||
public interface IMessengerAdapterFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Список зарегистрированных адаптеров.
|
||||
/// </summary>
|
||||
Dictionary<string, IMessangerAdapterSetup> Adapters { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Зарегистрировать адаптер для указанного типа мессенджера.
|
||||
/// </summary>
|
||||
/// <param name="messengerType">
|
||||
/// Тип мессенджера (например, "Telegram", "Slack", "VK").
|
||||
/// </param>
|
||||
/// <param name="adapter">
|
||||
/// Экземпляр адаптера, реализующий <see cref="IMessengerAdapter"/>.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// Текущий экземпляр <see cref="MultiAdapterFactory"/> для цепочки вызовов.
|
||||
/// </returns>
|
||||
IMessengerAdapterFactory Register(string messengerType, IMessangerAdapterSetup adapter);
|
||||
|
||||
/// <summary>
|
||||
/// Получить адаптер для указанного мессенджера.
|
||||
/// </summary>
|
||||
/// <param name="messengerType">
|
||||
/// Тип мессенджера (например, "Telegram", "Slack", "VK").
|
||||
/// Значение должно совпадать с <see cref="UpdateContext.User"/>.<see cref="UserContext.MessengerType"/>.
|
||||
/// Значение должно совпадать с <see cref="UpdateContext.MessengerType"/>.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// Экземпляр <see cref="IMessengerAdapter"/>, зарегистрированный для данного типа мессенджера.
|
||||
|
||||
@@ -6,7 +6,12 @@
|
||||
/// </summary>
|
||||
public sealed class MultiAdapterFactory : IMessengerAdapterFactory
|
||||
{
|
||||
private readonly Dictionary<string, IMessengerAdapter> _adapters = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly Dictionary<string, IMessangerAdapterSetup> _adapters = new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
/// <summary>
|
||||
/// Список зарегистрированных адаптеров.
|
||||
/// </summary>
|
||||
public Dictionary<string, IMessangerAdapterSetup> Adapters => _adapters;
|
||||
|
||||
/// <summary>
|
||||
/// Зарегистрировать адаптер для указанного типа мессенджера.
|
||||
@@ -20,7 +25,7 @@ public sealed class MultiAdapterFactory : IMessengerAdapterFactory
|
||||
/// <returns>
|
||||
/// Текущий экземпляр <see cref="MultiAdapterFactory"/> для цепочки вызовов.
|
||||
/// </returns>
|
||||
public MultiAdapterFactory Register(string messengerType, IMessengerAdapter adapter)
|
||||
public IMessengerAdapterFactory Register(string messengerType, IMessangerAdapterSetup adapter)
|
||||
{
|
||||
_adapters[messengerType] = adapter;
|
||||
return this;
|
||||
|
||||
@@ -19,16 +19,30 @@ public sealed class BotPagesApp
|
||||
private readonly ILogger _logger;
|
||||
private readonly NavigationService _navigation;
|
||||
|
||||
/// <summary>
|
||||
/// Серсвис логирования.
|
||||
/// </summary>
|
||||
public ILogger Logger => _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Создать приложение BotPages.
|
||||
/// </summary>
|
||||
public BotPagesApp(IMessengerAdapterFactory adapterFactory, IStateStorage state, ILogger logger)
|
||||
public BotPagesApp(IStateStorage state, ILogger logger)
|
||||
{
|
||||
_adapterFactory = adapterFactory;
|
||||
_state = state;
|
||||
_logger = logger;
|
||||
|
||||
_navigation = new NavigationService(_routes);
|
||||
_adapterFactory = new MultiAdapterFactory();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавить адаптер.
|
||||
/// </summary>
|
||||
public BotPagesApp AddAdapter(string messengerType, IMessangerAdapterSetup adapter)
|
||||
{
|
||||
_adapterFactory.Register(messengerType, adapter);
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -173,4 +187,17 @@ public sealed class BotPagesApp
|
||||
/// </summary>
|
||||
private Page? ResolveCurrentPage(PageContext ctx)
|
||||
=> _navigation.ResolveCurrentPage(ctx);
|
||||
|
||||
/// <summary>
|
||||
/// Сборка и запуск приложения.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task Build(CancellationToken cancellationToken)
|
||||
{
|
||||
foreach (var adapter in _adapterFactory.Adapters)
|
||||
{
|
||||
await adapter.Value.StartAdapterAsync(update => HandleUpdateAsync(update, cancellationToken), cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,4 @@ public sealed class ChatContext
|
||||
|
||||
/// <summary>Идентификатор треда (опционально).</summary>
|
||||
public string? ThreadId { get; init; }
|
||||
|
||||
/// <summary>Возможности мессенджера.</summary>
|
||||
public Capabilities Capabilities { get; init; } = new();
|
||||
}
|
||||
|
||||
@@ -49,13 +49,13 @@ public sealed class PageContext
|
||||
IEnumerable<IEnumerable<InlineButton>>? inline = null,
|
||||
IEnumerable<IEnumerable<ReplyButton>>? reply = null,
|
||||
CancellationToken ct = default)
|
||||
=> Adapter.SendTextAsync(this, text, format, inline, reply, ct);
|
||||
=> Adapter.SendTextAsync(this.Update.Chat.Id, text, format, inline, reply, ct);
|
||||
|
||||
/// <summary>
|
||||
/// Отправить файл.
|
||||
/// </summary>
|
||||
public Task SendFileAsync(FileDescriptor file, string? caption = null, CancellationToken ct = default)
|
||||
=> Adapter.SendFileAsync(this, file, caption, ct);
|
||||
=> Adapter.SendFileAsync(this.Update.Chat.Id, file, caption, ct);
|
||||
|
||||
/// <summary>
|
||||
/// Получить билдер альбомов.
|
||||
|
||||
@@ -25,6 +25,9 @@ public class ButtonAttribute : Attribute
|
||||
public string? Value { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Расширение для работы с кнопками.
|
||||
/// </summary>
|
||||
public static class ButtonExtensions
|
||||
{
|
||||
private static readonly Dictionary<Type, Dictionary<string, object>> _cacheName = new();
|
||||
|
||||
@@ -31,6 +31,7 @@ public sealed class InMemoryStateStorage : IStateStorage
|
||||
public Task<bool> RemoveAsync(CompositeSessionKey session, string key, CancellationToken ct)
|
||||
=> Task.FromResult(_store.TryGetValue(session, out var dict) ? dict.TryRemove(key, out _) : true);
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<bool> ClearAsync(CompositeSessionKey session, CancellationToken ct)
|
||||
=> Task.FromResult(_store.TryRemove(session, out _));
|
||||
}
|
||||
26
BotPages.Telegram/BotPagesAppExtension.cs
Normal file
26
BotPages.Telegram/BotPagesAppExtension.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using BotPages.Core;
|
||||
|
||||
namespace BotPages.Telegram;
|
||||
|
||||
/// <summary>
|
||||
/// Расширения для <see cref="BotPagesApp"/>.
|
||||
/// </summary>
|
||||
public static class BotPagesAppExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Добавление адаптера для телеграмм в <see cref="BotPages.Core.Abstractions.IMessengerAdapterFactory"/>
|
||||
/// </summary>
|
||||
/// <param name="app"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <param name="messengerType"></param>
|
||||
/// <returns></returns>
|
||||
public static BotPagesApp AddTelegramAdapter(this BotPagesApp app, string token, string messengerType = "")
|
||||
{
|
||||
var telegram = new TelegramAdapter(app.Logger, token);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(messengerType)) telegram.MessengerType = messengerType;
|
||||
|
||||
app.AddAdapter(telegram.MessengerType, telegram);
|
||||
return app;
|
||||
}
|
||||
}
|
||||
@@ -21,32 +21,56 @@ namespace BotPages.Telegram;
|
||||
/// Адаптер для Telegram на базе Telegram.Bot.
|
||||
/// Реализует отправку текста, кнопок, файлов, альбомов и прогресса.
|
||||
/// </summary>
|
||||
public sealed class TelegramAdapter : IMessengerAdapter
|
||||
public sealed class TelegramAdapter : IMessangerAdapterSetup
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private TelegramBotClient? _client;
|
||||
private string _token;
|
||||
private static Capabilities _capabilities = new()
|
||||
{
|
||||
SupportsInlineButtons = true,
|
||||
SupportsReplyButtons = true,
|
||||
SupportsAlbums = true,
|
||||
SupportsFormattingMarkdown = true,
|
||||
SupportsFormattingHtml = true,
|
||||
MaxMessageLength = 4096,
|
||||
};
|
||||
|
||||
/// <summary>Создать адаптер Telegram.</summary>
|
||||
public TelegramAdapter(ILogger logger) => _logger = logger;
|
||||
public TelegramAdapter(ILogger logger, string token)
|
||||
{
|
||||
_logger = logger;
|
||||
_token = token;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///Идентификатор мессенджера / адаптера
|
||||
/// </summary>
|
||||
public string MessengerType { get; set; } = "Telegram: " + Guid.NewGuid().ToString();
|
||||
|
||||
/// <summary>
|
||||
/// Доступные возможности адаптера.
|
||||
/// </summary>
|
||||
public Capabilities Capabilities => _capabilities;
|
||||
|
||||
/// <summary>
|
||||
/// Запустить polling для приема обновлений от Telegram.
|
||||
/// </summary>
|
||||
public async Task StartPollingAsync(string token, Func<UpdateContext, Task> onUpdate, CancellationToken ct)
|
||||
public async Task StartAdapterAsync(Func<UpdateContext, Task> onUpdate, CancellationToken ct)
|
||||
{
|
||||
_client = new TelegramBotClient(token);
|
||||
_client = new TelegramBotClient(_token);
|
||||
|
||||
_client.StartReceiving(
|
||||
updateHandler: async (_, update, ct2) =>
|
||||
{
|
||||
var mapped = TelegramUpdateMapper.Map(update, _client);
|
||||
var mapped = TelegramUpdateMapper.Map(MessengerType, update, _client);
|
||||
if (mapped is not null)
|
||||
await onUpdate(mapped);
|
||||
},
|
||||
|
||||
errorHandler: async (_, ex, ct2) =>
|
||||
{
|
||||
_logger.Log(LogLevel.Warn, "Telegram error.", ex);
|
||||
_logger.Log(LogLevel.Warn, $"{MessengerType} error.", ex);
|
||||
await Task.CompletedTask;
|
||||
},
|
||||
|
||||
@@ -55,19 +79,19 @@ public sealed class TelegramAdapter : IMessengerAdapter
|
||||
|
||||
|
||||
var me = await _client.GetMe();
|
||||
_logger.Log(LogLevel.Info, $"Telegram started: @{me.Username}");
|
||||
_logger.Log(LogLevel.Info, $"{MessengerType} started: @{me.Username}");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task SendTextAsync(PageContext ctx, string text, MessageFormat format,
|
||||
public async Task SendTextAsync(string chatId, string text, MessageFormat format,
|
||||
IEnumerable<IEnumerable<InlineButton>>? inline,
|
||||
IEnumerable<IEnumerable<ReplyButton>>? reply, CancellationToken ct)
|
||||
{
|
||||
if (_client is null)
|
||||
{
|
||||
_logger.Log(LogLevel.Critical, "Telegram client is not initialized.");
|
||||
_logger.Log(LogLevel.Critical, $"{MessengerType} client is not initialized.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -117,14 +141,14 @@ public sealed class TelegramAdapter : IMessengerAdapter
|
||||
}
|
||||
|
||||
// Длина сообщения
|
||||
if (text.Length > ctx.Update.Chat.Capabilities.MaxMessageLength)
|
||||
if (text.Length > Capabilities.MaxMessageLength)
|
||||
{
|
||||
_logger.Log(LogLevel.Warn, $"Message too long ({text.Length}). Truncated to {ctx.Update.Chat.Capabilities.MaxMessageLength}.");
|
||||
text = text.Substring(0, ctx.Update.Chat.Capabilities.MaxMessageLength);
|
||||
_logger.Log(LogLevel.Warn, $"Message too long ({text.Length}). Truncated to {Capabilities.MaxMessageLength}.");
|
||||
text = text.Substring(0, Capabilities.MaxMessageLength);
|
||||
}
|
||||
|
||||
await _client.SendMessage(
|
||||
chatId: long.Parse(ctx.Update.Chat.Id),
|
||||
chatId: long.Parse(chatId),
|
||||
text: text,
|
||||
parseMode: parseMode,
|
||||
replyMarkup: markup,
|
||||
@@ -133,16 +157,14 @@ public sealed class TelegramAdapter : IMessengerAdapter
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task SendFileAsync(PageContext ctx, FileDescriptor file, string? caption, CancellationToken ct)
|
||||
public async Task SendFileAsync(string chatId, FileDescriptor file, string? caption, CancellationToken ct)
|
||||
{
|
||||
if (_client is null)
|
||||
{
|
||||
_logger.Log(LogLevel.Critical, "Telegram client is not initialized.");
|
||||
_logger.Log(LogLevel.Critical, $"{MessengerType} client is not initialized.");
|
||||
return;
|
||||
}
|
||||
|
||||
var chatId = long.Parse(ctx.Update.Chat.Id);
|
||||
|
||||
// Получаем поток, если он задан
|
||||
Stream? stream = null;
|
||||
if (file.GetStreamAsync is not null)
|
||||
@@ -170,16 +192,16 @@ public sealed class TelegramAdapter : IMessengerAdapter
|
||||
switch (file.Kind)
|
||||
{
|
||||
case FileKind.Photo:
|
||||
await _client.SendPhoto(chatId, inputFile, caption ?? "", cancellationToken: ct);
|
||||
await _client.SendPhoto(long.Parse(chatId), inputFile, caption ?? "", cancellationToken: ct);
|
||||
break;
|
||||
case FileKind.Video:
|
||||
await _client.SendVideo(chatId, inputFile, caption: caption ?? "", cancellationToken: ct);
|
||||
await _client.SendVideo(long.Parse(chatId), inputFile, caption: caption ?? "", cancellationToken: ct);
|
||||
break;
|
||||
case FileKind.Audio:
|
||||
await _client.SendAudio(chatId, inputFile, caption ?? "", cancellationToken: ct);
|
||||
await _client.SendAudio(long.Parse(chatId), inputFile, caption ?? "", cancellationToken: ct);
|
||||
break;
|
||||
default:
|
||||
await _client.SendDocument(chatId, inputFile, caption ?? "", cancellationToken: ct);
|
||||
await _client.SendDocument(long.Parse(chatId), inputFile, caption ?? "", cancellationToken: ct);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -192,7 +214,7 @@ public sealed class TelegramAdapter : IMessengerAdapter
|
||||
{
|
||||
if (_client is null)
|
||||
{
|
||||
_logger.Log(LogLevel.Critical, "Telegram client is not initialized.");
|
||||
_logger.Log(LogLevel.Critical, $"{MessengerType} client is not initialized.");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -216,7 +238,7 @@ public sealed class TelegramAdapter : IMessengerAdapter
|
||||
{
|
||||
if (_client is null)
|
||||
{
|
||||
_logger.Log(LogLevel.Critical, "Telegram client is not initialized.");
|
||||
_logger.Log(LogLevel.Critical, $"{MessengerType} client is not initialized.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,11 +49,11 @@ public sealed class TelegramAlbumBuilder : IAlbumBuilder
|
||||
|
||||
var chatId = long.Parse(_ctx.Update.Chat.Id);
|
||||
|
||||
if (!_ctx.Update.Chat.Capabilities.SupportsAlbums)
|
||||
if (!_adapter.Capabilities.SupportsAlbums)
|
||||
{
|
||||
_logger.Log(LogLevel.Warn, "Albums not supported. Degraded to sequential sends.");
|
||||
foreach (var (file, caption) in _items)
|
||||
await _adapter.SendFileAsync(_ctx, file, caption, ct);
|
||||
await _adapter.SendFileAsync(_ctx.Update.Chat.Id, file, caption, ct);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public sealed class TelegramAlbumBuilder : IAlbumBuilder
|
||||
{
|
||||
// Telegram не поддерживает document в альбомах — деградация
|
||||
_logger.Log(LogLevel.Warn, $"Document '{file.Kind}' in album not supported. Sending document separately.");
|
||||
await _adapter.SendFileAsync(_ctx, file, caption, ct);
|
||||
await _adapter.SendFileAsync(_ctx.Update.Chat.Id, file, caption, ct);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public static class TelegramUpdateMapper
|
||||
/// <summary>
|
||||
/// Маппинг Telegram Update в UpdateContext BotPages.
|
||||
/// </summary>
|
||||
public static UpdateContext Map(Update update, TelegramBotClient client)
|
||||
public static UpdateContext Map(string MessengerType, Update update, TelegramBotClient client)
|
||||
{
|
||||
var chat = update.Message?.Chat ?? update.CallbackQuery?.Message?.Chat;
|
||||
var user = update.Message?.From ?? update.CallbackQuery?.From;
|
||||
@@ -34,15 +34,6 @@ public static class TelegramUpdateMapper
|
||||
{
|
||||
Id = chat?.Id.ToString() ?? "unknown",
|
||||
Title = chat?.Title,
|
||||
Capabilities = new Capabilities
|
||||
{
|
||||
SupportsInlineButtons = true,
|
||||
SupportsReplyButtons = true,
|
||||
SupportsAlbums = true,
|
||||
SupportsFormattingMarkdown = true,
|
||||
SupportsFormattingHtml = true,
|
||||
MaxMessageLength = 4096,
|
||||
}
|
||||
};
|
||||
|
||||
string? text = null;
|
||||
@@ -131,7 +122,7 @@ public static class TelegramUpdateMapper
|
||||
|
||||
return new UpdateContext
|
||||
{
|
||||
MessengerType = "Telegram",
|
||||
MessengerType = MessengerType,
|
||||
User = userContext,
|
||||
Chat = chatContext,
|
||||
Text = text,
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.Models
|
||||
namespace Demo.Models
|
||||
{
|
||||
internal class Request
|
||||
{
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using BotPages.Core;
|
||||
using BotPages.Core.Messaging;
|
||||
using System.Xml;
|
||||
|
||||
namespace Demo.Pages;
|
||||
|
||||
@@ -43,7 +42,8 @@ public sealed class DetailsPage : StatefullPage<DetailsArgs>
|
||||
await ctx.Navigation.GoToAsync<TitlePage>(ctx, ct);
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
;
|
||||
}
|
||||
|
||||
public override async Task OnText(PageContext ctx, string text, CancellationToken ct)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using BotPages.Core;
|
||||
using BotPages.Core.Abstractions;
|
||||
using BotPages.Core.Logging;
|
||||
using BotPages.Core.Middleware;
|
||||
using BotPages.Core.Storage;
|
||||
@@ -17,22 +16,15 @@ namespace Demo
|
||||
|
||||
var logger = new ConsoleLogger();
|
||||
var state = new InMemoryStateStorage();
|
||||
using var cts = new CancellationTokenSource();
|
||||
|
||||
var telegram = new TelegramAdapter(logger);
|
||||
var factory = new MultiAdapterFactory()
|
||||
.Register("Telegram", telegram);
|
||||
|
||||
var app = new BotPagesApp(factory, state, logger)
|
||||
var app = new BotPagesApp(state, logger)
|
||||
.AddDefaultPage<WelcomePage>()
|
||||
.MapCommand<WelcomePage>("/start")
|
||||
.AddMiddleware(new ErrorHandlingMiddleware(logger))
|
||||
.AddMiddleware(new LoggingMiddleware(logger));
|
||||
|
||||
using var cts = new CancellationTokenSource();
|
||||
|
||||
await telegram.StartPollingAsync(token,
|
||||
update => app.HandleUpdateAsync(update, CancellationToken.None),
|
||||
cts.Token);
|
||||
.AddMiddleware(new LoggingMiddleware(logger))
|
||||
.AddTelegramAdapter(token, "Telegram")
|
||||
.Build(cts.Token);
|
||||
|
||||
Console.ReadKey();
|
||||
cts.Cancel();
|
||||
|
||||
Reference in New Issue
Block a user