Package Description
$ dotnet add package Telegrator
A modern reactive framework for Telegram bots in C# with aspect-oriented design, mediator-based dispatching, and flexible architecture.
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.
# .NET CLI
dotnet add package Telegrator
# NuGet CLI
NuGet\Install-Package Telegrator
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();
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>();
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>();
We welcome your questions, suggestions, and pull requests! Open issues or contact us directly.
GPLv3