Skip to content

feat(telegram): group chat support + channel source context in system prompt#4

Open
dmitriyzhuk wants to merge 1 commit into
mainfrom
feat/telegram-group-chat
Open

feat(telegram): group chat support + channel source context in system prompt#4
dmitriyzhuk wants to merge 1 commit into
mainfrom
feat/telegram-group-chat

Conversation

@dmitriyzhuk

@dmitriyzhuk dmitriyzhuk commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Channel context in system prompt — agent now always knows which channel it's responding on. A # Channel section is injected near the top of the system prompt (after # Soul) with a sentence like "You are responding via Telegram (direct message) with @alice." — fixes the agent thinking every conversation is Bridle.

  • Telegram group chat — bot can now participate in groups, but only responds when directly @mentioned or someone replies to one of its messages:

    • Fetches its own @username via getMe on start-up
    • Maintains a per-group sliding buffer of the last 20 messages (discussion context)
    • Silent on non-mention messages — just adds them to the buffer
    • When addressed: strips the @mention, prepends the recent group discussion, passes everything to the agent
  • Richer Telegram metadatafromUserId, fromName, chatTitle, isGroup, channel (dm/group) now flow into the system prompt channel context builder.

Setup note

For the agent to see all group messages (not just @mentions), disable privacy mode in BotFather: /setprivacy → Disable.

Test plan

  • DM the bot — system prompt says "You are responding via Telegram (direct message) with @<username>."
  • Add bot to a group, send without @mention — bot stays silent, buffer fills
  • @mention the bot in a group — responds with [Recent group discussion] preamble
  • Reply to bot message in a group — bot responds
  • Verify Bridle sessions work normally (no regression)

🤖 Generated with Claude Code

… prompt

- Agent now always knows which channel it's responding on (Telegram DM,
  Telegram group, Bridle, Slack) via a # Channel section injected near the
  top of the system prompt — fixes the agent thinking every message is Bridle.

- Telegram group support: bot fetches its own @username on start, tracks a
  20-message per-group discussion buffer, and only calls the message handler
  when it is directly @mentioned or someone replies to its message.  Non-
  mention messages are silently collected for context.  When the bot is
  addressed the @mention is stripped from the text and the recent group
  discussion is prepended so the agent can see the conversation thread.

- Richer Telegram metadata: fromUserId, fromName (group sender), chatTitle,
  isGroup, channel type (dm / group) now flow through to the system prompt
  channel context builder.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant