Overview
TheTelegratorOptions class provides configuration options for controlling various aspects of Telegrator bot operation, including concurrency limits, routing behavior, and execution policies.
Telegrator
Implements: ITelegratorOptions
Properties
Gets or sets the maximum number of parallel working handlers. When
null, there is no limit on concurrent handler execution.Use case: Limit concurrency to prevent resource exhaustion when handling many simultaneous updates.Gets or sets a value indicating whether awaiting handlers should be routed separately from regular handlers.When
true, handlers that are awaiting user input are processed exclusively, preventing other handlers from interfering with the awaiting flow.Use case: Ensure that multi-step conversations are not interrupted by other handlers.Gets or sets a value indicating whether to exclude intersecting command aliases.When
true, the framework will detect and reject command handlers with overlapping aliases during registration.Use case: Prevent conflicts between similar command names like /start and /started.Gets or sets the global cancellation token for all bot operations.This token is used to gracefully shut down the bot and cancel all ongoing operations.
Examples
Basic Configuration
Limiting Concurrency
Limit the number of handlers that can execute simultaneously to prevent resource exhaustion:Exclusive Awaiting Handler Routing
Ensure that multi-step conversations are not interrupted by other handlers:Global Cancellation Token
Implement graceful shutdown with a cancellation token:Complete Configuration Example
Configuration Scenarios
High-Traffic Bot
For bots that handle many concurrent users:Resource-Constrained Environment
For bots running on limited resources:Wizard/Conversation-Heavy Bot
For bots with many multi-step conversations:Best Practices
Concurrency Limits
Concurrency Limits
- Set
MaximumParallelWorkingHandlersbased on your server’s resources - Monitor CPU and memory usage to find optimal values
- Start conservative (e.g., 5-10) and increase based on testing
- Use
null(unlimited) only if you’re confident about resource availability
Awaiting Handler Routing
Awaiting Handler Routing
- Enable
ExclusiveAwaitingHandlerRoutingfor conversation-heavy bots - Disable it if you need handlers to run alongside awaiting flows
- Test thoroughly with concurrent users to ensure expected behavior
Command Aliases
Command Aliases
- Keep
ExceptIntersectingCommandAliasesenabled (default) to prevent conflicts - Only disable if you have a specific need for overlapping command names
- Use unique, non-overlapping command names to avoid issues
Cancellation Tokens
Cancellation Tokens
- Always provide a
GlobalCancellationTokenfor production bots - Implement graceful shutdown handlers (Ctrl+C, SIGTERM)
- Use the same token for both options and
StartReceiving() - Clean up resources in cancellation handlers
See Also
- TelegratorClient - Main client class
- ITelegramBotInfo - Bot information interface
- Concurrency & Awaiting - Guide on managing concurrent handlers
- State Management - Guide on state keeping