49310439e0
* Changed debug writing to trace writing inside "Alligator" * Added "HostedTelegramBotInfo" representing hosted version of ITelegramBotInfo. Provides access to services and configuration * Filters now can acces services and configuration using new "HostedTelegramBotInfo" through context.BotInfo property
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.jsonand 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
Installation
dotnet add package Telegrator.Hosting
Quick Start Example
Program.cs:
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)
{
"TelegramBotClientOptions": {
"Token": "YOUR_BOT_TOKEN"
},
"HostOptions": {
"ShutdownTimeout": 10,
"BackgroundServiceExceptionBehavior": "StopHost"
},
"ReceiverOptions": {
"DropPendingUpdates": true,
"Limit": 10
}
}
TelegramBotClientOptions: Bot token and client settingsHostOptions: Host lifecycle and shutdown behaviorReceiverOptions: Long-polling configuration
Documentation
License
GPLv3