时间:2026-03-15 14:28
人气:
作者:admin
安装飞书插件:
npx -y @larksuite/openclaw-lark-tools install
进入应用的「事件订阅」页面,选择 Stream 模式(WebSocket 长连接)。
| 事件名称 | 用途 |
|---|---|
im.message.receive_v1 |
接收消息 |
im.message.reaction.created_v1 |
表情回应(可选) |
在「权限管理」中添加以下权限:
| 权限名称 | 说明 |
|---|---|
im:message |
获取与发送消息 |
im:message:send_as_bot |
以应用身份发消息 |
im:chat |
获取群组信息 |
im:chat:readonly |
读取群组信息 |
contact:user.base:readonly |
获取用户基础信息 |
配置完成后,创建版本并发布应用。
C:\Users\Administrator\.openclaw\openclaw.json
以下是完整的 openclaw.json 配置文件,重点关注 channels 和 plugins 部分:
{
"models": {
"mode": "merge",
"providers": {
"your-provider": {
"baseUrl": "https://your-api-endpoint/v1",
"apiKey": "your-api-key",
"api": "openai-completions",
"models": [
{
"id": "your-model-id",
"name": "your-model-name",
"reasoning": false,
"input": ["text"],
"cost": {
"input": 0,
"output": 0,
"cacheRead": 0,
"cacheWrite": 0
},
"contextWindow": 16000,
"maxTokens": 4096
}
]
}
}
},
"agents": {
"defaults": {
"model": {
"primary": "your-provider/your-model-id"
},
"workspace": "C:\\Users\\Administrator\\.openclaw\\workspace",
"compaction": {
"mode": "safeguard"
},
"maxConcurrent": 4,
"subagents": {
"maxConcurrent": 8
}
},
"list": [
{
"id": "main"
}
]
},
"tools": {
"profile": "full"
},
"messages": {
"ackReactionScope": "group-mentions"
},
"commands": {
"native": "auto",
"nativeSkills": "auto",
"restart": true,
"ownerDisplay": "raw"
},
"session": {
"dmScope": "per-channel-peer"
},
"channels": {
"feishu": {
"enabled": true,
"appId": "****",
"appSecret": "****",
"domain": "feishu",
"connectionMode": "websocket",
"dmPolicy": "open",
"allowFrom": ["*"],
"groupPolicy": "open",
"groupAllowFrom": ["*"],
"requireMention": true,
"typingIndicator": true,
"resolveSenderNames": true
}
},
"gateway": {
"port": 18789,
"mode": "local",
"bind": "loopback",
"auth": {
"mode": "token",
"token": "your-gateway-token"
},
"tailscale": {
"mode": "off",
"resetOnExit": false
},
"nodes": {
"denyCommands": [
"camera.snap",
"camera.clip",
"screen.record",
"contacts.add",
"calendar.add",
"reminders.add",
"sms.send"
]
}
},
"plugins": {
"entries": {
"feishu": {
"enabled": true
}
}
}
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
enabled |
boolean | 是 | 是否启用飞书通道。true 启用,false 禁用 |
appId |
string | 是 | 飞书应用的 App ID,在飞书开放平台「凭证与基础信息」页面获取。格式:cli_xxxxxxxx |
appSecret |
string | 是 | 飞书应用的 App Secret,在飞书开放平台「凭证与基础信息」页面获取。格式:32 位字符串 |
domain |
string | 否 | 飞书域名。取值:"feishu"(国内版,默认)、"lark"(国际版) |
connectionMode |
string | 否 | 连接模式。取值:"websocket"(默认,推荐)、"webhook"(需公网服务器) |
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
dmPolicy |
string | 否 | 私聊策略。取值:"open"(开放,任何人可私聊)、"pairing"(需配对确认)、"allowlist"(白名单模式)。默认:"pairing" |
allowFrom |
array | 否 | 允许私聊的用户列表。取值:["*"](允许所有人)、["ou_user1", "ou_user2"](指定用户的 open_id)。注意:dmPolicy: "open" 时必须包含 "*" |
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
groupPolicy |
string | 否 | 群聊策略。取值:"open"(开放,任何群可用)、"allowlist"(白名单模式)、"disabled"(禁用群聊)。默认:"allowlist" |
groupAllowFrom |
array | 否 | 允许的群聊列表。取值:["*"](允许所有群)、["oc_group1", "oc_group2"](指定群的 chat_id) |
requireMention |
boolean | 否 | 群聊是否需要 @机器人 才会响应。取值:true(需要 @)、false(所有消息都响应)。默认:true |
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
typingIndicator |
boolean | 否 | 是否显示「正在输入…」状态。取值:true(显示)、false(不显示)。默认:true |
resolveSenderNames |
boolean | 否 | 是否解析发送者名称。取值:true(解析,消息中会显示发送者名字)、false(不解析)。默认:true |
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
webhookHost |
string | 是* | Webhook 服务器域名,如 "example.com"。*仅 webhook 模式需要 |
webhookPort |
number | 否 | Webhook 服务器端口,如 443、8080 |
webhookPath |
string | 否 | Webhook 接收路径。默认:"/feishu/events" |
verificationToken |
string | 是* | 飞书事件订阅的验证令牌,在飞书开放平台获取。*仅 webhook 模式需要 |
| 信息 | 获取方式 |
|---|---|
appId / appSecret |
飞书开放平台 → 你的应用 → 凭证与基础信息 |
用户的 open_id |
让用户给机器人发消息,查看日志中的 open_id 字段;或通过飞书 API 获取 |
群聊的 chat_id |
将机器人加入群聊,查看日志中的 chat_id 字段;或在飞书群设置中查看 |
verificationToken |
飞书开放平台 → 你的应用 → 事件订阅 → 验证令牌 |
# 启动 OpenClaw Gateway
/c/Users/Administrator/.openclaw/gateway.cmd
启动成功后会看到以下日志:
[feishu] starting feishu[default] (mode: websocket)
[feishu] feishu[default]: bot open_id resolved: ou_xxxxxxxx
[feishu] feishu[default]: starting WebSocket connection...
# 查看实时日志
tail -f /tmp/openclaw/openclaw-$(date +%Y-%m-%d).log
# 查看完整日志
cat /tmp/openclaw/openclaw-$(date +%Y-%m-%d).log
直接在飞书中给机器人发送消息即可开始对话。
在群聊中需要 @机器人 才会触发回复(除非配置了 requireMention: false)。
以下示例均为完整的 openclaw.json 配置文件,请直接替换或参考修改。
只允许特定用户和群聊使用机器人:
{
"models": {
"mode": "merge",
"providers": {
"your-provider": {
"baseUrl": "https://your-api-endpoint/v1",
"apiKey": "your-api-key",
"api": "openai-completions",
"models": [
{
"id": "your-model-id",
"name": "your-model-name",
"reasoning": false,
"input": ["text"],
"cost": {
"input": 0,
"output": 0,
"cacheRead": 0,
"cacheWrite": 0
},
"contextWindow": 16000,
"maxTokens": 4096
}
]
}
}
},
"agents": {
"defaults": {
"model": { "primary": "your-provider/your-model-id" },
"workspace": "C:\\Users\\Administrator\\.openclaw\\workspace",
"compaction": { "mode": "safeguard" },
"maxConcurrent": 4,
"subagents": { "maxConcurrent": 8 }
},
"list": [{ "id": "main" }]
},
"tools": { "profile": "full" },
"messages": { "ackReactionScope": "group-mentions" },
"commands": {
"native": "auto",
"nativeSkills": "auto",
"restart": true,
"ownerDisplay": "raw"
},
"session": { "dmScope": "per-channel-peer" },
"channels": {
"feishu": {
"enabled": true,
"appId": "****",
"appSecret": "****",
"domain": "feishu",
"connectionMode": "websocket",
"dmPolicy": "allowlist",
"allowFrom": ["ou_user1", "ou_user2"],
"groupPolicy": "allowlist",
"groupAllowFrom": ["oc_group1"],
"requireMention": true,
"typingIndicator": true,
"resolveSenderNames": true
}
},
"gateway": {
"port": 18789,
"mode": "local",
"bind": "loopback",
"auth": { "mode": "token", "token": "your-gateway-token" },
"tailscale": { "mode": "off", "resetOnExit": false },
"nodes": {
"denyCommands": [
"camera.snap",
"camera.clip",
"screen.record",
"contacts.add",
"calendar.add",
"reminders.add",
"sms.send"
]
}
},
"plugins": {
"entries": { "feishu": { "enabled": true } }
}
}
字段说明:
dmPolicy: "allowlist" - 使用白名单模式限制私聊,只有 allowFrom 列表中的用户可以私聊allowFrom: ["ou_user1", "ou_user2"] - 允许私聊的用户 open_id 列表。ou_user1、ou_user2 需替换为实际的用户 open_idgroupPolicy: "allowlist" - 使用白名单模式限制群聊,只有 groupAllowFrom 列表中的群可以触发机器人groupAllowFrom: ["oc_group1"] - 允许的群聊 chat_id 列表。oc_group1 需替换为实际的群 chat_id一个 OpenClaw 实例管理多个飞书机器人:
{
"models": {
"mode": "merge",
"providers": {
"your-provider": {
"baseUrl": "https://your-api-endpoint/v1",
"apiKey": "your-api-key",
"api": "openai-completions",
"models": [
{
"id": "your-model-id",
"name": "your-model-name",
"reasoning": false,
"input": ["text"],
"cost": {
"input": 0,
"output": 0,
"cacheRead": 0,
"cacheWrite": 0
},
"contextWindow": 16000,
"maxTokens": 4096
}
]
}
}
},
"agents": {
"defaults": {
"model": { "primary": "your-provider/your-model-id" },
"workspace": "C:\\Users\\Administrator\\.openclaw\\workspace",
"compaction": { "mode": "safeguard" },
"maxConcurrent": 4,
"subagents": { "maxConcurrent": 8 }
},
"list": [{ "id": "main" }]
},
"tools": { "profile": "full" },
"messages": { "ackReactionScope": "group-mentions" },
"commands": {
"native": "auto",
"nativeSkills": "auto",
"restart": true,
"ownerDisplay": "raw"
},
"session": { "dmScope": "per-channel-peer" },
"channels": {
"feishu": {
"enabled": true,
"defaultAccount": "bot1",
"domain": "feishu",
"connectionMode": "websocket",
"dmPolicy": "open",
"allowFrom": ["*"],
"groupPolicy": "open",
"groupAllowFrom": ["*"],
"requireMention": true,
"typingIndicator": true,
"resolveSenderNames": true,
"accounts": {
"bot1": {
"name": "客服机器人",
"appId": "cli_xxx1",
"appSecret": "secret1"
},
"bot2": {
"name": "助手机器人",
"appId": "cli_xxx2",
"appSecret": "secret2"
}
}
}
},
"gateway": {
"port": 18789,
"mode": "local",
"bind": "loopback",
"auth": { "mode": "token", "token": "your-gateway-token" },
"tailscale": { "mode": "off", "resetOnExit": false },
"nodes": {
"denyCommands": [
"camera.snap",
"camera.clip",
"screen.record",
"contacts.add",
"calendar.add",
"reminders.add",
"sms.send"
]
}
},
"plugins": {
"entries": { "feishu": { "enabled": true } }
}
}
字段说明:
defaultAccount: "bot1" - 默认使用的机器人账号,当没有指定账号时使用此账号accounts - 多个机器人账号配置对象
bot1 / bot2 - 自定义的账号标识符,用于区分不同机器人name - 账号显示名称,方便识别,可选appId - 该机器人账号的 App ID,格式:cli_xxxxxxxxappSecret - 该机器人账号的 App Secret,32 位字符串为特定群聊设置不同的行为:
{
"models": {
"mode": "merge",
"providers": {
"your-provider": {
"baseUrl": "https://your-api-endpoint/v1",
"apiKey": "your-api-key",
"api": "openai-completions",
"models": [
{
"id": "your-model-id",
"name": "your-model-name",
"reasoning": false,
"input": ["text"],
"cost": {
"input": 0,
"output": 0,
"cacheRead": 0,
"cacheWrite": 0
},
"contextWindow": 16000,
"maxTokens": 4096
}
]
}
}
},
"agents": {
"defaults": {
"model": { "primary": "your-provider/your-model-id" },
"workspace": "C:\\Users\\Administrator\\.openclaw\\workspace",
"compaction": { "mode": "safeguard" },
"maxConcurrent": 4,
"subagents": { "maxConcurrent": 8 }
},
"list": [{ "id": "main" }]
},
"tools": { "profile": "full" },
"messages": { "ackReactionScope": "group-mentions" },
"commands": {
"native": "auto",
"nativeSkills": "auto",
"restart": true,
"ownerDisplay": "raw"
},
"session": { "dmScope": "per-channel-peer" },
"channels": {
"feishu": {
"enabled": true,
"appId": "****",
"appSecret": "****",
"domain": "feishu",
"connectionMode": "websocket",
"dmPolicy": "open",
"allowFrom": ["*"],
"groupPolicy": "open",
"groupAllowFrom": ["*"],
"requireMention": true,
"typingIndicator": true,
"resolveSenderNames": true,
"groups": {
"oc_xxxxxxxx": {
"enabled": true,
"requireMention": false,
"systemPrompt": "你是一个专业的客服助手,请用简洁专业的语言回答问题。"
},
"oc_yyyyyyyy": {
"enabled": true,
"requireMention": true,
"systemPrompt": "你是一个技术顾问,专注于解决编程和技术问题。"
}
}
}
},
"gateway": {
"port": 18789,
"mode": "local",
"bind": "loopback",
"auth": { "mode": "token", "token": "your-gateway-token" },
"tailscale": { "mode": "off", "resetOnExit": false },
"nodes": {
"denyCommands": [
"camera.snap",
"camera.clip",
"screen.record",
"contacts.add",
"calendar.add",
"reminders.add",
"sms.send"
]
}
},
"plugins": {
"entries": { "feishu": { "enabled": true } }
}
}
字段说明:
groups - 按群聊 ID 进行个性化配置的对象
oc_xxxxxxxx / oc_yyyyyyyy - 群聊的 chat_id,需要替换为实际的群 IDenabled - 是否在该群启用机器人,true 启用,false 禁用requireMention - 该群是否需要 @机器人。设置为 false 可覆盖全局设置,让机器人在该群响应所有消息systemPrompt - 该群使用的系统提示词,可让机器人在不同群扮演不同角色requireMention 配置如果需要将飞书机器人切换到另一个 OpenClaw 实例:
openclaw.json 中的飞书配置复制到新的 OpenClaw 实例# 设置配置文件路径
export OPENCLAW_CONFIG_PATH=/path/to/new/openclaw.json
# 启动 Gateway
/c/Users/Administrator/.openclaw/gateway.cmd
飞书 WebSocket 模式是单连接的,同一时间只能有一个客户端保持连接。如果多个 OpenClaw 实例尝试连接同一个飞书机器人:
只运行一个 OpenClaw Gateway 实例,通过配置文件管理多个机器人账号。参见上方「3.2 多账号支持」。
如果需要多实例部署,可以改用 Webhook 模式。
完整配置文件示例:
{
"models": {
"mode": "merge",
"providers": {
"your-provider": {
"baseUrl": "https://your-api-endpoint/v1",
"apiKey": "your-api-key",
"api": "openai-completions",
"models": [
{
"id": "your-model-id",
"name": "your-model-name",
"reasoning": false,
"input": ["text"],
"cost": {
"input": 0,
"output": 0,
"cacheRead": 0,
"cacheWrite": 0
},
"contextWindow": 16000,
"maxTokens": 4096
}
]
}
}
},
"agents": {
"defaults": {
"model": { "primary": "your-provider/your-model-id" },
"workspace": "C:\\Users\\Administrator\\.openclaw\\workspace",
"compaction": { "mode": "safeguard" },
"maxConcurrent": 4,
"subagents": { "maxConcurrent": 8 }
},
"list": [{ "id": "main" }]
},
"tools": { "profile": "full" },
"messages": { "ackReactionScope": "group-mentions" },
"commands": {
"native": "auto",
"nativeSkills": "auto",
"restart": true,
"ownerDisplay": "raw"
},
"session": { "dmScope": "per-channel-peer" },
"channels": {
"feishu": {
"enabled": true,
"appId": "****",
"appSecret": "****",
"domain": "feishu",
"connectionMode": "webhook",
"webhookHost": "your-domain.com",
"webhookPort": 443,
"webhookPath": "/feishu/events",
"verificationToken": "your_verification_token",
"dmPolicy": "open",
"allowFrom": ["*"],
"groupPolicy": "open",
"groupAllowFrom": ["*"],
"requireMention": true,
"typingIndicator": true,
"resolveSenderNames": true
}
},
"gateway": {
"port": 18789,
"mode": "local",
"bind": "loopback",
"auth": { "mode": "token", "token": "your-gateway-token" },
"tailscale": { "mode": "off", "resetOnExit": false },
"nodes": {
"denyCommands": [
"camera.snap",
"camera.clip",
"screen.record",
"contacts.add",
"calendar.add",
"reminders.add",
"sms.send"
]
}
},
"plugins": {
"entries": { "feishu": { "enabled": true } }
}
}
Webhook 模式需要:
https://your-domain.com/feishu/events使用消息队列(如 Redis、RabbitMQ)进行消息分发:
| 场景 | 推荐方案 |
|---|---|
| 单机器人、单租户 | 单实例 WebSocket |
| 多机器人、单租户 | 单实例多账号配置 |
| 单机器人、高可用 | 主备切换 + WebSocket |
| 高并发、多租户 | Webhook + 负载均衡 |