feishu_admission_diagnostics.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536
  1. """Operator-facing diagnostics for Feishu inbound admission.
  2. Admission rejections are logged at DEBUG (busy groups with ``require_mention`` drop most
  3. traffic by design). The one rejection that is almost never intended — the code-default
  4. ``allowlist`` policy with an empty ``FEISHU_ALLOWED_USERS`` — gets one WARNING that names
  5. the keys to set, because under multiplex a secondary profile reads only its own ``.env``
  6. and a launch-profile ``FEISHU_GROUP_POLICY=open`` is (deliberately) not inherited.
  7. """
  8. from __future__ import annotations
  9. from typing import Any, Collection, Mapping, Optional
  10. def empty_allowlist_drop_warning(
  11. *,
  12. chat_id: str,
  13. group_rules: Mapping[str, Any],
  14. default_group_policy: str,
  15. allowed_group_users: Collection[str],
  16. ) -> Optional[str]:
  17. """Message for a group drop caused by the empty-allowlist default, else None.
  18. A per-chat ``group_rules`` entry, a non-``allowlist`` policy or a populated allowlist
  19. means the operator configured the deny; only the untouched default is surfaced.
  20. """
  21. if chat_id in group_rules or default_group_policy != "allowlist" or allowed_group_users:
  22. return None
  23. return (
  24. f"[Feishu] Dropped a group message in chat {chat_id}: group policy is 'allowlist' and "
  25. "FEISHU_ALLOWED_USERS is empty for this profile, so every human group message is rejected. "
  26. "Set FEISHU_GROUP_POLICY=open or FEISHU_ALLOWED_USERS=<open_id,...> in this profile's .env "
  27. "(under multiplex each profile reads only its own .env; the default profile's value is not "
  28. "inherited), or platforms.feishu.extra.group_rules in its config.yaml. "
  29. "Further drops are logged at DEBUG."
  30. )