Feishu Group Manager
Quick Reference
| Operation | Command | Billed |
|---|
| Check permissions | INLINECODE0 | Free |
| Get access token |
get_token | Free |
| List all groups |
list_chats | Free |
| Find group by name |
find_chat --name | Free |
| List group members |
list_members --chat_id | Free |
| Search user by name |
find_user --name | Free |
| Add member to group |
add_member | 0.002 USDT |
| Remove member |
remove_member | 0.002 USDT |
| Send message |
send_message | 0.002 USDT |
| Rename group |
rename_chat | 0.002 USDT |
| Create group |
create_chat | 0.002 USDT |
When a write operation returns {"error": "payment_required", ...}: stop, show the message field to the user, and wait for them to top up before retrying.
First Use: Credential Check + Permission Verification
The user is already chatting via Feishu, so the app exists and credentials are configured. No need to ask them to set anything up.
Credentials are resolved automatically in this order:
- 1. Environment variables
FEISHU_APP_ID / INLINECODE14 - INLINECODE15 → INLINECODE16
On the first request of a session, run:
CODEBLOCK0
If all_ok: true — proceed directly.
If all_ok: false — show the user a friendly message listing missing permissions and how to grant them, e.g.:
"Before I can manage your groups, your Feishu app needs a couple of extra permissions (takes ~2 min).
Missing:
- -
im:chat.member — add/remove group members - INLINECODE20 — search members by name
Steps:
- 1. Open https://open.feishu.cn/app and find your app
- Go to Permission Management → search and enable the permissions above
- Go to Version Management → create a new version → submit for review
- Once approved (usually a few minutes), let me know and I'll continue."
Re-run check_permissions after the user confirms. Cache the result for the session — only re-check if the user says they just updated permissions, or if Feishu returns error code 99991672.
Execution Flow
Step 1 — Understand intent
Confirm briefly in the user's language, e.g.: "Got it, I'll add Zhang San to the Marketing group."
Step 2 — Gather info
python3 {baseDir}/scripts/feishu.py get_token
python3 {baseDir}/scripts/feishu.py find_chat --token TOKEN --name "marketing"
python3 {baseDir}/scripts/feishu.py find_user --token TOKEN --name "Zhang San"
If multiple matches are returned, list them and ask the user to confirm.
Step 3 — Confirm before any write
"I'm about to add Zhang San (Marketing dept.) to Marketing Group. Confirm?"
Wait for confirmation before executing.
Step 4 — Execute and report
Success: "Done! Zhang San has been added to Marketing Group."
Failure: Explain in plain language — never expose raw API errors.
Command Reference
CODEBLOCK2
INLINECODE23 is the caller's Feishu open_id — used for billing. Retrieve it from conversation context or from find_user results.
Error Handling
| Error | Response |
|---|
| Group not found | "I couldn't find a group called 'X'. Could you give me the full name?" |
| User not found |
"I couldn't find anyone called 'X'. Please check the name or provide their email." |
| Feishu error
99991672 | Re-run
check_permissions and show missing permission guidance |
| Token expired | Automatically re-call
get_token and retry |
| Network error | "There was a problem reaching Feishu. Please try again in a moment." |
|
payment_required | Show the
message field (includes top-up link), stop, wait for user |
飞书群组管理工具
快速参考
| 操作 | 命令 | 计费 |
|---|
| 检查权限 | checkpermissions | 免费 |
| 获取访问令牌 |
gettoken | 免费 |
| 列出所有群组 | list_chats | 免费 |
| 按名称查找群组 | find_chat --name | 免费 |
| 列出群组成员 | list
members --chatid | 免费 |
| 按名称搜索用户 | find_user --name | 免费 |
| 添加成员到群组 | add_member | 0.002 USDT |
| 移除成员 | remove_member | 0.002 USDT |
| 发送消息 | send_message | 0.002 USDT |
| 重命名群组 | rename_chat | 0.002 USDT |
| 创建群组 | create_chat | 0.002 USDT |
当写操作返回 {error: payment_required, ...} 时:停止操作,向用户显示 message 字段内容,等待用户充值后重试。
首次使用:凭证检查 + 权限验证
用户已通过飞书进行对话,因此应用已存在且凭证已配置。无需要求用户进行任何设置。
凭证按以下顺序自动解析:
- 1. 环境变量 FEISHUAPPID / FEISHUAPPSECRET
- ~/.openclaw/openclaw.json → channels.feishu.accounts..appId / appSecret
在会话的首次请求时,运行:
bash
python3 {baseDir}/scripts/feishu.py check_permissions
如果 all_ok: true — 直接继续。
如果 all_ok: false — 向用户显示友好提示,列出缺失的权限及如何授予,例如:
在我管理您的群组之前,您的飞书应用需要额外几个权限(大约需要2分钟)。
缺失的权限:
- - im:chat.member — 添加/移除群组成员
- contact:user.id:readonly — 按名称搜索成员
操作步骤:
- 1. 打开 https://open.feishu.cn/app 找到您的应用
- 进入权限管理 → 搜索并启用上述权限
- 进入版本管理 → 创建新版本 → 提交审核
- 审核通过后(通常几分钟),请告知我,我将继续操作。
在用户确认后重新运行 check_permissions。将结果缓存在会话中 — 仅在用户表示刚刚更新了权限,或飞书返回错误代码 99991672 时重新检查。
执行流程
第一步 — 理解意图
用用户的语言简要确认,例如:好的,我将把张三添加到市场部群组。
第二步 — 收集信息
bash
python3 {baseDir}/scripts/feishu.py get_token
python3 {baseDir}/scripts/feishu.py find_chat --token TOKEN --name 市场部
python3 {baseDir}/scripts/feishu.py find_user --token TOKEN --name 张三
如果返回多个匹配结果,列出并请用户确认。
第三步 — 执行任何写操作前确认
我将把张三(市场部)添加到市场部群组。确认吗?
在执行前等待用户确认。
第四步 — 执行并报告结果
成功:已完成!张三已添加到市场部群组。
失败:用通俗语言解释 — 绝不暴露原始API错误。
命令参考
bash
检查应用权限
python3 {baseDir}/scripts/feishu.py check_permissions
获取租户访问令牌(自动读取凭证)
python3 {baseDir}/scripts/feishu.py get_token
列出所有群组
python3 {baseDir}/scripts/feishu.py list_chats --token TOKEN
按名称查找群组(模糊匹配)
python3 {baseDir}/scripts/feishu.py find_chat --token TOKEN --name 名称
列出群组成员
python3 {baseDir}/scripts/feishu.py list
members --token TOKEN --chatid CHAT_ID
按名称搜索用户
python3 {baseDir}/scripts/feishu.py find_user --token TOKEN --name 名称
添加成员到群组(计费)
python3 {baseDir}/scripts/feishu.py add_member \
--token TOKEN --chat
id CHATID \
--target
userid TARGET
UID --userid CALLER_UID
从群组移除成员(计费)
python3 {baseDir}/scripts/feishu.py remove_member \
--token TOKEN --chat
id CHATID \
--target
userid TARGET
UID --userid CALLER_UID
向群组发送消息(计费)
python3 {baseDir}/scripts/feishu.py send_message \
--token TOKEN --chat
id CHATID --text 消息内容 --user
id CALLERUID
重命名群组(计费)
python3 {baseDir}/scripts/feishu.py rename_chat \
--token TOKEN --chat
id CHATID --name 新名称 --user
id CALLERUID
创建群组并添加成员(计费)
python3 {baseDir}/scripts/feishu.py create_chat \
--token TOKEN --name 群组名称 --user
ids uid1,uid2 --userid CALLER_UID
--userid 是调用者的飞书 openid — 用于计费。从对话上下文或 find_user 结果中获取。
错误处理
| 错误 | 响应 |
|---|
| 未找到群组 | 我找不到名为X的群组。您能提供完整名称吗? |
| 未找到用户 |
我找不到名为X的人。请检查姓名或提供其邮箱。 |
| 飞书错误 99991672 | 重新运行 check_permissions 并显示缺失权限指引 |
| 令牌过期 | 自动重新调用 get_token 并重试 |
| 网络错误 | 连接飞书时出现问题。请稍后重试。 |
| payment_required | 显示 message 字段(包含充值链接),停止操作,等待用户 |