diff --git a/docs/Telegrator.Hosting.Web.xml b/docs/Telegrator.Hosting.Web.xml
index fbdb2ee..b1cdf24 100644
--- a/docs/Telegrator.Hosting.Web.xml
+++ b/docs/Telegrator.Hosting.Web.xml
@@ -35,7 +35,7 @@
- Service for receiving updates for Hosted telegram bots via Webhooks
+ Service for receiving updates for Hosted telegram bots via Webhooks and queuing them to router
@@ -95,6 +95,14 @@
Provides method to configure Telegram Bot WebHost
+
+
+ Adds WebhookerOptions to services
+
+
+
+
+
Searchs for hosted service inside hosts services
diff --git a/docs/Telegrator.Hosting.WideBot.xml b/docs/Telegrator.Hosting.WideBot.xml
index b48e7d6..fa5e33f 100644
--- a/docs/Telegrator.Hosting.WideBot.xml
+++ b/docs/Telegrator.Hosting.WideBot.xml
@@ -4,6 +4,116 @@
Telegrator.Hosting.WideBot
+
+
+ Service for receiving updates for Hosted wide telegram bots and queuing them to router
+
+
+
+
+
+
+
+
+ Service for receiving updates for Hosted wide telegram bots and queuing them to router
+
+
+
+
+
+
+
+
+
+
+
+ Reactive implementation of for polling updates from Telegram.
+ Provides custom update receiving logic with error handling and configuration options.
+
+ The Telegram bot client for making API requests.
+
+
+
+ Reactive implementation of for polling updates from Telegram.
+ Provides custom update receiving logic with error handling and configuration options.
+
+ The Telegram bot client for making API requests.
+
+
+
+
+
+
+ Client class for the Telegrator library with Wider functionality, provided by WTelegramBotClient.
+ Extends TelegramBotClient with reactive capabilities for handling updates.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Initializes new instance of
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Provides extensions memebrs for for easy access to Wider bot functions and update
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Casts Update to
+
+
+
+
+ Casts Update to
+
+
+
+
+ Casts Update to
+
+
+
+
+ Casts Update to
+
+
+
+
+ Casts Update to
+
+
Provides extension methods for to configure Telegrator.
@@ -30,6 +140,22 @@
Provides method to configure Telegram Bot WebHost
+
+
+ Adds WTelegramBotClientOptions to services
+
+
+
+
+
+
+
+ Adds WTelegramBotClient
+
+
+
+
+
Provides useful methods to adjust Telegram bot Host
diff --git a/docs/Telegrator.Hosting.xml b/docs/Telegrator.Hosting.xml
index c394b45..f8eff90 100644
--- a/docs/Telegrator.Hosting.xml
+++ b/docs/Telegrator.Hosting.xml
@@ -97,7 +97,7 @@
- Service for receiving updates for Hosted telegram bots
+ Service for receiving updates for Hosted telegram botsand queuing them to router
@@ -106,7 +106,7 @@
- Service for receiving updates for Hosted telegram bots
+ Service for receiving updates for Hosted telegram botsand queuing them to router
@@ -207,6 +207,22 @@
Provides method to configure Telegram Bot Host
+
+
+ Adds TelegramBotClientOptions to services
+
+
+
+
+
+
+
+ Adds ReceiverOptions to services
+
+
+
+
+
Registers service
diff --git a/docs/Telegrator.xml b/docs/Telegrator.xml
index f8b3a28..1e220d9 100644
--- a/docs/Telegrator.xml
+++ b/docs/Telegrator.xml
@@ -5483,6 +5483,14 @@
Gets the update router for handling incoming updates.
+
+
+ Initializes the update router and begins polling for updates asynchronously.
+
+ Optional receiver options for configuring update polling.
+ The cancellation token to stop receiving updates.
+
+
Console logger implementation that writes to System.Console.
@@ -6804,13 +6812,8 @@
Optional HTTP client for making requests.
The cancellation token.
-
-
- Starts receiving updates from Telegram.
- Initializes the update router and begins polling for updates.
-
- Optional receiver options for configuring update polling.
- The cancellation token to stop receiving updates.
+
+
@@ -6871,6 +6874,19 @@
Gets or sets the global cancellation token for all bot operations.
+
+
+ Provides usefull helper methods for TelegratorBot
+
+
+
+
+ Initializes the update router and begins polling for updates synchronously (Blocking calling thread).
+
+
+ Optional receiver options for configuring update polling.
+ The cancellation token to stop receiving updates.
+
Provides usefull helper methods for messages
diff --git a/src/Telegrator.Hosting.Web/Mediation/HostedUpdateWebhooker.cs b/src/Telegrator.Hosting.Web/Mediation/HostedUpdateWebhooker.cs
index 938b445..1f0f63d 100644
--- a/src/Telegrator.Hosting.Web/Mediation/HostedUpdateWebhooker.cs
+++ b/src/Telegrator.Hosting.Web/Mediation/HostedUpdateWebhooker.cs
@@ -13,7 +13,7 @@ using Telegrator.Hosting.Web;
namespace Telegrator.Mediation;
///
-/// Service for receiving updates for Hosted telegram bots via Webhooks
+/// Service for receiving updates for Hosted telegram bots via Webhooks and queuing them to router
///
public class HostedUpdateWebhooker : IHostedService
{
diff --git a/src/Telegrator.Hosting.Web/TypesExtensions.cs b/src/Telegrator.Hosting.Web/TypesExtensions.cs
index 11dace3..963a09d 100644
--- a/src/Telegrator.Hosting.Web/TypesExtensions.cs
+++ b/src/Telegrator.Hosting.Web/TypesExtensions.cs
@@ -99,8 +99,15 @@ public static class WebHostBuilderExtensions
///
public static class WebServicesCollectionExtensions
{
+ ///
+ /// Adds WebhookerOptions to services
+ ///
+ ///
+ ///
+ ///
public static IServiceCollection ConfigureWebhooker(this IServiceCollection services, WebhookerOptions options)
{
+ services.RemoveAll>();
services.AddSingleton(Options.Create(options));
return services;
}
@@ -176,6 +183,9 @@ public static class WebTelegramBotHostExtensions
///
public static IServiceCollection AddTelegramWebhook(this IServiceCollection services)
{
+ services.RemoveAll>();
+ services.RemoveAll();
+
services.AddHttpClient("tgwebhook").RemoveAllLoggers().AddTypedClient(TypedTelegramBotClientFactory);
services.AddHostedService();
return services;
diff --git a/src/Telegrator.Hosting.WideBot/GlobalSuppressions.cs b/src/Telegrator.Hosting.WideBot/GlobalSuppressions.cs
index 3562098..329f6b0 100644
--- a/src/Telegrator.Hosting.WideBot/GlobalSuppressions.cs
+++ b/src/Telegrator.Hosting.WideBot/GlobalSuppressions.cs
@@ -6,3 +6,5 @@
using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Roslynator", "RCS1037")]
+[assembly: SuppressMessage("Style", "IDE0090")]
+[assembly: SuppressMessage("Style", "IDE0270")]
diff --git a/src/Telegrator.Hosting.WideBot/Mediation/HostedWideBotUpdateReceiver.cs b/src/Telegrator.Hosting.WideBot/Mediation/HostedWideBotUpdateReceiver.cs
index b49c9ba..c885dd6 100644
--- a/src/Telegrator.Hosting.WideBot/Mediation/HostedWideBotUpdateReceiver.cs
+++ b/src/Telegrator.Hosting.WideBot/Mediation/HostedWideBotUpdateReceiver.cs
@@ -1,18 +1,22 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
-using System;
-using System.Threading;
-using System.Threading.Tasks;
using Telegram.Bot;
using Telegram.Bot.Polling;
using Telegrator.Core;
namespace Telegrator.Mediation;
-//Hosting.WideBot
+///
+/// Service for receiving updates for Hosted wide telegram bots and queuing them to router
+///
+///
+///
+///
+///
public class HostedWideBotUpdateReceiver(ILogger logger, ITelegramBotClient botClient, IUpdateRouter updateRouter, IOptions? options) : BackgroundService
{
+ ///
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
if (botClient is not WTelegramBotClient wideBotClient)
diff --git a/src/Telegrator.Hosting.WideBot/Mediation/WideUpdateReceiver.cs b/src/Telegrator.Hosting.WideBot/Mediation/WideUpdateReceiver.cs
index 5aafb75..4aa912c 100644
--- a/src/Telegrator.Hosting.WideBot/Mediation/WideUpdateReceiver.cs
+++ b/src/Telegrator.Hosting.WideBot/Mediation/WideUpdateReceiver.cs
@@ -8,12 +8,19 @@ using WUpdate = WTelegram.Types.Update;
namespace Telegrator.Mediation;
+///
+/// Reactive implementation of for polling updates from Telegram.
+/// Provides custom update receiving logic with error handling and configuration options.
+///
+/// The Telegram bot client for making API requests.
+// Optional receiver options for configuring update polling behavior.
public class WideUpdateReceiver(WTelegramBotClient client) : IUpdateReceiver
{
private readonly WTelegramBotClient _client = client;
private IUpdateHandler? _updateHandler = null;
private CancellationToken _cancellation = default;
+ ///
public async Task ReceiveAsync(IUpdateHandler updateHandler, CancellationToken cancellationToken = default)
{
_updateHandler = updateHandler;
diff --git a/src/Telegrator.Hosting.WideBot/TelegratorWideClient.cs b/src/Telegrator.Hosting.WideBot/TelegratorWideClient.cs
index bff5eb2..690f559 100644
--- a/src/Telegrator.Hosting.WideBot/TelegratorWideClient.cs
+++ b/src/Telegrator.Hosting.WideBot/TelegratorWideClient.cs
@@ -13,18 +13,33 @@ using Telegrator.States;
namespace Telegrator;
+///
+/// Client class for the Telegrator library with Wider functionality, provided by WTelegramBotClient.
+/// Extends TelegramBotClient with reactive capabilities for handling updates.
+///
public class TelegratorWClient : WTelegramBotClient, ITelegratorBot, ICollectingProvider
{
private IUpdateRouter? _updateRouter = null;
+ ///
public TelegratorOptions Options { get; }
-
+
+ ///
public IHandlersCollection Handlers { get; }
-
+
+ ///
public ITelegramBotInfo BotInfo { get; }
+ ///
public IUpdateRouter UpdateRouter => _updateRouter ?? throw new InvalidOperationException("Router's not created yet. Invoke `StartReceiving` to initialize this property.");
+ ///
+ /// Initializes new instance of
+ ///
+ ///
+ ///
+ ///
+ ///
public TelegratorWClient(WTelegramBotClientOptions wOptions, TelegratorOptions? telegratorOptions = null, HttpClient? httpClient = null, CancellationToken cancellationToken = default)
: base(wOptions, httpClient, cancellationToken)
{
@@ -33,7 +48,8 @@ public class TelegratorWClient : WTelegramBotClient, ITelegratorBot, ICollecting
BotInfo = new TelegramBotInfo(GetMe(cancellationToken).Result);
}
- public void StartReceiving(CancellationToken cancellationToken = default)
+ ///
+ public void StartReceiving(ReceiverOptions? _, CancellationToken cancellationToken = default)
{
if (Options.GlobalCancellationToken == CancellationToken.None)
Options.GlobalCancellationToken = cancellationToken;
@@ -45,10 +61,27 @@ public class TelegratorWClient : WTelegramBotClient, ITelegratorBot, ICollecting
_updateRouter = new UpdateRouter(handlerProvider, awaitingProvider, stateStorage, Options, BotInfo);
TelegratorLogging.LogInformation($"TelegratorW bot starting up - BotId: {BotInfo.User.Id}, Username: {BotInfo.User.Username}");
- StartReceivingInternal(Options.GlobalCancellationToken);
+ StartReceivingInternal(Options.GlobalCancellationToken)
+ .ConfigureAwait(false).GetAwaiter().GetResult();
}
- private async void StartReceivingInternal(CancellationToken cancellationToken)
+ ///
+ public async Task StartReceivingAsync(ReceiverOptions? receiverOptions = null,CancellationToken cancellationToken = default)
+ {
+ if (Options.GlobalCancellationToken == CancellationToken.None)
+ Options.GlobalCancellationToken = cancellationToken;
+
+ HandlersProvider handlerProvider = new HandlersProvider(Handlers, Options);
+ AwaitingProvider awaitingProvider = new AwaitingProvider(Options);
+ DefaultStateStorage stateStorage = new DefaultStateStorage();
+
+ _updateRouter = new UpdateRouter(handlerProvider, awaitingProvider, stateStorage, Options, BotInfo);
+ TelegratorLogging.LogInformation($"TelegratorW bot starting up - BotId: {BotInfo.User.Id}, Username: {BotInfo.User.Username}");
+
+ await StartReceivingInternal(Options.GlobalCancellationToken);
+ }
+
+ private async Task StartReceivingInternal(CancellationToken cancellationToken)
{
try
{
diff --git a/src/Telegrator.Hosting.WideBot/TypesExtensions.cs b/src/Telegrator.Hosting.WideBot/TypesExtensions.cs
index fa6c003..0b5cabc 100644
--- a/src/Telegrator.Hosting.WideBot/TypesExtensions.cs
+++ b/src/Telegrator.Hosting.WideBot/TypesExtensions.cs
@@ -13,15 +13,21 @@ using Telegrator.Hosting;
using Telegrator.Mediation;
using Telegrator.Providers;
-using TLUpdate = TL.Update;
using WUpdate = WTelegram.Types.Update;
+using TLUpdate = TL.Update;
namespace Telegrator;
+///
+/// Provides extensions memebrs for for easy access to Wider bot functions and update
+///
public static class HandlersExtensions
{
extension(AbstractUpdateHandler handler) where TUpdate : class
{
+ ///
+ /// Casts Update to
+ ///
public WTelegramBotClient WClient
{
get
@@ -35,6 +41,9 @@ public static class HandlersExtensions
}
+ ///
+ /// Casts Update to
+ ///
public WUpdate WideUpdate
{
get
@@ -47,18 +56,27 @@ public static class HandlersExtensions
}
}
+ ///
+ /// Casts Update to
+ ///
public TLUpdate? TLUpdate
{
get => handler.WideUpdate.TLUpdate;
}
}
+ ///
+ /// Casts Update to
+ ///
public static WTelegramBotClient AsWClient(this ITelegramBotClient client)
{
return client as WTelegramBotClient
?? throw new InvalidCastException("Client is not assignable to `WTelegram.Bot.WTelegramBotClient`");
}
+ ///
+ /// Casts Update to
+ ///
public static WUpdate AsWUpdate(this Update update)
{
return update as WUpdate
@@ -149,20 +167,45 @@ public static class WideHostBuilderExtensions
///
public static class WideBotServiceCollectionExtensions
{
+ ///
+ /// Adds WTelegramBotClientOptions to services
+ ///
+ ///
+ ///
+ ///
public static IServiceCollection ConfigureWideTelegram(this IServiceCollection services, WTelegramBotClientOptions options)
{
+ services.RemoveAll>();
services.AddSingleton(Options.Create(options));
return services;
}
- public static IServiceCollection AddMTProtoUpdateReceiver(this IServiceCollection services)
+ ///
+ /// Adds WTelegramBotClient
+ ///
+ ///
+ ///
+ ///
+ public static IServiceCollection AddMTProtoUpdateReceiver(this IServiceCollection services, bool useHttp = false)
{
- services.AddHttpClient("tgmtproto").RemoveAllLoggers().AddTypedClient(TypedTelegramBotClientFactory);
+ services.RemoveAll();
+ services.RemoveAll();
+
+ if (useHttp)
+ {
+ services.AddHttpClient("tgmtproto").RemoveAllLoggers().AddTypedClient(TypedTelegramBotClientFactory);
+ }
+ else
+ {
+ services.AddSingleton(TypedTelegramBotClientFactory);
+ }
+
services.AddSingleton(sp => sp.GetRequiredService());
services.AddHostedService();
return services;
}
+#pragma warning disable CA2254
private static WTelegramBotClient TypedTelegramBotClientFactory(HttpClient httpClient, IServiceProvider provider)
{
ILogger logger = provider.GetRequiredService>();
@@ -171,6 +214,16 @@ public static class WideBotServiceCollectionExtensions
WTelegram.Helpers.Log = (lvl, str) => logger.Log((LogLevel)lvl, str);
return client;
}
+
+ private static WTelegramBotClient TypedTelegramBotClientFactory(IServiceProvider provider)
+ {
+ ILogger logger = provider.GetRequiredService>();
+ WTelegramBotClient client = new WTelegramBotClient(provider.GetRequiredService>().Value);
+
+ WTelegram.Helpers.Log = (lvl, str) => logger.Log((LogLevel)lvl, str);
+ return client;
+ }
+#pragma warning restore CA2254
}
///
diff --git a/src/Telegrator.Hosting.WideBot/WideReceiverOptions.cs b/src/Telegrator.Hosting.WideBot/WideReceiverOptions.cs
deleted file mode 100644
index 224b112..0000000
--- a/src/Telegrator.Hosting.WideBot/WideReceiverOptions.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace Telegrator;
-
-public class WideReceiverOptions
-{
-}
diff --git a/src/Telegrator.Hosting/Mediation/HostedUpdateReceiver.cs b/src/Telegrator.Hosting/Mediation/HostedUpdateReceiver.cs
index 89d8f02..2d2dcef 100644
--- a/src/Telegrator.Hosting/Mediation/HostedUpdateReceiver.cs
+++ b/src/Telegrator.Hosting/Mediation/HostedUpdateReceiver.cs
@@ -8,7 +8,7 @@ using Telegrator.Core;
namespace Telegrator.Mediation;
///
-/// Service for receiving updates for Hosted telegram bots
+/// Service for receiving updates for Hosted telegram botsand queuing them to router
///
///
///
diff --git a/src/Telegrator.Hosting/TypesExtensions.cs b/src/Telegrator.Hosting/TypesExtensions.cs
index 5efcbe1..2e9d001 100644
--- a/src/Telegrator.Hosting/TypesExtensions.cs
+++ b/src/Telegrator.Hosting/TypesExtensions.cs
@@ -129,14 +129,28 @@ public static class HostBuilderExtensions
///
public static class HostServicesCollectionExtensions
{
+ ///
+ /// Adds TelegramBotClientOptions to services
+ ///
+ ///
+ ///
+ ///
public static IServiceCollection ConfigureTelegram(this IServiceCollection services, TelegramBotClientOptions options)
{
+ services.RemoveAll>();
services.AddSingleton(Options.Create(options));
return services;
}
+ ///
+ /// Adds ReceiverOptions to services
+ ///
+ ///
+ ///
+ ///
public static IServiceCollection ConfigureReceiver(this IServiceCollection services, ReceiverOptions options)
{
+ services.RemoveAll>();
services.AddSingleton(Options.Create(options));
return services;
}
@@ -176,6 +190,9 @@ public static class HostServicesCollectionExtensions
///
public static IServiceCollection AddTelegramReceiver(this IServiceCollection services)
{
+ services.RemoveAll();
+ services.RemoveAll();
+
services.AddHttpClient("tgreceiver").RemoveAllLoggers().AddTypedClient(TypedTelegramBotClientFactory);
services.AddHostedService();
return services;
diff --git a/src/Telegrator/GlobalSuppressions.cs b/src/Telegrator/GlobalSuppressions.cs
index cef1ccc..c601b9b 100644
--- a/src/Telegrator/GlobalSuppressions.cs
+++ b/src/Telegrator/GlobalSuppressions.cs
@@ -10,3 +10,4 @@ using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Style", "IDE0057")]
[assembly: SuppressMessage("Style", "IDE0270")]
[assembly: SuppressMessage("Roslynator", "RCS1037")]
+[assembly: SuppressMessage("Roslynator", "RCS1227")]
diff --git a/src/Telegrator/ITelegratorBot.cs b/src/Telegrator/ITelegratorBot.cs
index dcd754f..2abb973 100644
--- a/src/Telegrator/ITelegratorBot.cs
+++ b/src/Telegrator/ITelegratorBot.cs
@@ -1,4 +1,5 @@
-using Telegrator.Core;
+using Telegram.Bot.Polling;
+using Telegrator.Core;
namespace Telegrator;
@@ -12,4 +13,12 @@ public interface ITelegratorBot
/// Gets the update router for handling incoming updates.
///
public IUpdateRouter UpdateRouter { get; }
+
+ ///
+ /// Initializes the update router and begins polling for updates asynchronously.
+ ///
+ /// Optional receiver options for configuring update polling.
+ /// The cancellation token to stop receiving updates.
+ ///
+ Task StartReceivingAsync(ReceiverOptions? receiverOptions = null, CancellationToken cancellationToken = default);
}
diff --git a/src/Telegrator/TelegratorClient.cs b/src/Telegrator/TelegratorClient.cs
index ec16e3f..49fb606 100644
--- a/src/Telegrator/TelegratorClient.cs
+++ b/src/Telegrator/TelegratorClient.cs
@@ -20,13 +20,13 @@ public class TelegratorClient : TelegramBotClient, ITelegratorBot, ICollectingPr
private IUpdateRouter? updateRouter = null;
///
- public TelegratorOptions Options { get; private set; }
+ public TelegratorOptions Options { get; }
///
- public IHandlersCollection Handlers { get; private set; }
+ public IHandlersCollection Handlers { get; }
///
- public ITelegramBotInfo BotInfo { get; private set; }
+ public ITelegramBotInfo BotInfo { get; }
///
public IUpdateRouter UpdateRouter => updateRouter ?? throw new InvalidOperationException("Router's not created yet. Invoke `StartReceiving` to initialize this property.");
@@ -63,26 +63,19 @@ public class TelegratorClient : TelegramBotClient, ITelegratorBot, ICollectingPr
BotInfo = new TelegramBotInfo(this.GetMe(cancellationToken).Result);
}
- ///
- /// Starts receiving updates from Telegram.
- /// Initializes the update router and begins polling for updates.
- ///
- /// Optional receiver options for configuring update polling.
- /// The cancellation token to stop receiving updates.
- public void StartReceiving(ReceiverOptions? receiverOptions = null, CancellationToken globalCancellationToken = default)
+ ///
+ public async Task StartReceivingAsync(ReceiverOptions? receiverOptions = null, CancellationToken cancellationToken = default)
{
if (Options.GlobalCancellationToken == CancellationToken.None)
- Options.GlobalCancellationToken = globalCancellationToken;
+ Options.GlobalCancellationToken = cancellationToken;
HandlersProvider handlerProvider = new HandlersProvider(Handlers, Options);
AwaitingProvider awaitingProvider = new AwaitingProvider(Options);
DefaultStateStorage stateStorage = new DefaultStateStorage();
- updateRouter = new UpdateRouter(handlerProvider, awaitingProvider, stateStorage, Options, BotInfo);
-
- // Log startup
TelegratorLogging.LogInformation($"Telegrator bot starting up - BotId: {BotInfo.User.Id}, Username: {BotInfo.User.Username}, MaxParallelHandlers: {Options.MaximumParallelWorkingHandlers ?? -1}");
- StartReceivingInternal(receiverOptions, globalCancellationToken);
+ updateRouter = new UpdateRouter(handlerProvider, awaitingProvider, stateStorage, Options, BotInfo);
+ await StartReceivingInternal(receiverOptions, Options.GlobalCancellationToken);
}
///
@@ -91,7 +84,7 @@ public class TelegratorClient : TelegramBotClient, ITelegratorBot, ICollectingPr
///
/// Optional receiver options for configuring update polling.
/// The cancellation token to stop receiving updates.
- private async void StartReceivingInternal(ReceiverOptions? receiverOptions, CancellationToken cancellationToken)
+ private async Task StartReceivingInternal(ReceiverOptions? receiverOptions, CancellationToken cancellationToken)
{
try
{
diff --git a/src/Telegrator/TypesExtensions.cs b/src/Telegrator/TypesExtensions.cs
index 93db750..81257f5 100644
--- a/src/Telegrator/TypesExtensions.cs
+++ b/src/Telegrator/TypesExtensions.cs
@@ -1,4 +1,5 @@
using System.Reflection;
+using Telegram.Bot.Polling;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
using Telegram.Bot.Types.Payments;
@@ -13,6 +14,24 @@ using Telegrator.States;
namespace Telegrator;
+///
+/// Provides usefull helper methods for TelegratorBot
+///
+public static class TelegratorBotExtensions
+{
+ ///
+ /// Initializes the update router and begins polling for updates synchronously (Blocking calling thread).
+ ///
+ ///
+ /// Optional receiver options for configuring update polling.
+ /// The cancellation token to stop receiving updates.
+ public static void StartReceiving(this ITelegratorBot bot, ReceiverOptions? receiverOptions = null, CancellationToken cancellationToken = default)
+ {
+ bot.StartReceivingAsync(receiverOptions, cancellationToken)
+ .ConfigureAwait(false).GetAwaiter().GetResult();
+ }
+}
+
///
/// Provides usefull helper methods for messages
///
diff --git a/tests/Telegrator.Tests/GlobalSuppressions.cs b/tests/Telegrator.Tests/GlobalSuppressions.cs
new file mode 100644
index 0000000..3562098
--- /dev/null
+++ b/tests/Telegrator.Tests/GlobalSuppressions.cs
@@ -0,0 +1,8 @@
+// This file is used by Code Analysis to maintain SuppressMessage
+// attributes that are applied to this project.
+// Project-level suppressions either have no target or are given
+// a specific target and scoped to a namespace, type, member, etc.
+
+using System.Diagnostics.CodeAnalysis;
+
+[assembly: SuppressMessage("Roslynator", "RCS1037")]
diff --git a/tests/Telegrator.Tests/Program.cs b/tests/Telegrator.Tests/Program.cs
index f8870ed..e90b378 100644
--- a/tests/Telegrator.Tests/Program.cs
+++ b/tests/Telegrator.Tests/Program.cs
@@ -32,7 +32,7 @@ internal static class Program
ApplicationName = "WBot example",
});
- using DbConnection connection = new SqliteConnection(@"Data Source=wtgb.db");
+ using DbConnection connection = new SqliteConnection("Data Source=wtgb.db");
builder.Services.ConfigureWideTelegram(
new WTelegramBotClientOptions(token: "BOT_TOKEN", apiId: 123, apiHash: "API_HASH", dbConnection: connection));
diff --git a/tests/Telegrator.Tests/TestUpdateHandler.cs b/tests/Telegrator.Tests/TestUpdateHandler.cs
index e897e9d..2ffda50 100644
--- a/tests/Telegrator.Tests/TestUpdateHandler.cs
+++ b/tests/Telegrator.Tests/TestUpdateHandler.cs
@@ -1,23 +1,21 @@
using Telegram.Bot.Types;
using Telegrator.Handlers;
-namespace Telegrator.Tests
-{
- ///
- /// Вспомогательный класс для тестирования абстрактного UpdateHandlerBase.
- ///
- /// ПРИНЦИП: Создание тестовых двойников для абстрактных классов
- ///
- [MessageHandler]
- internal class TestUpdateHandler : MessageHandler
- {
- public bool WasExecuted { get; private set; }
+namespace Telegrator.Tests;
- public override Task Execute(IHandlerContainer container, CancellationToken cancellationToken)
- {
- cancellationToken.ThrowIfCancellationRequested();
- WasExecuted = true;
- return Task.FromResult(Result.Ok());
- }
+///
+/// Вспомогательный класс для тестирования абстрактного UpdateHandlerBase.
+/// ПРИНЦИП: Создание тестовых двойников для абстрактных классов
+///
+[MessageHandler]
+internal class TestUpdateHandler : MessageHandler
+{
+ public bool WasExecuted { get; private set; }
+
+ public override Task Execute(IHandlerContainer container, CancellationToken cancellationToken)
+ {
+ cancellationToken.ThrowIfCancellationRequested();
+ WasExecuted = true;
+ return Task.FromResult(Result.Ok());
}
}