Files
Telegrator/src/Telegrator.Hosting
Rikitav 3d2d21f6c0 * Added building delegate to UseTelegrator method
* Fixed Webhooker trying to resolve IEndpointRouteBuildr from DI
2026-03-15 17:20:53 +04:00
..
2026-03-09 13:23:21 +04:00
2026-03-09 13:23:21 +04:00
2026-03-09 13:23:21 +04:00
2026-03-09 13:40:58 +04:00
2026-03-07 20:53:41 +04:00

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


Installation

dotnet add package Telegrator.Hosting

Quick Start Example

Program.cs:

using Telegrator.Hosting;

// Creating builder
TelegramBotHostBuilder builder = TelegramBotHost.CreateBuilder(new HostApplicationBuilderSettings()
{
    Args = args,
    ApplicationName = "TelegramBotHost example",
});

// 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();

Application integration Example

Program.cs:

using Telegrator.Hosting;

// Creating builder
HostApplicationBuilder builder = Host.CreateApplicationBuilder(new HostApplicationBuilderSettings()
{
    Args = args,
    ApplicationName = "Host example",
});

// Adding Telegrator
builder.AddTelegrator();

// Registerring handlers (extension)
builder.Handlers.CollectHandlersAssemblyWide();

// Building and running application
builder.Build()
    .UseTelegrator()
    .SetBotCommands()
    .Run();


Configuration (appsettings.json)

{
  "TelegratorOptions": {
    "Token": "YOUR_BOT_TOKEN",
    "ExceptIntersectingCommandAliases": true
  },

  "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


License

GPLv3