Files
Telegrator/Telegrator.Hosting.Web

Telegrator.Hosting.Web

Telegrator.Hosting.Web is an extension for the Telegrator framework that enables seamless integration with ASP.NET Core and webhook-based Telegram bots. It is designed for scalable, production-ready web applications.


Features

  • ASP.NET Core integration for webhook-based bots
  • Automatic handler discovery and registration
  • Strongly-typed configuration via appsettings.json and environment variables
  • Dependency injection and middleware support
  • Graceful startup/shutdown and lifecycle management
  • Advanced error handling and logging
  • Supports all Telegrator handler/filter/state features

Requirements

  • .NET 8.0 or later
  • ASP.NET Core

Installation

dotnet add package Telegrator.Hosting.Web

Quick Start Example

Program.cs (ASP.NET Core):

using Telegrator.Hosting;
using Telegrator.Hosting.Web;

// Creating builder
TelegramBotWebHostBuilder builder = TelegramBotWebHost.CreateBuilder(new TelegramBotWebOptions()
{
    Args = args,
    WebhookUri = "https://you-public-host.ru/bot"
    ExceptIntersectingCommandAliases = true
});

// Register handlers
builder.Handlers.CollectHandlersAssemblyWide();
builder.Services.AddHandlersFromAssembly(typeof(Program).Assembly);

// Register your services
builder.Services.AddSingleton<IMyService, MyService>();

// Building and running application
TelegramBotWebHost telegramBot = builder.Build();
telegramBot.SetBotCommands();
telegramBot.Run();

Configuration (appsettings.json)

{
  "TelegramBotClientOptions": {
    "Token": "YOUR_BOT_TOKEN"
  }
}
  • TelegramBotClientOptions: Bot token and client settings

Documentation


License

GPLv3