本文将详细介绍 OpenClaw 中飞书(Feishu/Lark)频道在私聊和群聊两种模式下的配置方法,包括各种策略参数、使用场景以及如何获取必要的 ID 信息。通过本文,你可以灵活控制机器人的访问权限和行为,满足不同场景下的需求。
一、两种消息模式概述
飞书(Feishu/Lark)在 OpenClaw 中支持两种消息模式:
| 模式 | 术语 |
|---|---|
| 私聊 | Direct Message (DM) |
| 群聊 | Group Chat |
二、私聊 (DM) 配置参数
核心配置
json
{
"channels": {
"feishu": {
"dmPolicy": "pairing", // 默认值
"allowFrom": ["ou_xxx"] // 白名单模式下的用户 ID 列表
}
}
}
dmPolicy 参数详解
| 值 | 行为描述 |
|---|---|
"pairing" |
默认。未知用户会收到配对码,需要管理员手动批准 |
"allowlist" |
只有 allowFrom 列表中的用户可以对话 |
"open" |
允许所有人对话(需设置 allowFrom: ["*"]) |
"disabled" |
禁用私聊功能 |
私聊场景示例
场景 1: 严格的配对模式(默认)
json
{
"channels": {
"feishu": {
"dmPolicy": "pairing"
}
}
}
- 用户发消息 → 收到配对码 → 管理员执行
openclaw pairing approve feishu <CODE>批准
场景 2: 白名单模式
json
{
"channels": {
"feishu": {
"dmPolicy": "allowlist",
"allowFrom": ["ou_123456", "ou_789012"]
}
}
}
- 只有列表中的用户可以对话,其他人被忽略
场景 3: 完全开放
json
{
"channels": {
"feishu": {
"dmPolicy": "open",
"allowFrom": ["*"]
}
}
}
- 无需审批,任何人都可以直接对话
三、群聊 (Group) 配置参数
核心配置
json
{
"channels": {
"feishu": {
"groupPolicy": "allowlist", // 默认值
"groupAllowFrom": ["oc_xxx"],
"requireMention": true, // 默认值
"groups": {
"oc_xxx": {
"requireMention": false,
"enabled": true,
"allowFrom": ["ou_user1"]
}
}
}
}
}
groupPolicy 参数详解
| 值 | 行为描述 |
|---|---|
"open" |
允许所有群组 |
"allowlist" |
默认。只有 groupAllowFrom 或 groups 中配置的群组有效 |
"disabled" |
禁用所有群聊功能 |
requireMention 参数详解
| 值 | 行为描述 |
|---|---|
true |
必须在群聊中 @ 机器人才能触发回复 |
false |
群中任何消息都会触发回复(慎用) |
| 未设置 | 根据策略决定 |
群聊场景示例
场景 1: 允许所有群组,但需要 @mention
json
{
"channels": {
"feishu": {
"groupPolicy": "open",
"requireMention": true
}
}
}
- 用户在群中 @机器人 → 机器人回复
场景 2: 允许所有群组,不需要 @mention
json
{
"channels": {
"feishu": {
"groupPolicy": "open",
"requireMention": false
}
}
}
- 群中任何消息都会触发回复(慎用)
场景 3: 只允许特定群组
json
{
"channels": {
"feishu": {
"groupPolicy": "allowlist",
"groupAllowFrom": ["oc_group1", "oc_group2"]
}
}
}
- 只有配置的两个群组能使用机器人
场景 4: 按群组精细配置
json
{
"channels": {
"feishu": {
"groupPolicy": "allowlist",
"groupAllowFrom": ["oc_team_a", "oc_team_b"],
"groups": {
"oc_team_a": {
"requireMention": false
},
"oc_team_b": {
"requireMention": true,
"allowFrom": ["ou_admin1", "ou_admin2"]
}
}
}
}
}
-
团队 A 群:不需要 @mention
-
团队 B 群:需要 @mention,且限制发送者
场景 5: 禁用所有群聊
json
{
"channels": {
"feishu": {
"groupPolicy": "disabled"
}
}
}
四、完整配置参数速查表
顶层配置
| 参数 | 类型 | 说明 |
|---|---|---|
enabled |
boolean | 是否启用飞书频道 |
domain |
string | 飞书域名(feishu.cn 或 larksuite.com) |
connectionMode |
string | 连接模式 |
defaultAccount |
string | 默认账号 ID |
dmPolicy |
string | 私聊策略 |
groupPolicy |
string | 群聊策略 |
allowFrom |
string[] | 私聊白名单用户 ID 列表 |
groupAllowFrom |
string[] | 群聊白名单群组 ID 列表 |
requireMention |
boolean | 是否需要 @mention |
textChunkLimit |
number | 文本分块限制 |
mediaMaxMb |
number | 媒体文件最大大小(MB) |
streaming |
boolean | 是否启用流式输出 |
typingIndicator |
boolean | 是否显示"正在输入"状态 |
resolveSenderNames |
boolean | 是否解析发送者名称 |
账号配置 (accounts.<id>)
| 参数 | 类型 | 说明 |
|---|---|---|
appId |
string | 飞书应用 App ID |
appSecret |
string | 飞书应用 App Secret |
name |
string | 账号显示名称 |
domain |
string | 覆盖顶层域名 |
typingIndicator |
boolean | 覆盖顶层配置 |
resolveSenderNames |
boolean | 覆盖顶层配置 |
群组配置 (groups.<chat_id>)
| 参数 | 类型 | 说明 |
|---|---|---|
requireMention |
boolean | 覆盖顶层配置 |
enabled |
boolean | 是否启用该群 |
allowFrom |
string[] | 允许在该群发送消息的用户 ID |
tools |
string[] | 限制群组可用的工具 |
toolsBySender |
object | 按发送者限制工具 |
五、消息路由与会话
-
私聊 :使用主会话
agent:<agentId>:main -
群聊 :使用独立会话
agent:<agentId>:feishu:group:<chat_id> -
群组话题 :每个话题有独立会话(当
reply_in_thread时)
六、获取 ID 的方法
1. 群组 ID (oc_xxx)
-
在群中 @mention 机器人
-
运行
openclaw logs --follow查看日志中的chat_id
2. 用户 ID (ou_xxx)
-
用户私信机器人
-
运行
openclaw logs --follow查看日志中的open_id -
或运行
openclaw pairing list feishu
总结
通过以上配置,你可以灵活控制 OpenClaw 飞书机器人在私聊和群聊中的行为,从严格的配对审批到完全开放,再到精细化的群组权限管理,满足不同场景下的安全和使用需求。结合获取 ID 的方法,可以快速定位和配置目标用户或群组。
希望本文能帮助你更好地使用 OpenClaw 与飞书集成。如有疑问,欢迎在评论区交流!