gateway_env.py 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. """WhatsApp (Baileys bridge) env -> gateway config bridge (``PlatformEntry.env_overrides``)."""
  2. from gateway.config import GatewayConfig, Platform
  3. from gateway.platform_env import enable_from_env, getenv, home_step
  4. from utils import is_truthy_value
  5. def _enabled_flag(config: GatewayConfig) -> None:
  6. """WhatsApp (Baileys bridge) uses a flag, not credentials. WHATSAPP_ENABLED=false overrides YAML;
  7. WHATSAPP_ENABLED=true follows the credential contract — it never beats an explicit YAML disable
  8. (the dashboard's disable action writes only ``platforms.whatsapp.enabled: false`` and leaves the
  9. env flag on disk, #73289)."""
  10. raw = getenv("WHATSAPP_ENABLED")
  11. wa_cfg = config.platforms.get(Platform.WHATSAPP)
  12. if wa_cfg is not None and raw.lower() in {"false", "0", "no"}:
  13. wa_cfg.enabled = False
  14. elif is_truthy_value(raw):
  15. enable_from_env(config, Platform.WHATSAPP)
  16. ENV_ENABLE_CREDENTIALS = ("WHATSAPP_ENABLED",)
  17. ENV_OVERRIDES = (_enabled_flag, home_step(Platform.WHATSAPP, "WHATSAPP_HOME_CHANNEL"))
  18. # Authorization env names (``PlatformEntry`` fields). Core reads them from this file when the
  19. # live entry lacks them: a user plugin overriding this platform, safe mode, the plugin disabled.
  20. AUTHZ = {
  21. "allowed_users_env": "WHATSAPP_ALLOWED_USERS",
  22. "allow_all_env": "WHATSAPP_ALLOW_ALL_USERS",
  23. "own_policy_env": ("WHATSAPP_DM_POLICY", "WHATSAPP_GROUP_POLICY"),
  24. "allowlist_suppresses_pairing": True,
  25. }