Conversation
Adds the same require_mention behavior that Discord already has to the
Telegram gateway. In group chats, the bot now only responds when
@mentioned or replied to, preventing it from responding to every message.
NOTE: These features require BotFather group privacy mode to be turned
OFF so the bot receives all group messages. With privacy mode ON
(default), Telegram itself filters messages before they reach the bot,
making application-level filtering redundant.
Configuration (all optional, defaults preserve stock behavior):
- telegram.require_mention in config.yaml (default: true)
- telegram.free_response_channels: chat IDs where bot responds freely
- telegram.trigger_words: words that trigger a response without @mention
- Env var overrides: TELEGRAM_REQUIRE_MENTION, TELEGRAM_FREE_RESPONSE_CHANNELS,
TELEGRAM_TRIGGER_WORDS
Example config.yaml:
telegram:
require_mention: true
free_response_channels: [-100123456]
trigger_words: ["help", "deploy"]
Changes:
- gateway/platforms/telegram.py: Add mention detection, reply-to-bot
check, mention stripping, trigger word matching, and group message
filtering for both text and media handlers
- gateway/config.py: Bridge telegram settings from config.yaml to env
vars (require_mention, free_response_channels, trigger_words)
- tests/gateway/test_telegram_require_mention.py: 28 tests covering
all filtering logic
ctlst
marked this pull request as ready for review
March 22, 2026 15:35
Collaborator
|
Thanks for the contribution @ctlst — closing as redundant. PR #3870 (merged March 29) added |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds the same
require_mentionbehavior that Discord already has to the Telegram gateway. In group chats, the bot only responds when @mentioned, replied to, or when a trigger word is detected — preventing it from responding to every message.This requires BotFather group privacy mode to be turned OFF so the bot receives all group messages. With privacy mode ON (default), Telegram filters messages before they reach the bot, making application-level filtering redundant.
All settings are optional and default to preserving stock behavior — a fresh install with no config changes behaves identically to before this PR.
Related Issue
No existing issue. This was discovered while deploying Hermes in a Telegram group chat where the bot responded to every message without a way to filter.
Type of Change
Changes Made
gateway/platforms/telegram.py: Add 4 methods toTelegramAdapter:_is_bot_mentioned(message)— detects @username and text_mention entities_is_reply_to_bot(message)— checks if message replies to bot_strip_bot_mention(text)— removes @botName from message text_should_skip_group_message(message)— orchestrates all filtering (mention, reply, free channels, trigger words)_handle_text_messageand_handle_media_messageto call skip check earlygateway/config.py: Bridgetelegram.require_mention,telegram.free_response_channels, andtelegram.trigger_wordsfrom config.yaml to env vars (same pattern as existing Discord config bridge)tests/gateway/test_telegram_require_mention.py: 28 tests covering all filtering logicHow to Test
config.yaml:/mybots→ Bot Settings → Group Privacy → Turn OFF)pytest tests/gateway/test_telegram_require_mention.py -vChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs
28 tests passing: