Skip to content

The agent that grows with you

fix(whatsapp): blank free_response_chats in YAML falls through to the env CSV

teknium162417876627c
diff --git a/gateway/platforms/whatsapp_common.py b/gateway/platforms/whatsapp_common.py
index ef202be5fcb..16bcd009932 100644
--- a/gateway/platforms/whatsapp_common.py
+++ b/gateway/platforms/whatsapp_common.py
@@ -18,7 +18,7 @@ import re
from pathlib import Path
from typing import Any, Dict, Optional
-from gateway.platforms._shared import get_scoped_secret as _get_wsecret
+from gateway.platforms._shared import extra_or_secret as _extra_or_wsecret, get_scoped_secret as _get_wsecret
from gateway.platforms.access_policy_mixin import OwnAccessPolicyMixin
@@ -93,10 +93,9 @@ class WhatsAppBehaviorMixin(OwnAccessPolicyMixin):
return bool(configured)
def _whatsapp_free_response_chats(self) -> set[str]:
- raw = self.config.extra.get("free_response_chats")
- if raw is None:
- raw = _get_wsecret("WHATSAPP_FREE_RESPONSE_CHATS", default="") or ""
- return self._coerce_allow_list(raw)
+ """``extra.free_response_chats`` (blank = unset) else the scoped env CSV."""
+ return self._coerce_allow_list(
+ _extra_or_wsecret(self.config.extra, "free_response_chats", "WHATSAPP_FREE_RESPONSE_CHATS"))
@staticmethod
def _coerce_allow_list(raw) -> set[str]:
diff --git a/tests/gateway/test_whatsapp_group_gating.py b/tests/gateway/test_whatsapp_group_gating.py
index 3c045c26769..2e9b152dd1e 100644
--- a/tests/gateway/test_whatsapp_group_gating.py
+++ b/tests/gateway/test_whatsapp_group_gating.py
@@ -118,6 +118,18 @@ def test_free_response_chats_bypass_mention_gating():
assert adapter._should_process_message(_group_message("hello everyone")) is True
+def test_blank_free_response_chats_falls_through_to_env(monkeypatch):
+ """A present-but-blank ``free_response_chats: ''`` in config.yaml means unset: the env CSV applies."""
+ from plugins.platforms.whatsapp.adapter import WhatsAppAdapter
+
+ monkeypatch.setenv("WHATSAPP_FREE_RESPONSE_CHATS", "[email protected]")
+ adapter = object.__new__(WhatsAppAdapter)
+ adapter.config = PlatformConfig(enabled=True, extra={"free_response_chats": ""})
+ assert adapter._whatsapp_free_response_chats() == {"[email protected]"}
+ adapter.config = PlatformConfig(enabled=True, extra={"free_response_chats": []})
+ assert adapter._whatsapp_free_response_chats() == set()
+
+
def test_free_response_chats_does_not_bypass_other_groups():
adapter = _make_adapter(
require_mention=True,