fix(cron): route Telegram DM-topic cron delivery through DeliveryRouter (#22773) - #50023
Conversation
🔎 Lint report:
|
| Rule | Count |
|---|---|
invalid-argument-type |
1 |
First entries
cron/scheduler.py:900: [invalid-argument-type] invalid-argument-type: Argument to `DeliveryRouter.__init__` is incorrect: Expected `dict[Platform, Any]`, found `Unknown | None`
✅ Fixed issues: none
Unchanged: 5919 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
|
Related: #22773 (issue being fixed), #42051 and #23249 (salvaged predecessors, both open), #33397 (adjacent webhook metadata), #22410 (merged DeliveryRouter three-mode foundation). Competing open fix-PRs for the same #22773 path, each a different mechanism: #48836 (patches send_message_tool.py + scheduler), #49649 (inline direct_messages_topic_id + utf-8 in scheduler, Windows angle). This PR reuses the canonical DeliveryRouter instead ("extend, don't duplicate"). Related, not duplicate — reviewer's choice of mechanism. |
6908606 to
8748951
Compare
…er (#22773) PR #22410 added three-mode Telegram topic routing to the live message path (TelegramAdapter.send via the gateway DeliveryRouter), but the cron delivery path never got it. cron/scheduler.py::_deliver_result sent through the live adapter with a bare ``{"thread_id": ...}`` and fell back to the standalone _send_telegram, neither of which addresses Bot API Direct Messages topics correctly. After Bot API 10.0 (2026-05-08), sending to a private chat with a bare ``message_thread_id`` is rejected/mis-routed, so cron deliveries to a private DM topic landed in the General topic instead of the requested lane. Fix: the cron live-adapter branch now routes the text send through the gateway's ``DeliveryRouter._deliver_to_platform`` — the same canonical path live messages use — so it inherits all three Telegram routing modes: 1. Forum/supergroup (negative chat_id) -> message_thread_id 2. Bot API DM topics (private chat_id + numeric topic id) -> direct_messages_topic_id (the case #22773 reported) 3. Hermes-created named private DM-topic lanes -> ensure_dm_topic + reply anchor For mode 2, a private-chat target with a numeric topic id is passed as ``direct_messages_topic_id`` metadata (verified end-to-end: TelegramAdapter._thread_kwargs_for_send turns it into ``{message_thread_id: None, direct_messages_topic_id: <int>}``), instead of a bare message_thread_id. Forum/supergroup and home-channel deliveries are unchanged. The standalone fallback (gateway down) is preserved. No new config knob and no duplicated routing logic — this reuses the existing DeliveryRouter rather than reimplementing topic routing in the cron path. Salvaged from #42051 (stepanov1975) and #23249 (devsart95), which both diagnosed the missing three-mode routing in the cron/standalone path; reimplemented onto the canonical DeliveryRouter that landed since those PRs were opened. Co-authored-by: Alex <9785479+stepanov1975@users.noreply.github.com> Co-authored-by: devsart95 <devsart95@gmail.com>
8748951 to
f43c616
Compare
…elegram-dmtopic fix(cron): route Telegram DM-topic cron delivery through DeliveryRouter (NousResearch#22773)
…elegram-dmtopic fix(cron): route Telegram DM-topic cron delivery through DeliveryRouter (NousResearch#22773)
…elegram-dmtopic fix(cron): route Telegram DM-topic cron delivery through DeliveryRouter (NousResearch#22773)
…elegram-dmtopic fix(cron): route Telegram DM-topic cron delivery through DeliveryRouter (NousResearch#22773)
…elegram-dmtopic fix(cron): route Telegram DM-topic cron delivery through DeliveryRouter (NousResearch#22773)
…elegram-dmtopic fix(cron): route Telegram DM-topic cron delivery through DeliveryRouter (NousResearch#22773)
Summary
PR #22410 added three-mode Telegram topic routing to the live message path (
TelegramAdapter.sendvia the gatewayDeliveryRouter), but the cron delivery path never got it.cron/scheduler.py::_deliver_resultsent through the live adapter with a bare{"thread_id": …}and fell back to the standalone_send_telegram— neither addresses Bot API Direct Messages topics correctly.After Bot API 10.0 (2026-05-08), sending to a private chat with a bare
message_thread_idis rejected / mis-routed, so cron deliveries to a private DM topic landed in the General topic instead of the requested lane (#22773).Fix
The cron live-adapter branch now routes the text send through the gateway's
DeliveryRouter._deliver_to_platform— the same canonical path live messages use — so cron inherits all three Telegram routing modes:message_thread_iddirect_messages_topic_id← the #22773 caseensure_dm_topic+ reply anchorFor mode 2, a private-chat target with a numeric topic id is passed as
direct_messages_topic_idmetadata. Verified end-to-end:TelegramAdapter._thread_kwargs_for_send({"direct_messages_topic_id": "7072"})→{message_thread_id: None, direct_messages_topic_id: 7072}— not a baremessage_thread_id. Forum/supergroup and home-channel deliveries are unchanged; the standalone fallback (gateway down) is preserved.No new config knob and no duplicated routing logic — this reuses the existing
DeliveryRouter(which landed since the candidate PRs were opened) rather than reimplementing topic routing in the cron path, per "extend, don't duplicate."Salvage / attribution
Salvaged from #42051 (@stepanov1975) and #23249 (@devsart95), which both diagnosed the missing three-mode routing in the cron/standalone path. Reimplemented onto the canonical
DeliveryRouter(different, lower-duplication approach), so authored here with both contributors co-credited.devsart95added to AUTHOR_MAP (chore commit).To be closed with crediting redirects: #42051, #23249 (and the adjacent #33397).
Tests
Replaced the stale
test_live_adapter_thread_fallback_records_delivery_error(which asserted the buggy bare-thread_idsend) withtest_live_adapter_private_dm_topic_routes_via_direct_messages_topic_id, a behavior contract asserting a private-chat numeric topic routes viadirect_messages_topic_idand never sets a baremessage_thread_id. Updated the live-adapter test harness to actually run the routed coroutine.485 passedintests/cron/;146 passedintests/tools/test_send_message_tool.py;220 passedin gateway delivery tests.Fixes #22773