diff --git a/docs/Telegrator.Hosting.Web.xml b/docs/Telegrator.Hosting.Web.xml
index 04ff5db..fbdb2ee 100644
--- a/docs/Telegrator.Hosting.Web.xml
+++ b/docs/Telegrator.Hosting.Web.xml
@@ -69,33 +69,33 @@
-
+
+
+ Provides extension methods for to configure Telegrator.
+
+
+
+
+ Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
+
+
+
+
+ Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
+
+
+
+
+ Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
+
+
+
Contains extensions for
Provides method to configure Telegram Bot WebHost
-
-
- Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
-
-
-
-
- Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
-
-
-
-
- Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
-
-
-
-
- Provides useful methods to adjust Telegram bot Host
-
-
-
+
Searchs for hosted service inside hosts services
@@ -103,13 +103,18 @@
-
+
+
+ Provides useful methods to adjust Telegram bot Host
+
+
+
Replaces the initialization logic from TelegramBotWebHost constructor.
Initializes the bot and logs handlers on application startup.
-
+
Allows to remap receiving webhook endpoint and map new route to webhost.
@@ -118,7 +123,7 @@
-
+
Registers service with to receive updates using webhook
diff --git a/docs/Telegrator.Hosting.WideBot.xml b/docs/Telegrator.Hosting.WideBot.xml
new file mode 100644
index 0000000..3df7372
--- /dev/null
+++ b/docs/Telegrator.Hosting.WideBot.xml
@@ -0,0 +1,45 @@
+
+
+
+ Telegrator.Hosting.WideBot
+
+
+
+
+ Provides extension methods for to configure Telegrator.
+
+
+
+
+ Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
+
+
+
+
+ Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
+
+
+
+
+ Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
+
+
+
+
+ Contains extensions for
+ Provides method to configure Telegram Bot WebHost
+
+
+
+
+ Provides useful methods to adjust Telegram bot Host
+
+
+
+
+ Replaces the initialization logic from TelegramBotWebHost constructor.
+ Initializes the bot and logs handlers on application startup.
+
+
+
+
diff --git a/docs/Telegrator.Hosting.xml b/docs/Telegrator.Hosting.xml
index 05914c8..c394b45 100644
--- a/docs/Telegrator.Hosting.xml
+++ b/docs/Telegrator.Hosting.xml
@@ -201,13 +201,13 @@
Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
-
+
Contains extensions for
Provides method to configure Telegram Bot Host
-
+
Registers service
@@ -215,21 +215,21 @@
-
+
Registers default services
-
+
Registers service with to receive updates using long polling
-
+
factory method
diff --git a/src/Telegrator.Hosting.Web/Telegrator.Hosting.Web.csproj b/src/Telegrator.Hosting.Web/Telegrator.Hosting.Web.csproj
index 1fba795..cfdf037 100644
--- a/src/Telegrator.Hosting.Web/Telegrator.Hosting.Web.csproj
+++ b/src/Telegrator.Hosting.Web/Telegrator.Hosting.Web.csproj
@@ -15,7 +15,7 @@
True
Telegrator.Hosting.Web
- 1.16.9
+ 1.17.0
Rikitav Tim4ik
Rikitav Tim4ik
https://github.com/Rikitav/Telegrator
@@ -40,4 +40,5 @@
+
diff --git a/src/Telegrator.Hosting.Web/TypesExtensions.cs b/src/Telegrator.Hosting.Web/TypesExtensions.cs
index 4a038d3..11dace3 100644
--- a/src/Telegrator.Hosting.Web/TypesExtensions.cs
+++ b/src/Telegrator.Hosting.Web/TypesExtensions.cs
@@ -1,5 +1,4 @@
-using Microsoft.AspNetCore.Builder;
-using Microsoft.AspNetCore.Routing;
+using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
@@ -8,7 +7,6 @@ using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System.Diagnostics.CodeAnalysis;
using Telegram.Bot;
-using Telegram.Bot.Polling;
using Telegrator.Core;
using Telegrator.Hosting;
using Telegrator.Hosting.Web;
@@ -18,17 +16,10 @@ using Telegrator.Providers;
namespace Telegrator;
///
-/// Contains extensions for
-/// Provides method to configure Telegram Bot WebHost
+/// Provides extension methods for to configure Telegrator.
///
-public static class ServicesCollectionExtensions
+public static class WebHostBuilderExtensions
{
- public static IServiceCollection ConfigureWebhooker(this IServiceCollection services, WebhookerOptions options)
- {
- services.AddSingleton(Options.Create(options));
- return services;
- }
-
///
/// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
///
@@ -103,10 +94,17 @@ public static class ServicesCollectionExtensions
}
///
-/// Provides useful methods to adjust Telegram bot Host
+/// Contains extensions for
+/// Provides method to configure Telegram Bot WebHost
///
-public static class TelegramBotHostExtensions
+public static class WebServicesCollectionExtensions
{
+ public static IServiceCollection ConfigureWebhooker(this IServiceCollection services, WebhookerOptions options)
+ {
+ services.AddSingleton(Options.Create(options));
+ return services;
+ }
+
///
/// Searchs for hosted service inside hosts services
///
@@ -118,7 +116,13 @@ public static class TelegramBotHostExtensions
webhooker = services.GetServices().FirstOrDefault(s => s is HostedUpdateWebhooker) as HostedUpdateWebhooker;
return webhooker != null;
}
+}
+///
+/// Provides useful methods to adjust Telegram bot Host
+///
+public static class WebTelegramBotHostExtensions
+{
///
/// Replaces the initialization logic from TelegramBotWebHost constructor.
/// Initializes the bot and logs handlers on application startup.
diff --git a/src/Telegrator.Hosting.WideBot/README.md b/src/Telegrator.Hosting.WideBot/README.md
new file mode 100644
index 0000000..e02abfc
--- /dev/null
+++ b/src/Telegrator.Hosting.WideBot/README.md
@@ -0,0 +1 @@
+
diff --git a/src/Telegrator.Hosting.WideBot/Telegrator.Hosting.WideBot.csproj b/src/Telegrator.Hosting.WideBot/Telegrator.Hosting.WideBot.csproj
index f5a87c3..2e2f70d 100644
--- a/src/Telegrator.Hosting.WideBot/Telegrator.Hosting.WideBot.csproj
+++ b/src/Telegrator.Hosting.WideBot/Telegrator.Hosting.WideBot.csproj
@@ -2,9 +2,28 @@
net10.0
+ enable
enable
- Telegrator
latest
+ Telegrator
+ ..\..\bin
+ ..\..\docs\$(AssemblyName).xml
+
+ True
+ True
+ True
+ True
+
+ Telegrator.Hosting.WideBot
+ 1.17.0
+ Rikitav Tim4ik
+ Rikitav Tim4ik
+ https://github.com/Rikitav/Telegrator
+ telegram;bot;mediator;attributes;aspect;hosting;host;framework;easy;simple;handlers;wtelegrambot;userbot
+
+ telegrator_nuget.png
+ README.md
+ LICENSE
@@ -15,4 +34,10 @@
+
+
+
+
+
+
diff --git a/src/Telegrator.Hosting.WideBot/TelegratorWideClient.cs b/src/Telegrator.Hosting.WideBot/TelegratorWideClient.cs
index 4518d30..bff5eb2 100644
--- a/src/Telegrator.Hosting.WideBot/TelegratorWideClient.cs
+++ b/src/Telegrator.Hosting.WideBot/TelegratorWideClient.cs
@@ -1,6 +1,5 @@
-// Maybe later...
-
-/*
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Logging.Abstractions;
using System;
using System.Net.Http;
using System.Threading;
@@ -55,8 +54,8 @@ public class TelegratorWClient : WTelegramBotClient, ITelegratorBot, ICollecting
{
try
{
- await new HostedWideBotUpdateReceiver(this)
- .ReceiveAsync(UpdateRouter, cancellationToken)
+ await new HostedWideBotUpdateReceiver(NullLoggerFactory.Instance.CreateLogger(), this, UpdateRouter, null)
+ .StartAsync(cancellationToken)
.ConfigureAwait(false);
}
catch (Exception exception)
@@ -72,5 +71,4 @@ public class TelegratorWClient : WTelegramBotClient, ITelegratorBot, ICollecting
TelegratorLogging.LogInformation("Telegrator bot stopped (cancelled)");
}
}
-}
-*/
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/src/Telegrator.Hosting.WideBot/TypesExtensions.cs b/src/Telegrator.Hosting.WideBot/TypesExtensions.cs
index 0dd9759..4cb188e 100644
--- a/src/Telegrator.Hosting.WideBot/TypesExtensions.cs
+++ b/src/Telegrator.Hosting.WideBot/TypesExtensions.cs
@@ -27,13 +27,26 @@ public static class HandlersExtensions
{
extension(AbstractUpdateHandler handler) where TUpdate : class
{
- public WUpdate WUpdate
+ public WTelegramBotClient WClient
{
get
{
- object? update = typeof(AbstractUpdateHandler).GetField("HandlingUpdate")?.GetValue(handler);
+ object? client = handler.GetType().GetField("Client")?.GetValue(handler);
+ if (client is not WTelegramBotClient wideClient)
+ throw new InvalidCastException("Client is not assignable to `WTelegram.Bot.WTelegramBotClient`");
+
+ return wideClient;
+ }
+
+ }
+
+ public WUpdate WideUpdate
+ {
+ get
+ {
+ object? update = handler.GetType().GetField("HandlingUpdate")?.GetValue(handler);
if (update is not WUpdate wUpdate)
- throw new InvalidCastException();
+ throw new InvalidCastException("Update is not assignable to `WTelegram.Types.Update`");
return wUpdate;
}
@@ -41,7 +54,7 @@ public static class HandlersExtensions
public TLUpdate? TLUpdate
{
- get => handler.WUpdate.TLUpdate;
+ get => handler.WideUpdate.TLUpdate;
}
}
@@ -55,14 +68,8 @@ public static class HandlersExtensions
///
/// Provides extension methods for to configure Telegrator.
///
-public static class ServiceCollectionExtensions
+public static class WideHostBuilderExtensions
{
- public static IServiceCollection ConfigureWideTelegram(this IServiceCollection services, WTelegramBotClientOptions options)
- {
- services.AddSingleton(Options.Create(options));
- return services;
- }
-
///
/// Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
///
@@ -133,6 +140,19 @@ public static class ServiceCollectionExtensions
services.AddTelegramBotHostDefaults();
services.AddMTProtoUpdateReceiver();
}
+}
+
+///
+/// Contains extensions for
+/// Provides method to configure Telegram Bot WebHost
+///
+public static class WideBotServiceCollectionExtensions
+{
+ public static IServiceCollection ConfigureWideTelegram(this IServiceCollection services, WTelegramBotClientOptions options)
+ {
+ services.AddSingleton(Options.Create(options));
+ return services;
+ }
public static IServiceCollection AddMTProtoUpdateReceiver(this IServiceCollection services)
{
@@ -149,8 +169,12 @@ public static class ServiceCollectionExtensions
///
/// Provides useful methods to adjust Telegram bot Host
///
-public static class TelegramBotHostExtensions
+public static class WideTelegramBotHostExtensions
{
+ ///
+ /// Replaces the initialization logic from TelegramBotWebHost constructor.
+ /// Initializes the bot and logs handlers on application startup.
+ ///
public static IHost UseWideTelegrator(this IHost botHost)
{
if (!botHost.Services.TryFindWTelegramBotClient())
diff --git a/src/Telegrator.Hosting/Logging/MicrosoftLoggingAdapter.cs b/src/Telegrator.Hosting/Logging/MicrosoftLoggingAdapter.cs
index d0292ab..f6f36f5 100644
--- a/src/Telegrator.Hosting/Logging/MicrosoftLoggingAdapter.cs
+++ b/src/Telegrator.Hosting/Logging/MicrosoftLoggingAdapter.cs
@@ -32,11 +32,13 @@ public class MicrosoftLoggingAdapter : ITelegratorLogger
if (exception != null)
{
- _logger.Log(msLogLevel, default, message, exception, (str, exc) => string.Format("{0} : {1}", str, exc));
+ _logger.Log(msLogLevel, default, message, exception,
+ (str, exc) => string.Format("{0} : {1}", str, exc));
}
else
{
- _logger.Log(msLogLevel, default, message, null, (str, _) => str);
+ _logger.Log(msLogLevel, default, message, null,
+ (str, _) => str);
}
}
}
diff --git a/src/Telegrator.Hosting/Telegrator.Hosting.csproj b/src/Telegrator.Hosting/Telegrator.Hosting.csproj
index 3ae138e..e73f909 100644
--- a/src/Telegrator.Hosting/Telegrator.Hosting.csproj
+++ b/src/Telegrator.Hosting/Telegrator.Hosting.csproj
@@ -15,7 +15,7 @@
True
Telegrator.Hosting
- 1.16.9
+ 1.17.0
Rikitav Tim4ik
Rikitav Tim4ik
https://github.com/Rikitav/Telegrator
diff --git a/src/Telegrator.Hosting/TypesExtensions.cs b/src/Telegrator.Hosting/TypesExtensions.cs
index c998be2..5efcbe1 100644
--- a/src/Telegrator.Hosting/TypesExtensions.cs
+++ b/src/Telegrator.Hosting/TypesExtensions.cs
@@ -127,7 +127,7 @@ public static class HostBuilderExtensions
/// Contains extensions for
/// Provides method to configure Telegram Bot Host
///
-public static class ServicesCollectionExtensions
+public static class HostServicesCollectionExtensions
{
public static IServiceCollection ConfigureTelegram(this IServiceCollection services, TelegramBotClientOptions options)
{
diff --git a/src/Telegrator/Telegrator.csproj b/src/Telegrator/Telegrator.csproj
index f4c0664..4d23723 100644
--- a/src/Telegrator/Telegrator.csproj
+++ b/src/Telegrator/Telegrator.csproj
@@ -14,7 +14,7 @@
True
Telegrator : Telegram.Bot mediator framework
- 1.16.9
+ 1.17.0
Rikitav Tim4ik
Rikitav Tim4ik
https://github.com/Rikitav/Telegrator
@@ -23,7 +23,6 @@
telegrator_nuget.png
README.md
LICENSE
- b78bc62d-e49f-4ef0-b2de-ff4ceb3971af
diff --git a/src/Telegrator.Hosting.Web/Program.cs b/tests/Telegrator.Tests/Program.cs
similarity index 59%
rename from src/Telegrator.Hosting.Web/Program.cs
rename to tests/Telegrator.Tests/Program.cs
index a2cfcec..be28125 100644
--- a/src/Telegrator.Hosting.Web/Program.cs
+++ b/tests/Telegrator.Tests/Program.cs
@@ -1,8 +1,7 @@
using Microsoft.AspNetCore.Builder;
-using Microsoft.Extensions.Configuration;
+using Microsoft.Data.Sqlite;
using Microsoft.Extensions.Hosting;
-using Telegrator.Hosting;
-using Telegrator.Hosting.Web;
+using System.Data.Common;
namespace Telegrator;
@@ -22,8 +21,6 @@ internal static class Program
builder.Build()
.UseTelegratorWeb(dontMap: true)
.RemapWebhook("https://amazing-butt-sex.cloudpub.ru/")
- .AddLoggingAdapter()
- .SetBotCommands()
.Run();
}
@@ -40,8 +37,25 @@ internal static class Program
builder.Build()
.UseTelegrator()
- .AddLoggingAdapter()
- .SetBotCommands()
+ .Run();
+ }
+
+ public static void WideBotApplicationBuilder_Example(string[] args)
+ {
+ HostApplicationBuilder builder = Host.CreateApplicationBuilder(new HostApplicationBuilderSettings()
+ {
+ Args = args,
+ ApplicationName = "WBot example",
+ });
+
+ using DbConnection connection = new SqliteConnection(@"Data Source=wtgb.db");
+ builder.Services.ConfigureWideTelegram(new Telegram.Bot.WTelegramBotClientOptions(token: "BOT_TOKEN", apiId: 123, apiHash: "API_HASH", dbConnection: connection));
+
+ builder.AddWideTelegrator(action: builder => builder.Handlers
+ .CollectHandlersAssemblyWide());
+
+ builder.Build()
+ .UseWideTelegrator()
.Run();
}
}
diff --git a/tests/Telegrator.Tests/Telegrator.Tests.csproj b/tests/Telegrator.Tests/Telegrator.Tests.csproj
index e86bfe4..804f3ab 100644
--- a/tests/Telegrator.Tests/Telegrator.Tests.csproj
+++ b/tests/Telegrator.Tests/Telegrator.Tests.csproj
@@ -9,6 +9,7 @@
+
@@ -18,6 +19,10 @@
+
+
+
+