docs(dingtalk): clarify disable_private_chat intent in comments

Addresses automated review: document that the guard is an intentional hard group-only switch (allowlisted DMs blocked by design) and that str() guards a None sender_id. Comment-only.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
李明振
2026-07-27 02:33:41 +08:00
committed by Xubin Ren
co-authored by Claude
parent 205889f9e0
commit 9f3dee0192
+5 -4
View File
@@ -760,14 +760,15 @@ class DingTalkChannel(BaseChannel):
session_key = f"{self.name}:group:{conversation_id}:{sender_id}" session_key = f"{self.name}:group:{conversation_id}:{sender_id}"
if not is_group and self.config.disable_private_chat: if not is_group and self.config.disable_private_chat:
# Private chat is disabled: reply with a notice and drop the # Group-only kill switch: drop DMs with a notice *before* any
# message before any permission/pairing logic runs, so even # allow_from / pairing check, so even allowlisted senders are
# allowlisted users are redirected to group chat. # redirected — intentional, this is a hard private-chat guard
# rather than an authorization decision. No session is created.
self.logger.info("private chat disabled; rejecting DM from {}", sender_name) self.logger.info("private chat disabled; rejecting DM from {}", sender_name)
await self.send( await self.send(
OutboundMessage( OutboundMessage(
channel=self.name, channel=self.name,
chat_id=str(chat_id), chat_id=str(chat_id), # str() guards a None sender_id
content="该机器人未开启私聊,请在群聊中与我对话。", content="该机器人未开启私聊,请在群聊中与我对话。",
) )
) )