Telegrator.Hosting 1.16.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Telegrator.Hosting --version 1.16.0
                    
NuGet\Install-Package Telegrator.Hosting -Version 1.16.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Telegrator.Hosting" Version="1.16.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Telegrator.Hosting" Version="1.16.0" />
                    
Directory.Packages.props
<PackageReference Include="Telegrator.Hosting" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Telegrator.Hosting --version 1.16.0
                    
#r "nuget: Telegrator.Hosting, 1.16.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Telegrator.Hosting@1.16.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Telegrator.Hosting&version=1.16.0
                    
Install as a Cake Addin
#tool nuget:?package=Telegrator.Hosting&version=1.16.0
                    
Install as a Cake Tool

Telegrator

Telegrator Banner

A modern reactive framework for Telegram bots in C# with aspect-oriented design, mediator-based dispatching, and flexible architecture.


🚀 About Telegrator

Telegrator is a next-generation framework for building Telegram bots in C#, inspired by AOP (Aspect-Oriented Programming) and the mediator pattern. It enables decentralized, easily extensible, and maintainable bot logic without traditional state machines or monolithic handlers.


✨ Key Features

  • Aspect-oriented approach: Handlers and filters are "aspects" of the bot, easily composable and extendable.
  • Decentralized logic: Each handler is an independent module—no more giant switch/case blocks.
  • Mediator-based dispatching: All updates are routed through a powerful mediator-dispatcher.
  • Flexible filtering: Filters for commands, text, sender, chat, regex, and much more.
  • Execution order and priorities: Easily control handler priorities and execution order.
  • Thread safety and concurrency control: Limit the number of concurrent handlers, await other updates inside a handler.
  • Extensibility via attributes and providers: Easily add your own filters, handlers, and state keepers.
  • Minimal boilerplate—maximum declarativity!

🧩 Architecture & Approach

  • Decentralization: Bot logic is split into independent handlers (aspects), each responsible for its own part.
  • Mediator: All Telegram updates go through a mediator, which decides which handlers should process them and in what order.
  • Filters: Describe handler trigger conditions in a flexible, declarative way.
  • State: Built-in mechanisms for user/chat state without manual state machines.

🛠️ Quick Start

1. Installation

# .NET CLI
dotnet add package Telegrator

# NuGet CLI
NuGet\Install-Package Telegrator

2. Minimal Bot Example

using Telegrator.Handlers;
using Telegrator.Annotations;

[MessageHandler]
public class HelloHandler : MessageHandler
{
    public override async Task<Result> Execute(IAbstractHandlerContainer<Message> container, CancellationToken cancellation)
    {
        await Reply("Hello, world!", cancellationToken: cancellation);
        return Result.Ok();
    }
}

// Registration and launch:
var bot = new TelegratorClient("<YOUR_BOT_TOKEN>");
bot.Handlers.AddHandler<HelloHandler>();
bot.StartReceiving();

3. Adding Filtering and Commands

using Telegram.Bot.Types.Enums;
using Telegrator.Handlers;
using Telegrator.Annotations;

[CommandHandler, CommandAllias("start", "hello"), ChatType(ChatType.Private)]
public class StartCommandHandler : CommandHandler
{
    public override async Task<Result> Execute(IAbstractHandlerContainer<Message> container, CancellationToken cancellation)
    {
        await Responce("Welcome!", cancellationToken: cancellation);
        return Result.Ok();
    }
}

// Registration:
bot.Handlers.AddHandler<StartCommandHandler>();

4. State Management Example

using Telegrator.Handlers;
using Telegrator.Annotations;

[CommandHandler, CommandAllias("first"), NumericState(SpecialState.NoState)]
public class StateKeepFirst : CommandHandler
{
    public override async Task<Result> Execute(IAbstractHandlerContainer<Message> container, CancellationToken cancellation)
    {
        container.CreateNumericState();
        container.ForwardNumericState();
        await Reply("first state moved (1)", cancellationToken: cancellation);
        return Result.Ok();
    }
}

// Registration:
bot.Handlers.AddHandler<StateKeepFirst>();

🏆 Why Telegrator over state machines?

  • No tangled switch/case—logic is split into independent handlers.
  • Flexible dispatching—the mediator decides who and when processes an event.
  • Simple state management—no need to implement state machines manually.
  • Easy scaling—add new handlers without rewriting old ones.
  • High code readability and maintainability.

📚 Documentation & Examples


🤝 Contribution & Feedback

We welcome your questions, suggestions, and pull requests! Open issues or contact us directly.


⚡ License

GPLv3

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Telegrator.Hosting:

Package Downloads
Telegrator.Hosting.Web

Package Description

Telegrator.Hosting.WideBot

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.17.1 110 5/1/2026
1.17.0 110 4/27/2026
1.16.9 102 4/23/2026
1.16.8 131 4/3/2026
1.16.7 117 3/15/2026
1.16.6 113 3/15/2026
1.16.5 111 3/9/2026
1.16.4 101 3/9/2026
1.16.3 112 3/8/2026
1.16.1 111 3/7/2026
1.16.0 108 3/7/2026
1.15.9 323 8/24/2025
1.15.8 290 8/24/2025
1.15.7 152 8/23/2025
1.15.6 222 8/21/2025
1.15.5 222 8/19/2025
1.15.4 210 8/19/2025
1.15.3 224 8/19/2025
1.15.2 271 8/18/2025
1.15.1 202 8/18/2025
Loading failed