Skip to content

[Bug]: Telegram groups sender missing in LLM envelope #336

@parubets

Description

@parubets

Problem:
In Telegram group chats, the inbound message envelope passed to the LLM does NOT include the sender name/username in the Body header. The header
is built from the group title + chatId only, so the LLM cannot distinguish who wrote the message. Example current format:
[Telegram GROUP CHAT id:-12312312321 2026-01-06T20:40Z] @yolo_bot some message here
[message_id: 75438]
There is no sender identity in the text. This leads to hallucinated usernames and breaks authorization checks that rely on LLM context.

Current code:

  • src/telegram/bot.ts: in formatAgentEnvelope({ from: ... }) for groups it uses buildGroupLabel(msg, chatId) which only returns <group title> id:<chatId>.
  • Sender metadata exists in ctxPayload (SenderName, SenderId, SenderUsername) but is not surfaced in Body.

Expected behavior:
Include sender info in the group from label in the Body header, e.g.
[Telegram GROUP CHAT id:-12312312321 from Ada Lovelace (@ada) id:9 2026-01-06T20:40Z] ...

Suggested fix:

  • Add a helper like buildGroupFromLabel(msg, chatId, senderId) that returns ${groupLabel} from ${senderLabel}.
  • Adjust buildSenderLabel to accept senderId (not chatId) so the ID is correct for the user.
  • Use this new group label in the envelope for group messages.
  • Keep existing ctxPayload fields unchanged.

Tests:
Update src/telegram/bot.test.ts (there is a group message test) to assert that payload.Body includes both the group label and sender (name/id)
in the header.

Please implement and run the relevant test(s) if available.

Metadata

Metadata

Assignees

No one assigned

    Labels

    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