Feishu Skill - AI Tool Extension for Feishu API
A progressively extensible skill designed for AI tools to leverage Feishu capabilities. The core philosophy is implement only what you need, when you need it.
⚠️ CRITICAL: After Creating New Scripts
You MUST update scripts/script_index.json immediately after creating any new script.
Failure to update the index will cause:
- - Future AI lookup cannot find the newly created script
- Duplicate implementation of the same functionality
- Confusion for other AI tools using this skill
Action required: Add an entry to scripts/script_index.json with fields: name, description, usage_hint, added_date, INLINECODE6
Design Philosophy
This skill is designed specifically for AI tools, not for human manual use.
When an AI tool receives a task involving Feishu:
- 1. Check existing scripts first - Search
scripts/script_index.json for already-implemented APIs - Implement only if needed - If no match exists, use Context7 to query Feishu OpenAPI documentation
- Add to index - Once implemented, update the index to avoid future re-implementation
This approach ensures:
- - No wasted effort - Only implement APIs when actually needed
- Progressive expansion - The skill grows based on real usage patterns
- Efficient lookup - AI tools can quickly find what's already available
Quick Start
This skill works out of the box once authentication is configured:
CODEBLOCK0
AI Workflow
Decision Logic
When AI encounters a Feishu-related task, follow this decision tree:
Step 1: Check index file
CODEBLOCK1
If match found:
- - Run
python3 script.py --help to understand parameters - Execute the script
- Return result
If NO match found:
- - Use Context7 to query Feishu API documentation:
Library: open.feishu.cn / larksuite
Query: "[specific requirement, e.g., 如何获取群组成员列表]"
- - Implement new Python script based on documentation
- Execute and test
- IMPORTANT: Update
scripts/script_index.json to add the new script
If execution fails:
- - Check API error messages
- Use Context7 or
references/doc_urls.txt to consult documentation - Fix the script
- Re-test
Critical Decision Points
When deciding between "use existing" vs "implement new", consider:
- - Is there a semantic match? Even if parameter names differ, if the functionality is equivalent, use existing script
- What's the cost of implementing? Simple single-call APIs → implement immediately. Complex multi-call workflows → consider reusing existing scripts
- Can this compose from existing scripts? Sometimes new features can be achieved by combining multiple existing scripts
Technical Reference
Script Index Format
INLINECODE11 structure:
CODEBLOCK3
Key fields for AI search:
- -
description: Human-readable explanation of functionality - INLINECODE13 : Array of keywords for matching (prioritize these for fuzzy matching)
Authentication
Configuration file: INLINECODE14
CODEBLOCK4
To obtain credentials:
- 1. Login to Feishu Open Platform
- Create or select an application
- Get App ID and App Secret from application details
Token management: get_token.py handles token lifecycle:
- - Automatic caching during validity period
- Auto-refresh 5 minutes before expiration
- Cache file: INLINECODE16
Script Template
When implementing new APIs, use this template:
CODEBLOCK5
Development standards:
- 1. ⚠️ CRITICAL: After creating any new script, you MUST update
scripts/script_index.json immediately - Complete docstring with Usage, Parameters, Options, Output sections
- Support
--help parameter - Use
get_token.py for authentication - Output standard JSON format
- Proper error handling with friendly messages
📋 New Script Creation Checklist
When implementing a new API, you MUST complete ALL steps:
- - [ ] Query Context7 for API documentation
- [ ] Create the Python script following the template
- [ ] Test the script execution (verify it returns correct JSON)
- [ ] ⚠️ UPDATE
scripts/script_index.json ← Don't forget this! - [ ] Save the API documentation URL to INLINECODE21
Using Context7 for Feishu API
When implementing new APIs, query Feishu documentation via Context7:
CODEBLOCK6
Why Context7?
- - Provides up-to-date API documentation
- Includes code examples and parameters
- Faster than searching the web manually
- Reduces trial-and-error
Examples
AI Task Example 1: Get Group Members
User request: "Get the member list for group oc_xxxxxxxxxxxxx"
AI decision process:
- 1. Search
scripts/script_index.json → Found match: INLINECODE23 - Execute: INLINECODE24
- Return result
AI Task Example 2: Add New API Capability
User request: "Delete a message from the group"
AI decision process:
- 1. Search
scripts/script_index.json → No match - Context7 query: "飞书删除消息 API"
- Get documentation showing
message/delete endpoint - Implement
delete_message.py script - Test execution
- ⛔ CRITICAL STEP: Update
scripts/script_index.json with new entry - DO NOT skip this! - Return result
Why step 6 is critical:
- - If you skip it, next AI will NOT find
delete_message.py in the index - This causes duplicate work: same functionality will be re-implemented
- The progressive expansion philosophy breaks down
References
飞书技能 - 面向飞书API的AI工具扩展
一个渐进式可扩展技能,专为AI工具利用飞书能力而设计。核心理念是按需实现,需要时才实现。
⚠️ 关键提示:创建新脚本后
创建任何新脚本后,必须立即更新 scripts/script_index.json。
未更新索引将导致:
- - 未来AI查找无法找到新创建的脚本
- 相同功能的重复实现
- 使用此技能的其他AI工具产生混淆
必要操作: 在 scripts/scriptindex.json 中添加条目,包含字段:name、description、usagehint、added_date、tags
设计理念
本技能专为AI工具设计,而非供人工手动使用。
当AI工具收到涉及飞书的任务时:
- 1. 首先检查现有脚本 - 搜索 scripts/script_index.json 查找已实现的API
- 仅在需要时实现 - 若无匹配项,使用Context7查询飞书OpenAPI文档
- 添加到索引 - 实现后更新索引,避免将来重复实现
此方法确保:
- - 无浪费 - 仅在真正需要时实现API
- 渐进式扩展 - 技能基于实际使用模式增长
- 高效查找 - AI工具可快速找到已有功能
快速开始
配置认证后,此技能即可直接使用:
bash
配置认证(一次性设置)
cd scripts/env
echo {app
id: yourapp
id, appsecret: your
appsecret} > app.json
AI工作流程
决策逻辑
当AI遇到飞书相关任务时,遵循以下决策树:
步骤1:检查索引文件
读取 scripts/script_index.json
按以下条件搜索:description、tags
如果找到匹配项:
- - 运行 python3 script.py --help 了解参数
- 执行脚本
- 返回结果
如果未找到匹配项:
库:open.feishu.cn / larksuite
查询:[具体需求,例如:如何获取群组成员列表]
- - 基于文档实现新的Python脚本
- 执行并测试
- 重要: 更新 scripts/script_index.json 添加新脚本
如果执行失败:
- - 检查API错误信息
- 使用Context7或 references/doc_urls.txt 查阅文档
- 修复脚本
- 重新测试
关键决策点
在使用现有与实现新功能之间做决定时,考虑:
- - 是否存在语义匹配? 即使参数名称不同,若功能等价,则使用现有脚本
- 实现成本如何? 简单的单次调用API → 立即实现。复杂的多步调用工作流 → 考虑复用现有脚本
- 能否通过组合现有脚本实现? 有时新功能可通过组合多个现有脚本实现
技术参考
脚本索引格式
scripts/script_index.json 结构:
json
{
version: 1.0,
last_updated: 2026-02-12T12:00:00Z,
scripts: [
{
name: getgroupmembers,
description: 获取指定群组的人员列表,
usagehint: python3 getgroupmembers.py chat_id>,
added_date: 2026-02-12,
tags: [group, member, user]
}
]
}
AI搜索的关键字段:
- - description:功能的人类可读说明
- tags:用于匹配的关键词数组(优先用于模糊匹配)
认证
配置文件: scripts/env/app.json
json
{
appid: clixxxxxxxxxxxxxxxx,
app_secret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
}
获取凭证:
- 1. 登录飞书开放平台
- 创建或选择应用
- 从应用详情获取App ID和App Secret
令牌管理: get_token.py 处理令牌生命周期:
- - 有效期内自动缓存
- 过期前5分钟自动刷新
- 缓存文件:scripts/env/token_cache.json
脚本模板
实现新API时,使用此模板:
python
#!/usr/bin/env python3
[完整功能描述]
用法:
python3 script.py [选项]
参数:
param1:参数描述
param2:参数描述
选项:
--page-size:分页大小(默认:20)
--page-token:分页令牌
输出:
JSON格式输出:
{
code: 0,
msg: success,
data: { ... }
}
参考:
飞书API:https://open.feishu.cn/document/...
import sys
import json
import subprocess
from pathlib import Path
import requests
配置
TOKEN
SCRIPT = Path(file).parent / gettoken.py
BASE_URL = https://open.feishu.cn
def get_token():
获取飞书访问令牌
result = subprocess.run(
[sys.executable, str(TOKEN_SCRIPT)],
capture_output=True,
text=True,
check=True
)
return result.stdout.strip()
def api_function(param1, param2, token, kwargs):
API调用函数
headers = {Authorization: fBearer {token}}
# ... 实现API调用
pass
def main():
# 处理 --help
if --help in sys.argv or -h in sys.argv:
print(doc)
return
# 解析必需参数
if len(sys.argv) < 3:
print(doc, file=sys.stderr)
sys.exit(1)
param1 = sys.argv[1]
param2 = sys.argv[2]
kwargs = {}
# 解析可选参数
for i in range(3, len(sys.argv)):
if sys.argv[i].startswith(--):
key = sys.argv[i][2:].replace(-, _)
i += 1
if i < len(sys.argv):
kwargs[key] = sys.argv[i]
# 获取令牌
token = get_token()
# 调用API
result = api_function(param1, param2, token, kwargs)
# 输出JSON
print(json.dumps(result, indent=2, ensure_ascii=False))
if name == main:
main()
开发标准:
- 1. ⚠️ 关键提示: 创建任何新脚本后,必须立即更新 scripts/scriptindex.json
- 完整的文档字符串,包含用法、参数、选项、输出部分
- 支持 --help 参数
- 使用 gettoken.py 进行认证
- 输出标准JSON格式
- 适当的错误处理,包含友好提示
📋 新脚本创建检查清单
实现新API时,必须完成所有步骤:
- - [ ] 使用Context7查询API文档
- [ ] 按照模板创建Python脚本
- [ ] 测试脚本执行(验证返回正确的JSON)
- [ ] ⚠️ 更新 scripts/scriptindex.json ← 不要忘记!
- [ ] 将API文档URL保存到 references/docurls.txt
使用Context7查询飞书API
实现新API时,通过Context7查询飞书文档:
库ID:open.feishu.cn / larksuite
查询示例:
- - 如何获取群组成员列表
- 发送消息到飞书群组的 API 使用方法
- 飞书文档操作的 OpenAPI
为什么使用Context7?
- - 提供最新的API文档
- 包含代码示例和参数
- 比手动搜索网页更快
- 减少试错成本
示例
AI任务示例1:获取群组成员
用户请求: 获取群组 oc_xxxxxxxxxxxxx 的成员列表
AI决策过程:
- 1. 搜索 scripts/scriptindex.json → 找到匹配项:getgroupmembers
- 执行:python3 scripts/getgroupmembers.py ocxxxxxxxxxxxxx
- 返回结果
AI任务示例2:添加新API功能
用户请求: 删除群组中的一条消息
AI决策过程:
- 1. 搜索 scripts/scriptindex.json → 无匹配项
- Context7查询:飞书删除消息 API
- 获取文档,显示 message/delete 端点
- 实现 deletemessage.py 脚本
- 测试执行
- ⛔ 关键步骤:更新 scripts/script_index.json 添加新条目 - 不要跳过此步骤!
- 返回结果
为什么步骤6至关重要:
-