Commit 8939d97
authored
feat(telegram): rich-message wire types for Bot API 10.1 (chat@4.31 4662309 — TG1/4) (#163)
* feat(telegram): rich-message wire types for Bot API 10.1 (chat@4.31 4662309 — TG1/4)
Port the Telegram rich-message wire types added upstream in chat@4.31.0
(commit 4662309, "native rich message formatting + streaming for Bot
API 10.1"), faithfully mirroring adapter-telegram/src/types.ts. Types only;
the runtime rich.py consumer lands in TG2.
New named media interfaces (extend TelegramFile):
TelegramAnimation, TelegramAudio, TelegramVideoQuality,
TelegramVideo (widened), TelegramVoice, plus TelegramLocation.
Recursive rich-text structures:
TelegramRichText, TelegramRichCaption, TelegramRichCell,
TelegramRichItem, TelegramRichBlock, TelegramRichMessage. The
recursive unions (TelegramRichText / TelegramRichBlock) are expressed as
quoted forward-ref TypeAlias strings so they resolve statically under
pyrefly without evaluating `|` against a not-yet-defined name at runtime.
TelegramMessage gains an optional rich_message payload, and its video
field is widened from the old inline shape to the named TelegramVideo
(the now-redundant TelegramVideoFile is dropped; it had no external refs).
Wire keys stay snake_case: the Telegram Bot API is natively snake_case,
so there is no camelCase serialization boundary here. Optional fields use
total=False with `# required` markers, matching the existing file style.
pyrefly: 0 errors. New structural tests build the representative recursive
rich_message payloads from upstream rich.test.ts.
* test(telegram): make rich-type fixtures pyrefly type-sound
Annotate each rich-message fixture with its concrete variant TypedDict
(TelegramRichBlockText, TelegramRichBlockTable, etc.) instead of the
recursive TelegramRichText / TelegramRichBlock unions, which pyrefly
cannot narrow from a bare dict literal. Recursion into a nested union
member is bound to a typed intermediate local of the concrete variant,
with a targeted type: ignore[assignment] on the union-to-member downcast
(the documented recursive-union limitation; all 9 are load-bearing).
All fixture dict literals now type-check with zero suppression, the 8
runtime assertions are unchanged, and pyrefly check on the test file
goes from 189 errors to 0.1 parent d3b8f3f commit 8939d97
2 files changed
Lines changed: 722 additions & 15 deletions
0 commit comments