feat(platforms): add require_mention + allowed_users gating to DingTalk
DingTalk was the only messaging platform without group-mention gating or a per-user allowlist. Slack, Telegram, Discord, WhatsApp, Matrix, and Mattermost all support these via config.yaml + matching env vars; this change closes the gap for DingTalk using the same surface: Config: platforms.dingtalk.require_mention: bool (env: DINGTALK_REQUIRE_MENTION) platforms.dingtalk.mention_patterns: list (env: DINGTALK_MENTION_PATTERNS) platforms.dingtalk.free_response_chats: list (env: DINGTALK_FREE_RESPONSE_CHATS) platforms.dingtalk.allowed_users: list (env: DINGTALK_ALLOWED_USERS) Semantics mirror Telegram's implementation: - DMs are always accepted (subject to allowed_users). - Group messages are accepted only when the chat is allowlisted, mention is not required, the bot was @mentioned (dingtalk_stream sets is_in_at_list), or the text matches a configured regex wake-word. - allowed_users matches sender_id / sender_staff_id case-insensitively; a single "*" disables the check. Rationale: without this, any DingTalk user in a group chat can trigger the bot, which makes DingTalk less safe to deploy than the other platforms. A user's config.yaml already accepts require_mention for dingtalk but the value was silently ignored.
This commit is contained in:
@@ -677,6 +677,24 @@ def load_gateway_config() -> GatewayConfig:
|
||||
frc = ",".join(str(v) for v in frc)
|
||||
os.environ["WHATSAPP_FREE_RESPONSE_CHATS"] = str(frc)
|
||||
|
||||
# DingTalk settings → env vars (env vars take precedence)
|
||||
dingtalk_cfg = yaml_cfg.get("dingtalk", {})
|
||||
if isinstance(dingtalk_cfg, dict):
|
||||
if "require_mention" in dingtalk_cfg and not os.getenv("DINGTALK_REQUIRE_MENTION"):
|
||||
os.environ["DINGTALK_REQUIRE_MENTION"] = str(dingtalk_cfg["require_mention"]).lower()
|
||||
if "mention_patterns" in dingtalk_cfg and not os.getenv("DINGTALK_MENTION_PATTERNS"):
|
||||
os.environ["DINGTALK_MENTION_PATTERNS"] = json.dumps(dingtalk_cfg["mention_patterns"])
|
||||
frc = dingtalk_cfg.get("free_response_chats")
|
||||
if frc is not None and not os.getenv("DINGTALK_FREE_RESPONSE_CHATS"):
|
||||
if isinstance(frc, list):
|
||||
frc = ",".join(str(v) for v in frc)
|
||||
os.environ["DINGTALK_FREE_RESPONSE_CHATS"] = str(frc)
|
||||
allowed = dingtalk_cfg.get("allowed_users")
|
||||
if allowed is not None and not os.getenv("DINGTALK_ALLOWED_USERS"):
|
||||
if isinstance(allowed, list):
|
||||
allowed = ",".join(str(v) for v in allowed)
|
||||
os.environ["DINGTALK_ALLOWED_USERS"] = str(allowed)
|
||||
|
||||
# Matrix settings → env vars (env vars take precedence)
|
||||
matrix_cfg = yaml_cfg.get("matrix", {})
|
||||
if isinstance(matrix_cfg, dict):
|
||||
|
||||
Reference in New Issue
Block a user