* Added WideBot csproj data

* Added TelegratorWideClient
* Added WClient extension property for handlers
* Code cleanup
This commit is contained in:
gutii
2026-04-27 16:28:20 +04:00
parent aba9cf4037
commit 0e0a280308
15 changed files with 201 additions and 78 deletions
+30 -25
View File
@@ -69,33 +69,33 @@
</summary> </summary>
<param name="routeBuilder"></param> <param name="routeBuilder"></param>
</member> </member>
<member name="T:Telegrator.ServicesCollectionExtensions"> <member name="T:Telegrator.WebHostBuilderExtensions">
<summary>
Provides extension methods for <see cref="T:Microsoft.Extensions.Hosting.IHostApplicationBuilder"/> to configure Telegrator.
</summary>
</member>
<member name="M:Telegrator.WebHostBuilderExtensions.AddTelegratorWeb(Microsoft.Extensions.Hosting.IHostApplicationBuilder,Telegrator.TelegratorOptions,Telegrator.Core.IHandlersCollection)">
<summary>
Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
</summary>
</member>
<member name="M:Telegrator.WebHostBuilderExtensions.AddTelegratorWeb(Microsoft.Extensions.Hosting.IHostApplicationBuilder,Telegrator.TelegratorOptions,Telegrator.Core.IHandlersCollection,System.Action{Telegrator.Hosting.ITelegramBotHostBuilder})">
<summary>
Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
</summary>
</member>
<member name="M:Telegrator.WebHostBuilderExtensions.AddTelegratorWebInternal(Microsoft.Extensions.DependencyInjection.IServiceCollection,Microsoft.Extensions.Configuration.IConfiguration,System.Collections.Generic.IDictionary{System.Object,System.Object},Telegrator.Core.IHandlersCollection@,Telegrator.TelegratorOptions)">
<summary>
Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
</summary>
</member>
<member name="T:Telegrator.WebServicesCollectionExtensions">
<summary> <summary>
Contains extensions for <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection"/> Contains extensions for <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection"/>
Provides method to configure Telegram Bot WebHost Provides method to configure Telegram Bot WebHost
</summary> </summary>
</member> </member>
<member name="M:Telegrator.ServicesCollectionExtensions.AddTelegratorWeb(Microsoft.Extensions.Hosting.IHostApplicationBuilder,Telegrator.TelegratorOptions,Telegrator.Core.IHandlersCollection)"> <member name="M:Telegrator.WebServicesCollectionExtensions.TryFindWebhooker(System.IServiceProvider,Telegrator.Mediation.HostedUpdateWebhooker@)">
<summary>
Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
</summary>
</member>
<member name="M:Telegrator.ServicesCollectionExtensions.AddTelegratorWeb(Microsoft.Extensions.Hosting.IHostApplicationBuilder,Telegrator.TelegratorOptions,Telegrator.Core.IHandlersCollection,System.Action{Telegrator.Hosting.ITelegramBotHostBuilder})">
<summary>
Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
</summary>
</member>
<member name="M:Telegrator.ServicesCollectionExtensions.AddTelegratorWebInternal(Microsoft.Extensions.DependencyInjection.IServiceCollection,Microsoft.Extensions.Configuration.IConfiguration,System.Collections.Generic.IDictionary{System.Object,System.Object},Telegrator.Core.IHandlersCollection@,Telegrator.TelegratorOptions)">
<summary>
Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
</summary>
</member>
<member name="T:Telegrator.TelegramBotHostExtensions">
<summary>
Provides useful methods to adjust Telegram bot Host
</summary>
</member>
<member name="M:Telegrator.TelegramBotHostExtensions.TryFindWebhooker(System.IServiceProvider,Telegrator.Mediation.HostedUpdateWebhooker@)">
<summary> <summary>
Searchs for <see cref="T:Telegrator.Mediation.HostedUpdateWebhooker"/> hosted service inside hosts services Searchs for <see cref="T:Telegrator.Mediation.HostedUpdateWebhooker"/> hosted service inside hosts services
</summary> </summary>
@@ -103,13 +103,18 @@
<param name="webhooker"></param> <param name="webhooker"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:Telegrator.TelegramBotHostExtensions.UseTelegratorWeb``1(``0,System.Boolean)"> <member name="T:Telegrator.WebTelegramBotHostExtensions">
<summary>
Provides useful methods to adjust Telegram bot Host
</summary>
</member>
<member name="M:Telegrator.WebTelegramBotHostExtensions.UseTelegratorWeb``1(``0,System.Boolean)">
<summary> <summary>
Replaces the initialization logic from TelegramBotWebHost constructor. Replaces the initialization logic from TelegramBotWebHost constructor.
Initializes the bot and logs handlers on application startup. Initializes the bot and logs handlers on application startup.
</summary> </summary>
</member> </member>
<member name="M:Telegrator.TelegramBotHostExtensions.RemapWebhook``1(``0,System.String)"> <member name="M:Telegrator.WebTelegramBotHostExtensions.RemapWebhook``1(``0,System.String)">
<summary> <summary>
Allows to remap receiving webhook endpoint and map new route to webhost. Allows to remap receiving webhook endpoint and map new route to webhost.
</summary> </summary>
@@ -118,7 +123,7 @@
<returns></returns> <returns></returns>
<exception cref="T:System.ArgumentException"></exception> <exception cref="T:System.ArgumentException"></exception>
</member> </member>
<member name="M:Telegrator.TelegramBotHostExtensions.AddTelegramWebhook(Microsoft.Extensions.DependencyInjection.IServiceCollection)"> <member name="M:Telegrator.WebTelegramBotHostExtensions.AddTelegramWebhook(Microsoft.Extensions.DependencyInjection.IServiceCollection)">
<summary> <summary>
Registers <see cref="T:Telegram.Bot.ITelegramBotClient"/> service with <see cref="T:Telegrator.Mediation.HostedUpdateWebhooker"/> to receive updates using webhook Registers <see cref="T:Telegram.Bot.ITelegramBotClient"/> service with <see cref="T:Telegrator.Mediation.HostedUpdateWebhooker"/> to receive updates using webhook
</summary> </summary>
+45
View File
@@ -0,0 +1,45 @@
<?xml version="1.0"?>
<doc>
<assembly>
<name>Telegrator.Hosting.WideBot</name>
</assembly>
<members>
<member name="T:Telegrator.WideHostBuilderExtensions">
<summary>
Provides extension methods for <see cref="T:Microsoft.Extensions.Hosting.IHostApplicationBuilder"/> to configure Telegrator.
</summary>
</member>
<member name="M:Telegrator.WideHostBuilderExtensions.AddWideTelegrator(Microsoft.Extensions.Hosting.IHostApplicationBuilder,Telegrator.TelegratorOptions,Telegrator.Core.IHandlersCollection,System.Action{Telegrator.Hosting.ITelegramBotHostBuilder})">
<summary>
Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
</summary>
</member>
<member name="M:Telegrator.WideHostBuilderExtensions.AddWideTelegrator(Microsoft.Extensions.Hosting.IHostApplicationBuilder,Telegrator.TelegratorOptions,Telegrator.Core.IHandlersCollection)">
<summary>
Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
</summary>
</member>
<member name="M:Telegrator.WideHostBuilderExtensions.AddTelegratorInternal(Microsoft.Extensions.DependencyInjection.IServiceCollection,Microsoft.Extensions.Configuration.IConfiguration,System.Collections.Generic.IDictionary{System.Object,System.Object},Telegrator.Core.IHandlersCollection@,Telegrator.TelegratorOptions)">
<summary>
Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
</summary>
</member>
<member name="T:Telegrator.WideBotServiceCollectionExtensions">
<summary>
Contains extensions for <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection"/>
Provides method to configure Telegram Bot WebHost
</summary>
</member>
<member name="T:Telegrator.WideTelegramBotHostExtensions">
<summary>
Provides useful methods to adjust Telegram bot Host
</summary>
</member>
<member name="M:Telegrator.WideTelegramBotHostExtensions.UseWideTelegrator(Microsoft.Extensions.Hosting.IHost)">
<summary>
Replaces the initialization logic from TelegramBotWebHost constructor.
Initializes the bot and logs handlers on application startup.
</summary>
</member>
</members>
</doc>
+5 -5
View File
@@ -201,13 +201,13 @@
Replaces TelegramBotHostBuilder. Configures DI, options, and handlers. Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
</summary> </summary>
</member> </member>
<member name="T:Telegrator.ServicesCollectionExtensions"> <member name="T:Telegrator.HostServicesCollectionExtensions">
<summary> <summary>
Contains extensions for <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection"/> Contains extensions for <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection"/>
Provides method to configure Telegram Bot Host Provides method to configure Telegram Bot Host
</summary> </summary>
</member> </member>
<member name="M:Telegrator.ServicesCollectionExtensions.AddStateStorage``1(Microsoft.Extensions.DependencyInjection.IServiceCollection)"> <member name="M:Telegrator.HostServicesCollectionExtensions.AddStateStorage``1(Microsoft.Extensions.DependencyInjection.IServiceCollection)">
<summary> <summary>
Registers <see cref="T:Telegrator.Core.States.IStateStorage"/> service Registers <see cref="T:Telegrator.Core.States.IStateStorage"/> service
</summary> </summary>
@@ -215,21 +215,21 @@
<param name="services"></param> <param name="services"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:Telegrator.ServicesCollectionExtensions.AddTelegramBotHostDefaults(Microsoft.Extensions.DependencyInjection.IServiceCollection)"> <member name="M:Telegrator.HostServicesCollectionExtensions.AddTelegramBotHostDefaults(Microsoft.Extensions.DependencyInjection.IServiceCollection)">
<summary> <summary>
Registers <see cref="N:Telegrator"/> default services Registers <see cref="N:Telegrator"/> default services
</summary> </summary>
<param name="services"></param> <param name="services"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:Telegrator.ServicesCollectionExtensions.AddTelegramReceiver(Microsoft.Extensions.DependencyInjection.IServiceCollection)"> <member name="M:Telegrator.HostServicesCollectionExtensions.AddTelegramReceiver(Microsoft.Extensions.DependencyInjection.IServiceCollection)">
<summary> <summary>
Registers <see cref="T:Telegram.Bot.ITelegramBotClient"/> service with <see cref="T:Telegrator.Mediation.HostedUpdateReceiver"/> to receive updates using long polling Registers <see cref="T:Telegram.Bot.ITelegramBotClient"/> service with <see cref="T:Telegrator.Mediation.HostedUpdateReceiver"/> to receive updates using long polling
</summary> </summary>
<param name="services"></param> <param name="services"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:Telegrator.ServicesCollectionExtensions.TypedTelegramBotClientFactory(System.Net.Http.HttpClient,System.IServiceProvider)"> <member name="M:Telegrator.HostServicesCollectionExtensions.TypedTelegramBotClientFactory(System.Net.Http.HttpClient,System.IServiceProvider)">
<summary> <summary>
<see cref="T:Telegram.Bot.ITelegramBotClient"/> factory method <see cref="T:Telegram.Bot.ITelegramBotClient"/> factory method
</summary> </summary>
@@ -15,7 +15,7 @@
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild> <EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
<Title>Telegrator.Hosting.Web</Title> <Title>Telegrator.Hosting.Web</Title>
<Version>1.16.9</Version> <Version>1.17.0</Version>
<Authors>Rikitav Tim4ik</Authors> <Authors>Rikitav Tim4ik</Authors>
<Company>Rikitav Tim4ik</Company> <Company>Rikitav Tim4ik</Company>
<RepositoryUrl>https://github.com/Rikitav/Telegrator</RepositoryUrl> <RepositoryUrl>https://github.com/Rikitav/Telegrator</RepositoryUrl>
@@ -40,4 +40,5 @@
<None Include="..\..\LICENSE" Pack="True" PackagePath="\" /> <None Include="..\..\LICENSE" Pack="True" PackagePath="\" />
<None Include="..\..\resources\telegrator_nuget.png" Pack="True" PackagePath="\" /> <None Include="..\..\resources\telegrator_nuget.png" Pack="True" PackagePath="\" />
</ItemGroup> </ItemGroup>
</Project> </Project>
+18 -14
View File
@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.DependencyInjection.Extensions;
@@ -8,7 +7,6 @@ using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Telegram.Bot; using Telegram.Bot;
using Telegram.Bot.Polling;
using Telegrator.Core; using Telegrator.Core;
using Telegrator.Hosting; using Telegrator.Hosting;
using Telegrator.Hosting.Web; using Telegrator.Hosting.Web;
@@ -18,17 +16,10 @@ using Telegrator.Providers;
namespace Telegrator; namespace Telegrator;
/// <summary> /// <summary>
/// Contains extensions for <see cref="IServiceCollection"/> /// Provides extension methods for <see cref="IHostApplicationBuilder"/> to configure Telegrator.
/// Provides method to configure Telegram Bot WebHost
/// </summary> /// </summary>
public static class ServicesCollectionExtensions public static class WebHostBuilderExtensions
{ {
public static IServiceCollection ConfigureWebhooker(this IServiceCollection services, WebhookerOptions options)
{
services.AddSingleton(Options.Create(options));
return services;
}
/// <summary> /// <summary>
/// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers. /// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
/// </summary> /// </summary>
@@ -103,10 +94,17 @@ public static class ServicesCollectionExtensions
} }
/// <summary> /// <summary>
/// Provides useful methods to adjust Telegram bot Host /// Contains extensions for <see cref="IServiceCollection"/>
/// Provides method to configure Telegram Bot WebHost
/// </summary> /// </summary>
public static class TelegramBotHostExtensions public static class WebServicesCollectionExtensions
{ {
public static IServiceCollection ConfigureWebhooker(this IServiceCollection services, WebhookerOptions options)
{
services.AddSingleton(Options.Create(options));
return services;
}
/// <summary> /// <summary>
/// Searchs for <see cref="HostedUpdateWebhooker"/> hosted service inside hosts services /// Searchs for <see cref="HostedUpdateWebhooker"/> hosted service inside hosts services
/// </summary> /// </summary>
@@ -118,7 +116,13 @@ public static class TelegramBotHostExtensions
webhooker = services.GetServices<IHostedService>().FirstOrDefault(s => s is HostedUpdateWebhooker) as HostedUpdateWebhooker; webhooker = services.GetServices<IHostedService>().FirstOrDefault(s => s is HostedUpdateWebhooker) as HostedUpdateWebhooker;
return webhooker != null; return webhooker != null;
} }
}
/// <summary>
/// Provides useful methods to adjust Telegram bot Host
/// </summary>
public static class WebTelegramBotHostExtensions
{
/// <summary> /// <summary>
/// Replaces the initialization logic from TelegramBotWebHost constructor. /// Replaces the initialization logic from TelegramBotWebHost constructor.
/// Initializes the bot and logs handlers on application startup. /// Initializes the bot and logs handlers on application startup.
+1
View File
@@ -0,0 +1 @@
@@ -2,9 +2,28 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net10.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<RootNamespace>Telegrator</RootNamespace>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<RootNamespace>Telegrator</RootNamespace>
<BaseOutputPath>..\..\bin</BaseOutputPath>
<DocumentationFile>..\..\docs\$(AssemblyName).xml</DocumentationFile>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<EnableNETAnalyzers>True</EnableNETAnalyzers>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
<Title>Telegrator.Hosting.WideBot</Title>
<Version>1.17.0</Version>
<Authors>Rikitav Tim4ik</Authors>
<Company>Rikitav Tim4ik</Company>
<RepositoryUrl>https://github.com/Rikitav/Telegrator</RepositoryUrl>
<PackageTags>telegram;bot;mediator;attributes;aspect;hosting;host;framework;easy;simple;handlers;wtelegrambot;userbot</PackageTags>
<PackageIcon>telegrator_nuget.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@@ -15,4 +34,10 @@
<ProjectReference Include="..\..\src\Telegrator.Hosting\Telegrator.Hosting.csproj" /> <ProjectReference Include="..\..\src\Telegrator.Hosting\Telegrator.Hosting.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include=".\README.md" Pack="True" PackagePath="\" />
<None Include="..\..\LICENSE" Pack="True" PackagePath="\" />
<None Include="..\..\resources\telegrator_nuget.png" Pack="True" PackagePath="\" />
</ItemGroup>
</Project> </Project>
@@ -1,6 +1,5 @@
// Maybe later... using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
/*
using System; using System;
using System.Net.Http; using System.Net.Http;
using System.Threading; using System.Threading;
@@ -55,8 +54,8 @@ public class TelegratorWClient : WTelegramBotClient, ITelegratorBot, ICollecting
{ {
try try
{ {
await new HostedWideBotUpdateReceiver(this) await new HostedWideBotUpdateReceiver(NullLoggerFactory.Instance.CreateLogger<HostedWideBotUpdateReceiver>(), this, UpdateRouter, null)
.ReceiveAsync(UpdateRouter, cancellationToken) .StartAsync(cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
} }
catch (Exception exception) catch (Exception exception)
@@ -72,5 +71,4 @@ public class TelegratorWClient : WTelegramBotClient, ITelegratorBot, ICollecting
TelegratorLogging.LogInformation("Telegrator bot stopped (cancelled)"); TelegratorLogging.LogInformation("Telegrator bot stopped (cancelled)");
} }
} }
} }
*/
@@ -27,13 +27,26 @@ public static class HandlersExtensions
{ {
extension<TUpdate>(AbstractUpdateHandler<TUpdate> handler) where TUpdate : class extension<TUpdate>(AbstractUpdateHandler<TUpdate> handler) where TUpdate : class
{ {
public WUpdate WUpdate public WTelegramBotClient WClient
{ {
get get
{ {
object? update = typeof(AbstractUpdateHandler<TUpdate>).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) if (update is not WUpdate wUpdate)
throw new InvalidCastException(); throw new InvalidCastException("Update is not assignable to `WTelegram.Types.Update`");
return wUpdate; return wUpdate;
} }
@@ -41,7 +54,7 @@ public static class HandlersExtensions
public TLUpdate? TLUpdate public TLUpdate? TLUpdate
{ {
get => handler.WUpdate.TLUpdate; get => handler.WideUpdate.TLUpdate;
} }
} }
@@ -55,14 +68,8 @@ public static class HandlersExtensions
/// <summary> /// <summary>
/// Provides extension methods for <see cref="IHostApplicationBuilder"/> to configure Telegrator. /// Provides extension methods for <see cref="IHostApplicationBuilder"/> to configure Telegrator.
/// </summary> /// </summary>
public static class ServiceCollectionExtensions public static class WideHostBuilderExtensions
{ {
public static IServiceCollection ConfigureWideTelegram(this IServiceCollection services, WTelegramBotClientOptions options)
{
services.AddSingleton(Options.Create(options));
return services;
}
/// <summary> /// <summary>
/// Replaces TelegramBotHostBuilder. Configures DI, options, and handlers. /// Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
/// </summary> /// </summary>
@@ -133,6 +140,19 @@ public static class ServiceCollectionExtensions
services.AddTelegramBotHostDefaults(); services.AddTelegramBotHostDefaults();
services.AddMTProtoUpdateReceiver(); services.AddMTProtoUpdateReceiver();
} }
}
/// <summary>
/// Contains extensions for <see cref="IServiceCollection"/>
/// Provides method to configure Telegram Bot WebHost
/// </summary>
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) public static IServiceCollection AddMTProtoUpdateReceiver(this IServiceCollection services)
{ {
@@ -149,8 +169,12 @@ public static class ServiceCollectionExtensions
/// <summary> /// <summary>
/// Provides useful methods to adjust Telegram bot Host /// Provides useful methods to adjust Telegram bot Host
/// </summary> /// </summary>
public static class TelegramBotHostExtensions public static class WideTelegramBotHostExtensions
{ {
/// <summary>
/// Replaces the initialization logic from TelegramBotWebHost constructor.
/// Initializes the bot and logs handlers on application startup.
/// </summary>
public static IHost UseWideTelegrator(this IHost botHost) public static IHost UseWideTelegrator(this IHost botHost)
{ {
if (!botHost.Services.TryFindWTelegramBotClient()) if (!botHost.Services.TryFindWTelegramBotClient())
@@ -32,11 +32,13 @@ public class MicrosoftLoggingAdapter : ITelegratorLogger
if (exception != null) 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 else
{ {
_logger.Log(msLogLevel, default, message, null, (str, _) => str); _logger.Log(msLogLevel, default, message, null,
(str, _) => str);
} }
} }
} }
@@ -15,7 +15,7 @@
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild> <EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
<Title>Telegrator.Hosting</Title> <Title>Telegrator.Hosting</Title>
<Version>1.16.9</Version> <Version>1.17.0</Version>
<Authors>Rikitav Tim4ik</Authors> <Authors>Rikitav Tim4ik</Authors>
<Company>Rikitav Tim4ik</Company> <Company>Rikitav Tim4ik</Company>
<RepositoryUrl>https://github.com/Rikitav/Telegrator</RepositoryUrl> <RepositoryUrl>https://github.com/Rikitav/Telegrator</RepositoryUrl>
+1 -1
View File
@@ -127,7 +127,7 @@ public static class HostBuilderExtensions
/// Contains extensions for <see cref="IServiceCollection"/> /// Contains extensions for <see cref="IServiceCollection"/>
/// Provides method to configure Telegram Bot Host /// Provides method to configure Telegram Bot Host
/// </summary> /// </summary>
public static class ServicesCollectionExtensions public static class HostServicesCollectionExtensions
{ {
public static IServiceCollection ConfigureTelegram(this IServiceCollection services, TelegramBotClientOptions options) public static IServiceCollection ConfigureTelegram(this IServiceCollection services, TelegramBotClientOptions options)
{ {
+1 -2
View File
@@ -14,7 +14,7 @@
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild> <EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
<Title>Telegrator : Telegram.Bot mediator framework</Title> <Title>Telegrator : Telegram.Bot mediator framework</Title>
<Version>1.16.9</Version> <Version>1.17.0</Version>
<Authors>Rikitav Tim4ik</Authors> <Authors>Rikitav Tim4ik</Authors>
<Company>Rikitav Tim4ik</Company> <Company>Rikitav Tim4ik</Company>
<RepositoryUrl>https://github.com/Rikitav/Telegrator</RepositoryUrl> <RepositoryUrl>https://github.com/Rikitav/Telegrator</RepositoryUrl>
@@ -23,7 +23,6 @@
<PackageIcon>telegrator_nuget.png</PackageIcon> <PackageIcon>telegrator_nuget.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile> <PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE</PackageLicenseFile> <PackageLicenseFile>LICENSE</PackageLicenseFile>
<UserSecretsId>b78bc62d-e49f-4ef0-b2de-ff4ceb3971af</UserSecretsId>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@@ -1,8 +1,7 @@
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration; using Microsoft.Data.Sqlite;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Telegrator.Hosting; using System.Data.Common;
using Telegrator.Hosting.Web;
namespace Telegrator; namespace Telegrator;
@@ -22,8 +21,6 @@ internal static class Program
builder.Build() builder.Build()
.UseTelegratorWeb(dontMap: true) .UseTelegratorWeb(dontMap: true)
.RemapWebhook("https://amazing-butt-sex.cloudpub.ru/") .RemapWebhook("https://amazing-butt-sex.cloudpub.ru/")
.AddLoggingAdapter()
.SetBotCommands()
.Run(); .Run();
} }
@@ -40,8 +37,25 @@ internal static class Program
builder.Build() builder.Build()
.UseTelegrator() .UseTelegrator()
.AddLoggingAdapter() .Run();
.SetBotCommands() }
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(); .Run();
} }
} }
@@ -9,6 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Data.Sqlite" Version="10.0.7" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.6" /> <PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.5.6" />
@@ -18,6 +19,10 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\src\Telegartor.RedisStateStorage\Telegartor.RedisStateStorage.csproj" />
<ProjectReference Include="..\..\src\Telegrator.Hosting.Web\Telegrator.Hosting.Web.csproj" />
<ProjectReference Include="..\..\src\Telegrator.Hosting.WideBot\Telegrator.Hosting.WideBot.csproj" />
<ProjectReference Include="..\..\src\Telegrator.Localized\Telegrator.Localized.csproj" />
<ProjectReference Include="..\..\src\Telegrator\Telegrator.csproj" /> <ProjectReference Include="..\..\src\Telegrator\Telegrator.csproj" />
<ProjectReference Include="..\..\src\Telegrator.Hosting\Telegrator.Hosting.csproj" /> <ProjectReference Include="..\..\src\Telegrator.Hosting\Telegrator.Hosting.csproj" />
</ItemGroup> </ItemGroup>