diff --git a/gateway/run.py b/gateway/run.py index 60c57495b447..5ed8a3810669 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -79,6 +79,16 @@ def _ensure_ssl_certs() -> None: os.environ["SSL_CERT_FILE"] = candidate return +def _home_target_env_var(platform_name: str) -> str: + """Return the configured home-target env var for a platform.""" + from cron.scheduler import _HOME_TARGET_ENV_VARS + + return _HOME_TARGET_ENV_VARS.get( + platform_name.lower(), + f"{platform_name.upper()}_HOME_CHANNEL", + ) + + _ensure_ssl_certs() # Add parent directory to path @@ -4210,7 +4220,7 @@ async def _handle_message_with_agent(self, event, source, _quick_key: str, run_g # Skip for webhooks - they deliver directly to configured targets (github_comment, etc.) if not history and source.platform and source.platform != Platform.LOCAL and source.platform != Platform.WEBHOOK: platform_name = source.platform.value - env_key = f"{platform_name.upper()}_HOME_CHANNEL" + env_key = _home_target_env_var(platform_name) if not os.getenv(env_key): adapter = self.adapters.get(source.platform) if adapter: @@ -5739,9 +5749,9 @@ async def _handle_set_home_command(self, event: MessageEvent) -> str: platform_name = source.platform.value if source.platform else "unknown" chat_id = source.chat_id chat_name = source.chat_name or chat_id - - env_key = f"{platform_name.upper()}_HOME_CHANNEL" - + + env_key = _home_target_env_var(platform_name) + # Save to config.yaml try: import yaml @@ -5756,7 +5766,7 @@ async def _handle_set_home_command(self, event: MessageEvent) -> str: os.environ[env_key] = str(chat_id) except Exception as e: return f"Failed to save home channel: {e}" - + return ( f"✅ Home channel set to **{chat_name}** (ID: {chat_id}).\n" f"Cron jobs and cross-platform messages will be delivered here." diff --git a/tests/gateway/test_home_target_env_var.py b/tests/gateway/test_home_target_env_var.py new file mode 100644 index 000000000000..351823e2cdc3 --- /dev/null +++ b/tests/gateway/test_home_target_env_var.py @@ -0,0 +1,9 @@ +from gateway.run import _home_target_env_var + + +def test_matrix_home_target_env_var_uses_home_room(): + assert _home_target_env_var("matrix") == "MATRIX_HOME_ROOM" + + +def test_unknown_platform_home_target_env_var_falls_back_to_home_channel(): + assert _home_target_env_var("custom") == "CUSTOM_HOME_CHANNEL"