fix(telegram): ignored_threads and mention_patterns read scoped env → own YAML like every sibling

Rebase reconciliation with main's JSON-allowlist decoding (#109423): the two
remaining readers that consulted config.extra before the env var now follow the
per-profile precedence rule (explicit scoped env → the profile's YAML → default),
and ignored_threads still decodes a JSON-string list after the read.

The Matrix blank-YAML test asserted YAML-over-env, the old precedence #108440's
review flagged; it now pins the contract: explicit env beats YAML, a blank env
value is unset (YAML applies), YAML beats the default, and an explicit empty
list is a real "no rooms" value.
This commit is contained in:
teknium1
2026-09-13 15:18:58 -07:00
committed by Teknium
parent 8c06594c40
commit 178bf0436c
2 changed files with 32 additions and 22 deletions
+14 -14
View File
@@ -5133,9 +5133,8 @@ class TelegramAdapter(BasePlatformAdapter):
return self._extra_str_set("allowed_topics", "TELEGRAM_ALLOWED_TOPICS")
def _telegram_ignored_threads(self) -> set[int]:
raw = self.config.extra.get("ignored_threads")
if raw is None:
raw = _scoped_gate_env("TELEGRAM_IGNORED_THREADS")
"""Thread ids to skip: scoped ``TELEGRAM_IGNORED_THREADS`` → ``config.extra`` → none."""
raw = _extra_or_secret(self.config.extra, "ignored_threads", "TELEGRAM_IGNORED_THREADS", "", blank_is_unset=False)
raw = _decode_json_list_literal(raw)
ignored: set[int] = set()
for value in (raw if isinstance(raw, list) else str(raw).split(",")):
@@ -5150,17 +5149,18 @@ class TelegramAdapter(BasePlatformAdapter):
def _compile_mention_patterns(self) -> List[re.Pattern]:
"""Compile optional regex wake-word patterns for group triggers."""
patterns = self.config.extra.get("mention_patterns")
if patterns is None:
raw = _scoped_gate_env("TELEGRAM_MENTION_PATTERNS", "").strip()
if raw:
try:
loaded = json.loads(raw)
except Exception:
loaded = [part.strip() for part in raw.splitlines() if part.strip()]
if not loaded:
loaded = [part.strip() for part in raw.split(",") if part.strip()]
patterns = loaded
# Scoped env → the profile's YAML → none. Only the env rung is a serialized string (JSON list,
# newline- or comma-separated); a YAML string is one literal pattern and is left intact.
env_raw = _scoped_gate_env("TELEGRAM_MENTION_PATTERNS", "").strip()
if env_raw:
try:
patterns = json.loads(env_raw)
except Exception:
patterns = [part.strip() for part in env_raw.splitlines() if part.strip()]
if not patterns:
patterns = [part.strip() for part in env_raw.split(",") if part.strip()]
else:
patterns = self.config.extra.get("mention_patterns")
if patterns is None:
return [] # before touching ``self.name``: tests build bare adapters via object.__new__
return compile_mention_patterns(patterns, log_prefix=self.name, platform_label="telegram", display_label="Telegram", logger_=logger)