BotRouter calls your handler, it resolves every parameter automatically. You never build a parameter list by hand — just declare what you need and the generator emits the injection code at compile time.
Resolution order
Parameters are matched against the following sources in order. The first match wins; a parameter is never tested against a lower-priority source if a higher one already applies.Examples for each injection pattern
ITelegramBotClient — the bot itself
The client is passed straight through from IUpdateHandler.HandleUpdateAsync. Declare it in any position:
CancellationToken — shutdown signal
The cancellation token from the polling loop is forwarded automatically. Propagate it to every async call:
Update — the raw update envelope
Request the full Update object when you need fields that are not part of a single payload:
Payload types — strongly typed DTO injection
Declare a parameter whose type is the payload DTO (or a base type it derives from). The generator extracts the payload from the update and injects it directly. The payload is resolved from whicheverUpdate property carries a value assignable to that type:
[Key("x")] T — keyed DI services
Apply [Key] from PolyBot.Attributes to resolve a service registered under a specific key. The key must be a compile-time constant string or integer:
Anything else — plain DI services
Any parameter type not matched by the rules above is resolved withGetRequiredService<T>(). This is how you inject application services:
Combining injection patterns
All resolution rules compose freely within one signature. The generator handles them independently, in the order they appear in the parameter list:Restrictions in [ExceptionHandler] methods
Exception handlers follow the same injection rules, with one important difference: there is no current update in the error path, so update-bound parameters are rejected. Declaring Message, CallbackQuery, or any other payload type in an [ExceptionHandler] signature produces diagnostic CUR032.
Parameters that are available in exception handlers:
Exception— the caught exceptionHandleErrorSource— the error source enum from Telegram.BotITelegramBotClient— the bot clientCancellationToken— the cancellation token[Key("x")] T— keyed DI services- Any other type — resolved via
GetRequiredService<T>()