* Changed public API overview generator behaviour, now working only in DEBUG builds
* Fixed wrong LeveldDebug method calls after moving logic from providers to router * Added independent "IndentFlags" property to inner debugger class * Fixed debug logging in few places * Removed "ICollectingOptions" and merged it with new options abstract "ITelegratorOptions" * Added WebHook version of hosting class
This commit is contained in:
@@ -10,6 +10,6 @@
|
||||
/// Executes the pre-building routine on the specified host builder.
|
||||
/// </summary>
|
||||
/// <param name="hostBuilder">The host builder to configure.</param>
|
||||
public static abstract void PreBuildingRoutine(TelegramBotHostBuilder hostBuilder);
|
||||
public static abstract void PreBuildingRoutine(ITelegramBotHostBuilder hostBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Telegrator.MadiatorCore;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Telegrator.Hosting.Configuration
|
||||
/// Internal proxy class for configuring Telegram bot client options from configuration.
|
||||
/// Extends ConfigureOptionsProxy to provide specific configuration for Telegram bot client options.
|
||||
/// </summary>
|
||||
internal class TelegramBotClientOptionsProxy : ConfigureOptionsProxy<TelegramBotClientOptions>
|
||||
public class TelegramBotClientOptionsProxy : ConfigureOptionsProxy<TelegramBotClientOptions>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the bot token.
|
||||
|
||||
@@ -7,3 +7,4 @@ using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
[assembly: SuppressMessage("Style", "IDE0290")]
|
||||
[assembly: SuppressMessage("Style", "IDE0090")]
|
||||
[assembly: SuppressMessage("Usage", "CA2254")]
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Telegrator.Configuration;
|
||||
using Telegrator.MadiatorCore.Descriptors;
|
||||
using Telegrator.Polling;
|
||||
|
||||
namespace Telegrator.Hosting.Polling
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public class HostUpdateHandlersPool(IOptions<TelegramBotOptions> options, ILogger<HostUpdateHandlersPool> logger) : UpdateHandlersPool(options.Value, options.Value.GlobalCancellationToken)
|
||||
public class HostUpdateHandlersPool(IOptions<TelegratorOptions> options, ILogger<HostUpdateHandlersPool> logger) : UpdateHandlersPool(options.Value, options.Value.GlobalCancellationToken)
|
||||
{
|
||||
private readonly ILogger<HostUpdateHandlersPool> _logger = logger;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Telegrator.Hosting.Polling
|
||||
public HostUpdateRouter(
|
||||
IHandlersProvider handlersProvider,
|
||||
IAwaitingProvider awaitingProvider,
|
||||
IOptions<TelegramBotOptions> options,
|
||||
IOptions<TelegratorOptions> options,
|
||||
IUpdateHandlersPool handlersPool,
|
||||
ITelegramBotInfo botInfo,
|
||||
ILogger<HostUpdateRouter> logger) : base(handlersProvider, awaitingProvider, options.Value, handlersPool, botInfo)
|
||||
@@ -33,7 +33,7 @@ namespace Telegrator.Hosting.Polling
|
||||
/// <inheritdoc/>
|
||||
public override Task HandleUpdateAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)
|
||||
{
|
||||
//Logger.LogInformation("Received update of type \"{type}\"", update.Type);
|
||||
Logger.LogInformation("Received update of type \"{type}\"", update.Type);
|
||||
return base.HandleUpdateAsync(botClient, update, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Telegrator.Configuration;
|
||||
using Telegrator.Providers;
|
||||
|
||||
namespace Telegrator.Hosting.Providers
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public class HostAwaitingProvider(IOptions<TelegramBotOptions> options, ILogger<HostAwaitingProvider> logger) : AwaitingProvider(options.Value)
|
||||
public class HostAwaitingProvider(IOptions<TelegratorOptions> options, ILogger<HostAwaitingProvider> logger) : AwaitingProvider(options.Value)
|
||||
{
|
||||
private readonly ILogger<HostAwaitingProvider> _logger = logger;
|
||||
}
|
||||
|
||||
@@ -12,10 +12,10 @@ namespace Telegrator.Hosting.Providers
|
||||
/// Pre host building task
|
||||
/// </summary>
|
||||
/// <param name="builder"></param>
|
||||
public delegate void PreBuildingRoutine(TelegramBotHostBuilder builder);
|
||||
public delegate void PreBuildingRoutine(ITelegramBotHostBuilder builder);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public class HostHandlersCollection(IServiceCollection hostServiceColletion, IHandlersCollectingOptions options) : HandlersCollection(options)
|
||||
public class HostHandlersCollection(IServiceCollection hostServiceColletion, ITelegratorOptions options) : HandlersCollection(options)
|
||||
{
|
||||
private readonly IServiceCollection Services = hostServiceColletion;
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Telegrator.Configuration;
|
||||
using Telegrator.Handlers.Components;
|
||||
using Telegrator.MadiatorCore;
|
||||
using Telegrator.MadiatorCore.Descriptors;
|
||||
@@ -18,7 +17,7 @@ namespace Telegrator.Hosting.Providers
|
||||
/// <inheritdoc/>
|
||||
public HostHandlersProvider(
|
||||
IHandlersCollection handlers,
|
||||
IOptions<TelegramBotOptions> options,
|
||||
IOptions<TelegratorOptions> options,
|
||||
IServiceProvider serviceProvider,
|
||||
ILogger<HostHandlersProvider> logger) : base(handlers, options.Value)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
# Telegrator.Hosting
|
||||
|
||||
**Telegrator.Hosting** is an extension for the Telegrator framework that provides seamless integration with the .NET Generic Host, enabling production-ready, scalable, and maintainable Telegram bot applications.
|
||||
|
||||
---
|
||||
|
||||
## Features
|
||||
- Integration with `Microsoft.Extensions.Hosting` (background services, DI, configuration, logging)
|
||||
- Automatic handler discovery and registration
|
||||
- Strongly-typed configuration via `appsettings.json` and environment variables
|
||||
- Graceful startup/shutdown and lifecycle management
|
||||
- Advanced error handling and logging
|
||||
- Supports all Telegrator handler/filter/state features
|
||||
|
||||
---
|
||||
|
||||
## Requirements
|
||||
- .NET 8.0 or later
|
||||
- [Telegrator](https://github.com/Rikitav/Telegrator)
|
||||
|
||||
---
|
||||
|
||||
## Installation
|
||||
|
||||
```shell
|
||||
dotnet add package Telegrator.Hosting
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Quick Start Example
|
||||
|
||||
**Program.cs:**
|
||||
```csharp
|
||||
using Telegrator.Hosting;
|
||||
|
||||
// Creating builder
|
||||
TelegramBotHostBuilder builder = TelegramBotHost.CreateBuilder(new TelegramBotHostBuilderSettings()
|
||||
{
|
||||
Args = args,
|
||||
DescendDescriptorIndex = false,
|
||||
ExceptIntersectingCommandAliases = true
|
||||
});
|
||||
|
||||
// Registerring handlers
|
||||
builder.Handlers.CollectHandlersAssemblyWide();
|
||||
|
||||
// Register your services
|
||||
builder.Services.AddSingleton<IMyService, MyService>();
|
||||
|
||||
// Building and running application
|
||||
TelegramBotHost telegramBot = builder.Build();
|
||||
telegramBot.SetBotCommands();
|
||||
telegramBot.Run();
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Configuration (appsettings.json)
|
||||
|
||||
```json
|
||||
{
|
||||
"TelegramBotClientOptions": {
|
||||
"Token": "YOUR_BOT_TOKEN"
|
||||
},
|
||||
|
||||
"HostOptions": {
|
||||
"ShutdownTimeout": 10,
|
||||
"BackgroundServiceExceptionBehavior": "StopHost"
|
||||
},
|
||||
|
||||
"ReceiverOptions": {
|
||||
"DropPendingUpdates": true,
|
||||
"Limit": 10
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- `TelegramBotClientOptions`: Bot token and client settings
|
||||
- `HostOptions`: Host lifecycle and shutdown behavior
|
||||
- `ReceiverOptions`: Long-polling configuration
|
||||
|
||||
---
|
||||
|
||||
## Documentation
|
||||
- [Telegrator Main Docs](https://github.com/Rikitav/Telegrator)
|
||||
- [Getting Started Guide](https://github.com/Rikitav/Telegrator/wiki/Getting-started)
|
||||
- [Annotation Overview](https://github.com/Rikitav/Telegrator/wiki/Annotation-overview)
|
||||
|
||||
---
|
||||
|
||||
## License
|
||||
GPLv3
|
||||
@@ -114,6 +114,8 @@ namespace Telegrator.Hosting
|
||||
if (_disposed)
|
||||
return;
|
||||
|
||||
_innerHost.Dispose();
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
_disposed = true;
|
||||
}
|
||||
|
||||
@@ -4,10 +4,9 @@ using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Polling;
|
||||
using Telegrator.Hosting.Configuration;
|
||||
using Telegrator.Configuration;
|
||||
using Telegrator.Hosting;
|
||||
using Telegrator.Hosting.Components;
|
||||
using Telegrator.Hosting.Configuration;
|
||||
using Telegrator.Hosting.Providers;
|
||||
using Telegrator.MadiatorCore;
|
||||
|
||||
@@ -51,7 +50,7 @@ namespace Telegrator.Hosting
|
||||
|
||||
_innerBuilder.Logging.ClearProviders();
|
||||
|
||||
Services.Configure<TelegramBotOptions>(Configuration.GetSection(nameof(TelegramBotOptions)));
|
||||
Services.Configure<TelegratorOptions>(Configuration.GetSection(nameof(TelegratorOptions)));
|
||||
Services.Configure<ReceiverOptions>(Configuration.GetSection(nameof(ReceiverOptions)));
|
||||
Services.Configure<TelegramBotClientOptions>(Configuration.GetSection(nameof(TelegramBotClientOptions)), new TelegramBotClientOptionsProxy());
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Telegrator.Configuration;
|
||||
|
||||
namespace Telegrator.Hosting
|
||||
{
|
||||
/// <summary>
|
||||
/// Settings os hosted Telegram bot
|
||||
/// </summary>
|
||||
public class TelegramBotHostBuilderSettings() : IHandlersCollectingOptions
|
||||
public class TelegramBotHostBuilderSettings() : TelegratorOptions
|
||||
{
|
||||
/// <inheritdoc cref="HostApplicationBuilderSettings.DisableDefaults"/>
|
||||
public bool DisableDefaults { get; set; }
|
||||
@@ -27,12 +26,6 @@ namespace Telegrator.Hosting
|
||||
/// <inheritdoc cref="HostApplicationBuilderSettings.ContentRootPath"/>
|
||||
public string? ContentRootPath { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool DescendDescriptorIndex { get; set; } = true;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool ExceptIntersectingCommandAliases { get; set; } = true;
|
||||
|
||||
internal HostApplicationBuilderSettings ToApplicationBuilderSettings() => new HostApplicationBuilderSettings()
|
||||
{
|
||||
DisableDefaults = DisableDefaults,
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
<EnableNETAnalyzers>True</EnableNETAnalyzers>
|
||||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||
<Version>1.0.6</Version>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<Version>1.0.7</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -38,4 +39,11 @@
|
||||
<ProjectReference Include="..\Telegrator\Telegrator.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="README.md">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -4,7 +4,6 @@ using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Types;
|
||||
using Telegrator.Configuration;
|
||||
|
||||
Reference in New Issue
Block a user