feat: Support blocking commands in chat message - #477
Open
ziyilin wants to merge 1 commit into
Open
Conversation
支持在单聊和群聊中配置命令策略,限制用户可使用的命令。 包括 allowlist/denylist/open 三种模式,以及白名单绕过机制。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
为 DingTalk Connector 插件新增命令策略功能,支持在单聊和群聊中灵活控制用户可使用的命令,增强机器人的安全性和可控性。
解决issue:#549
功能详情
1. 三种策略模式
openallowlistdenylist2. 配置项说明
群聊命令策略 (
commandPolicy){ "commandPolicy": { "mode": "allowlist", "allow": ["/new", "/reset", "/clear"], "deny": ["/tools", "/admin"], "blockMessage": "抱歉,该命令已被禁用。如需帮助,请联系管理员。" } }单聊命令策略 (
dmCommandPolicy){ "dmCommandPolicy": { "mode": "allowlist", "allow": ["/new", "/reset", "/clear"], "blockMessage": "抱歉,我目前仅支持以下会话管理命令:\n/new、/reset、/clear" } }单聊命令白名单 (
dmCommandAllowlist){ "dmCommandAllowlist": ["user123", "admin456"] }3. 配置字段说明
modeopen/allowlist/denylist,默认openallowallowlist模式生效)denydenylist模式生效)blockMessage使用场景
场景1:限制群聊只能使用会话管理命令
OpenClaw 配置示例:
{ "channels": { "dingtalk-connector": { ... "commandPolicy": { "mode": "allowlist", "allow": ["/new", "/reset", "/clear"], "blockMessage": "抱歉,本群仅支持 /new、/reset、/clear 命令,其他功能请联系管理员。" } } } }场景2:禁用特定危险命令
OpenClaw 配置示例:
{ "channels": { "dingtalk-connector": { ... "commandPolicy": { "mode": "denylist", "deny": ["/tools", "/admin", "/config"], "blockMessage": "抱歉,该命令已被管理员禁用。如需帮助,请联系管理员。" } } } }场景3:单聊严格限制 + 管理员白名单
完整 OpenClaw 配置示例:
{ "channels": { "dingtalk-connector": { ... "dmCommandPolicy": { "mode": "allowlist", "allow": ["/new", "/reset", "/clear"], "blockMessage": "抱歉,我目前仅支持以下会话管理命令:\n/new、/reset、/clear\n如需其他帮助,请联系管理员。" }, "dmCommandAllowlist": ["1234567890", "0987654321"] } } }说明:
dmCommandAllowlist中的用户 ID 跳过dmCommandPolicy检查技术实现
核心逻辑
/开头的消息,普通消息直接放行/NEW等同于/new)mode为open时,允许所有命令拦截流程
/开头)默认配置
注意事项
open模式,不影响现有功能dmCommandAllowlist中的用户完全跳过策略检查