Why Telegrator?
Traditional Telegram bot development often leads to tangled switch/case statements, complex state machines, and tightly coupled code. Telegrator solves these problems with a modern, declarative approach.Aspect-Oriented Design
Each handler is an independent aspect that can be composed and extended without modifying existing code.
Mediator Pattern
All updates flow through a central mediator that routes them to appropriate handlers based on filters and priorities.
Declarative Filters
Specify handler conditions using intuitive attributes instead of imperative if/else chains.
Built-in State Management
Manage user and chat state without external storage or manual state machines.
Quick Example
Here’s a minimal bot that responds to the/start command in private chats:
Key Features
Aspect-Oriented Handler Architecture
Aspect-Oriented Handler Architecture
Handlers are independent “aspects” of your bot that can be added, removed, or modified without affecting other parts of the codebase. Each handler focuses on a single responsibility.
Mediator-Based Dispatching
Mediator-Based Dispatching
The
UpdateRouter acts as a mediator, receiving all Telegram updates and dispatching them to appropriate handlers based on filters, priorities, and execution order.Declarative Filter Attributes
Declarative Filter Attributes
Use attributes like
[CommandAllias("start")], [TextContains("hello")], and [ChatType(ChatType.Private)] to specify when handlers should execute.Built-in State Management
Built-in State Management
Manage numeric, string, and enum states for users and chats without external databases. State is tracked automatically by the framework.
Concurrency Control
Concurrency Control
Fine-grained control over handler execution. Limit concurrent handlers globally or per-handler, and await other updates from within a handler.
Extensibility
Extensibility
Create custom filters, state keepers, and aspect processors. The framework provides extension points at every level.
Microsoft.Extensions.Hosting Integration
Microsoft.Extensions.Hosting Integration
First-class support for .NET Generic Host, making it easy to integrate with ASP.NET Core applications and background services.
Next Steps
Installation
Install Telegrator via NuGet and set up your first project
Quickstart
Build your first Telegram bot in minutes
Core Concepts
Understand the architecture and design principles
API Reference
Explore the complete API documentation