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.
Problem:
In Telegram group chats, the inbound message envelope passed to the LLM does NOT include the sender name/username in the
Bodyheader. The headeris 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: informatAgentEnvelope({ from: ... })for groups it usesbuildGroupLabel(msg, chatId)which only returns<group title> id:<chatId>.ctxPayload(SenderName,SenderId,SenderUsername) but is not surfaced inBody.Expected behavior:
Include sender info in the group
fromlabel in theBodyheader, e.g.[Telegram GROUP CHAT id:-12312312321 from Ada Lovelace (@ada) id:9 2026-01-06T20:40Z] ...
Suggested fix:
buildGroupFromLabel(msg, chatId, senderId)that returns${groupLabel} from ${senderLabel}.buildSenderLabelto accept senderId (not chatId) so the ID is correct for the user.ctxPayloadfields unchanged.Tests:
Update
src/telegram/bot.test.ts(there is a group message test) to assert thatpayload.Bodyincludes both the group label and sender (name/id)in the header.
Please implement and run the relevant test(s) if available.