PolyBot.Routing.UpdateExtensions is a static class of extension methods on Telegram.Bot.Types.Update. A Telegram Update carries one of many optional payload properties (Message, CallbackQuery, PollAnswer, etc.), and different payload types nest their user and chat information in different places. These helpers walk a fixed probe order and return the first match found, so you never need to write property-chain ?? chains by hand.
These are the exact same probe chains that
StateKeyResolver uses internally to resolve FSM keys. The probe order is fixed and matches Telegram.Bot 22.10’s Update property declaration order — first match wins.Methods
GetUserId()
null when none is present.
long?
The user id, or
null.GetChatId()
null when none is present.
BusinessConnection exposes only UserChatId (a long), not a full Chat object. It contributes to GetChatId() but not to GetChat().long?
The chat id, or
null.GetSender()
User object found across all payload types, or null.
User?
The sender
User, or null.GetChat()
Chat object found across all payload types, or null. Unlike GetChatId(), this returns null for BusinessConnection updates because only a UserChatId long is available there.
Chat?
The
Chat, or null.GetMessage()
Message?
The
Message, or null when none of the four properties is set.GetText()
GetMessage(), falling back to its Caption (media captions are typed like message text in Telegram). Returns null when there is no message-shaped payload or neither Text nor Caption is set.
string?
The message text or caption, or
null.Probe order
The following table shows the full probe order for each method. Within each group, properties are checked top-to-bottom and the first non-null result is returned.User id / Sender probe order
Chat id / Chat probe order
Usage in handlers
Because parameter injection resolvesITelegramBotClient, CancellationToken, Update, and the specific payload automatically, you will usually receive the typed payload directly. UpdateExtensions is most useful in:
- Filters — where you receive the raw
Updateand need a cross-type probe:
-
Exception handlers — there is no typed payload in the error path, but the
Updateis not available either (seeCUR032). UseGetUserId()/GetChatId()on updates you access through other means. -
State key resolution —
IStateMachine.SetAsynccallsStateKeyResolverwhich uses the same probe chains internally. Understanding the probe order tells you exactly which update types are keyed byStateKey.UserIdvs.StateKey.ChatIdvs.StateKey.UserInChat.