Skip to content

Telegram: Final response chunks lose thread_id, breaking forum topic routing #7355

@PheriwinkleOC

Description

@PheriwinkleOC

Describe the bug
In Telegram forum groups, responses sometimes leak into the wrong thread (or General). This happens because gateway/run.py fails to pass the correct thread_id in the metadata when sending the final response chunk or when streaming falls back to a single adapter.send() call.

To Reproduce

  1. Use Hermes in a Telegram supergroup with Topics enabled.
  2. Send a message in a specific topic.
  3. The final first_response (around line 7332) uses getattr(event, "metadata", None) instead of explicitly passing source.thread_id.

Expected behavior
The final response should stay in the original thread by explicitly checking source.thread_id.

Code snippet
In gateway/run.py around line 7332:

# Current:
await adapter.send(source.chat_id, first_response,
                   metadata=getattr(event, "metadata", None))

# Expected:
_thread_meta = {"thread_id": source.thread_id} if source.thread_id else getattr(event, "metadata", None)
await adapter.send(source.chat_id, first_response, metadata=_thread_meta)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High — major feature broken, no workaroundcomp/gatewayGateway runner, session dispatch, deliveryplatform/telegramTelegram bot adaptertype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions