feat(dingtalk): add group_user_isolation to separate sessions per user in group chats

Add a new config option group_user_isolation (default: false) to the
DingTalk channel. When enabled, each user in a group chat gets their own
session while bot replies are still routed to the shared group chat.
This commit is contained in:
李明振
2026-06-01 23:01:19 +08:00
committed by Xubin Ren
parent 0042f68f94
commit da0aafcfbd
2 changed files with 54 additions and 0 deletions
+5
View File
@@ -160,6 +160,7 @@ class DingTalkConfig(Base):
allow_from: list[str] = Field(default_factory=list)
allow_remote_media_redirects: bool = False
remote_media_redirect_allowed_hosts: list[str] = Field(default_factory=list)
group_user_isolation: bool = False # If True, each user in group chat gets their own session
class DingTalkChannel(BaseChannel):
@@ -693,6 +694,9 @@ class DingTalkChannel(BaseChannel):
self.logger.info("inbound: {} from {}", content, sender_name)
is_group = conversation_type == "2" and conversation_id
chat_id = f"group:{conversation_id}" if is_group else sender_id
session_key = None
if is_group and self.config.group_user_isolation:
session_key = f"{self.name}:group:{conversation_id}:{sender_id}"
await self._handle_message(
sender_id=sender_id,
chat_id=chat_id,
@@ -702,6 +706,7 @@ class DingTalkChannel(BaseChannel):
"platform": "dingtalk",
"conversation_type": conversation_type,
},
session_key=session_key,
)
except Exception:
self.logger.exception("Error publishing message")