Skip to content

refactor(telegram): consolidate bot handlers into named modules - #122174

Merged
obviyus merged 1 commit into
mainfrom
refactor/telegram-handler-modules
Aug 11, 2026
Merged

obviyus merged 1 commit into
mainfrom
refactor/telegram-handler-modules

Conversation

@obviyus

@obviyus obviyus commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

What Problem This Solves

bot-handlers.* was 22 files behind a 22-line fan-out whose registration order was enforced only by call order: six files holding one callback_query switch, four files holding one inbound pipeline, every interface derived as ReturnType<typeof createTelegramXRuntime>, an 8-positional-argument processMessage type, and RegisterTelegramHandlerParams declared inside the 2,156-line bot-native-commands.ts. Only 7 of 22 files had tests.

Why This Change Was Made

The family now has three named coordinators behind the same single entry (registerTelegramHandlers, which owns registration order directly): the inbound pipeline (authorization → buffer → media → text → processing), the callback router (one internal table; approvals/errors/interactions as its controls), and event bindings (reaction, poll-answer, migration). Contracts live in a leaf bot-handlers.types.ts — zero implementation-derived types, named inbound-disposition and callback-outcome unions, processMessage as a named options object. RegisterTelegramHandlerParams moved to the leaf with a full cutover (no re-export shim). Per-slice factory graph and its cross-runtime parameter threading deleted; 12 *.runtime.ts slice files removed, externally-mocked module paths preserved.

User Impact

None: behavior-neutral. bot.test.ts (6,369 lines, the front-door pin) and the ingress-coalescing e2e are byte-identical to main — verified by SHA-256 in the round report — and green.

Evidence

  • Grouped suite: handlers + bot + ingress e2e, 185 tests green; both cycle checkers, both type lanes, oxlint on all 27 touched files (tests included), git diff --check clean.
  • Production LOC net +220 (+3104/−2884); tests +48. Named tradeoff, deliberately surfaced for maintainer ruling before landing: the residual buys the written leaf contract and three named coordinators while deleting the factory graph — the same interface-over-lines trade as refactor(telegram): merge dispatch controllers into one turn module #122091's +93, at larger scale and without an external policy forcing it. Compression was verified against donors (callback controls net −7 vs its three donor files; message-context 575 vs 678) — the growth is contracts, not duplication.

@clawsweeper

clawsweeper Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@obviyus
obviyus marked this pull request as ready for review August 11, 2026 17:44
@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: XL maintainer Maintainer-authored PR labels Aug 11, 2026
@obviyus

obviyus commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator Author

Telegram E2E evidence (exact head 9c8af83ac1c045f0a022f9c63541da38f9c6cc4d)

Live default-turn probe via the QA userbot lane (TDLib user, mock provider, ephemeral gateway from this head; DM, ids redacted): sent a real message, received the expected reply — the full inbound path now runs through the consolidated modules end to end (InboundPipeline authorization→buffer→media→text→processing, then dispatch/delivery), on real Telegram transport.

This diff is behavior-neutral by construction and by proof: bot.test.ts (the 6,369-line front-door suite driving handlers through createTelegramBot) and the ingress-coalescing e2e are byte-identical to main (SHA-256-pinned in the build report) and green, alongside the 7 rerouted colocated handler suites (185 tests total in the grouped run). Callback and authorization flows specifically are pinned by those suites — the userbot lane has no native callback-press verb, so no live button-press drive is included; the registration-order behavior formerly enforced by the deleted fan-out file is asserted by the new entry's test.

Gate ledger on this head: both cycle checkers, both type lanes, oxlint on all 27 touched files, git diff --check — all clean.

@obviyus
obviyus force-pushed the refactor/telegram-handler-modules branch from 9c8af83 to 35c40ab Compare August 11, 2026 18:06
@obviyus

obviyus commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator Author

Closing the review's two next-steps on exact head 35c40ab: (1) the live default-turn userbot probe was rerun on this head — real Telegram send and expected reply through the consolidated inbound pipeline, exit 0; (2) the +185 classified production LOC tradeoff is maintainer-accepted (Ayaan): the residual is written leaf contracts and named coordinators replacing the derived-type factory graph — better design over line count, same trade as #122091.

@obviyus
obviyus enabled auto-merge (squash) August 11, 2026 18:11
@obviyus
obviyus merged commit d2825c7 into main Aug 11, 2026
113 checks passed
@obviyus
obviyus deleted the refactor/telegram-handler-modules branch August 11, 2026 18:18
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 12, 2026
…claw#122174)

The bot-handlers family was 22 files behind a 22-line fan-out: six files holding one callback switch, four holding one inbound pipeline, every interface a derived ReturnType, processMessage taking 8 positional args, and its params type declared inside bot-native-commands.ts. Three named coordinators (inbound pipeline, callback router, event bindings) now sit behind the same registerTelegramHandlers entry with hand-written leaf contracts; the factory graph, 16 slice/barrel files, and the type shim are deleted. Behavior-neutral: bot.test.ts and the ingress e2e byte-identical to main (SHA-256-pinned) and green; +185 production LOC accepted as the written-contract tradeoff.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram maintainer Maintainer-authored PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant