Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion gateway/platforms/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -2350,7 +2350,12 @@ def _clean_bot_trigger_text(self, text: Optional[str]) -> Optional[str]:
def _should_process_message(self, message: Message, *, is_command: bool = False) -> bool:
"""Apply Telegram group trigger rules.

DMs remain unrestricted. Group/supergroup messages are accepted when:
User allowlist (``TELEGRAM_ALLOWED_USERS``) applies to BOTH DMs and
groups when set — non-allowlisted senders are dropped before any
group-mention gate runs. Empty env var preserves the legacy
permissive default.

Group/supergroup messages are then accepted when:
- the chat is explicitly allowlisted in ``free_response_chats``
- ``require_mention`` is disabled
- the message replies to the bot
Expand All @@ -2364,6 +2369,9 @@ def _should_process_message(self, message: Message, *, is_command: bool = False)
mentioning the bot (``@botname /command``), both of which are
recognised as mentions by :meth:`_message_mentions_bot`.
"""
sender_id = str(getattr(getattr(message, "from_user", None), "id", ""))
if not self._is_callback_user_authorized(sender_id):
return False
if not self._is_group_chat(message):
return True
thread_id = getattr(message, "message_thread_id", None)
Expand Down