hermes - 💡(How to fix) Fix [Gateway/Telegram] user.id is captured but not included in shared multi-user message prefix

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

In shared multi-user sessions (group chats, forum threads), Telegram's stable numeric user.id is correctly extracted from incoming messages and stored in SessionSource.user_id, but it is not included in the message prefix sent to the agent. Only user.full_name (the display name) appears in the [sender_name] prefix.

This means downstream parsers and game systems that need stable user identity across sessions cannot reliably identify users — display names change, Telegram numeric IDs don't.

Root Cause

In shared multi-user sessions (group chats, forum threads), Telegram's stable numeric user.id is correctly extracted from incoming messages and stored in SessionSource.user_id, but it is not included in the message prefix sent to the agent. Only user.full_name (the display name) appears in the [sender_name] prefix.

This means downstream parsers and game systems that need stable user identity across sessions cannot reliably identify users — display names change, Telegram numeric IDs don't.

Code Example

user_id = str(user.id) if user else (str(chat.id) if chat_type == "dm" else None)
   user_name = user.full_name if user ...

---

user_id: Optional[str] = None
   user_name: Optional[str] = None

---

if _is_shared_multi_user and source.user_name:
       message_text = f"[{source.user_name}] {message_text}"

---

if _is_shared_multi_user and source.user_name:
    if source.user_id:
        message_text = f"[{source.user_name}] [user:{source.user_id}] {message_text}"
    else:
        message_text = f"[{source.user_name}] {message_text}"

---

[Jack Zh] [user:12345678] message content

---

[Jack Zh] message content
RAW_BUFFERClick to expand / collapse

Description

In shared multi-user sessions (group chats, forum threads), Telegram's stable numeric user.id is correctly extracted from incoming messages and stored in SessionSource.user_id, but it is not included in the message prefix sent to the agent. Only user.full_name (the display name) appears in the [sender_name] prefix.

This means downstream parsers and game systems that need stable user identity across sessions cannot reliably identify users — display names change, Telegram numeric IDs don't.

Data Flow

  1. Telegram adapter (gateway/platforms/telegram.py:4706-4707):

    user_id = str(user.id) if user else (str(chat.id) if chat_type == "dm" else None)
    user_name = user.full_name if user ...

    ✅ user.id is extracted correctly.

  2. Stored in SessionSource (gateway/session.py:84-85):

    user_id: Optional[str] = None
    user_name: Optional[str] = None

    ✅ Both fields exist and are populated.

  3. Message formatting (gateway/run.py:6906-6907):

    if _is_shared_multi_user and source.user_name:
        message_text = f"[{source.user_name}] {message_text}"

    ❌ Only source.user_name is used. source.user_id is ignored.

Proposed Fix

Lines 6906-6907 of gateway/run.py:

if _is_shared_multi_user and source.user_name:
    if source.user_id:
        message_text = f"[{source.user_name}] [user:{source.user_id}] {message_text}"
    else:
        message_text = f"[{source.user_name}] {message_text}"

This makes messages appear as:

[Jack Zh] [user:12345678] message content

instead of just:

[Jack Zh] message content

Why This Matters

  • Display names change frequently on Telegram
  • Stable numeric user.id is the only reliable identifier
  • Needed for user databases, RPG game stores, moderation systems, and any application that tracks users across sessions
  • The data is already being fetched — just not surfaced to the agent context

Additional Context

  • The user.id number is Telegram's permanent user ID (never changes, even across username/name changes)
  • user.full_name is a mutable display string (subject to change any time)
  • SessionSource already has a user_id field — no schema changes needed
  • Alternative: make the format configurable via config.yaml (e.g. gateway.telegram.sender_prefix_mode: name | name+id | id)

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING