auto-sync: lark_bitable_operate_as_bot 2026-04-03_18:06
This commit is contained in:
commit
1196666539
54
SKILL.md
Normal file
54
SKILL.md
Normal file
@ -0,0 +1,54 @@
|
||||
---
|
||||
name: lark_bitable_operate_as_bot
|
||||
version: 1.0.0
|
||||
description: "飞书多维表格Bot身份操作专用技能,统一使用Bot身份读取、编辑多维表格记录,禁止触发用户身份授权"
|
||||
metadata:
|
||||
requires:
|
||||
permissions: ["bitable:app", "base:record:retrieve", "base:record:create", "base:record:update", "base:record:delete"]
|
||||
---
|
||||
# lark_bitable_operate_as_bot 技能规范
|
||||
## 核心规则(强制执行)
|
||||
1. **身份限制**:所有多维表格操作**永远使用Bot身份**执行,绝对不触发任何用户身份授权弹窗
|
||||
2. **权限告知规则**:
|
||||
- Bot无权限访问目标多维表格:回复「当前Bot无访问该多维表格权限,请将Bot应用(App ID: `cli_a931175d41799cc7`)添加为多维表格协作者并授予对应权限后重试」
|
||||
- 权限不足时提示需要开通的权限:`bitable:app`、`base:record:retrieve`、`base:record:create`等
|
||||
## 支持操作
|
||||
- ✅ 读取多维表格记录
|
||||
- ✅ 新增单条/多条记录
|
||||
- ✅ 更新已有记录
|
||||
- ✅ 删除记录
|
||||
- ✅ 列出多维表格所有数据表
|
||||
## 参数说明
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| action | string | 是 | 操作类型:`list_tables`/`list_records`/`create_record`/`update_record`/`delete_record` |
|
||||
| app_token | string | 是 | 多维表格app_token,从链接中提取 |
|
||||
| table_id | string | 否 | 数据表ID,`list_tables`时不需要,其他操作必填 |
|
||||
| record_id | string | 否 | 记录ID,`update_record`/`delete_record`时必填 |
|
||||
| fields | object | 否 | 记录字段内容,`create_record`/`update_record`时必填 |
|
||||
| page_size | number | 否 | 读取记录数量,默认50,最大500 |
|
||||
## 使用示例
|
||||
### 1. 列出多维表格所有数据表
|
||||
```bash
|
||||
./skills/lark_bitable_operate_as_bot/scripts/operate_bitable.sh list_tables <app_token>
|
||||
```
|
||||
### 2. 读取数据表记录
|
||||
```bash
|
||||
./skills/lark_bitable_operate_as_bot/scripts/operate_bitable.sh list_records <app_token> <table_id> [page_size]
|
||||
```
|
||||
### 3. 新增记录
|
||||
```bash
|
||||
./skills/lark_bitable_operate_as_bot/scripts/operate_bitable.sh create_record <app_token> <table_id> '{"字段名1":"值1","字段名2":"值2"}'
|
||||
```
|
||||
### 4. 更新记录
|
||||
```bash
|
||||
./skills/lark_bitable_operate_as_bot/scripts/operate_bitable.sh update_record <app_token> <table_id> <record_id> '{"字段名1":"新值"}'
|
||||
```
|
||||
### 5. 删除记录
|
||||
```bash
|
||||
./skills/lark_bitable_operate_as_bot/scripts/operate_bitable.sh delete_record <app_token> <table_id> <record_id>
|
||||
```
|
||||
## 完整执行流程
|
||||
1. 自动获取Bot租户访问凭证(有效期2小时,自动复用)
|
||||
2. 调用对应飞书OpenAPI执行操作
|
||||
3. 处理返回结果,结构化输出给用户
|
||||
72
scripts/operate_bitable.sh
Executable file
72
scripts/operate_bitable.sh
Executable file
@ -0,0 +1,72 @@
|
||||
#!/bin/bash
|
||||
# 飞书多维表格Bot操作脚本
|
||||
ACTION="$1"
|
||||
APP_TOKEN="$2"
|
||||
TABLE_ID="$3"
|
||||
RECORD_ID="$4"
|
||||
FIELDS="$5"
|
||||
PAGE_SIZE="${5:-50}"
|
||||
CRED_FILE="/root/.openclaw/credentials/xiaoyan/config.json"
|
||||
APP_ID=$(jq -r '.apps[0].appId' "$CRED_FILE")
|
||||
APP_SECRET=$(jq -r '.apps[0].appSecret' "$CRED_FILE")
|
||||
# 获取tenant_access_token
|
||||
get_token() {
|
||||
TOKEN=$(curl -s -X POST "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"app_id\":\"$APP_ID\",\"app_secret\":\"$APP_SECRET\"}" \
|
||||
| jq -r '.tenant_access_token')
|
||||
echo "$TOKEN"
|
||||
}
|
||||
TOKEN=$(get_token)
|
||||
case "$ACTION" in
|
||||
list_tables)
|
||||
if [ -z "$APP_TOKEN" ]; then
|
||||
echo "参数错误:请传入app_token"
|
||||
exit 1
|
||||
fi
|
||||
curl -s -X GET "https://open.feishu.cn/open-apis/bitable/v1/apps/$APP_TOKEN/tables" \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
;;
|
||||
list_records)
|
||||
if [ -z "$APP_TOKEN" ] || [ -z "$TABLE_ID" ]; then
|
||||
echo "参数错误:请传入app_token和table_id"
|
||||
exit 1
|
||||
fi
|
||||
curl -s -X GET "https://open.feishu.cn/open-apis/bitable/v1/apps/$APP_TOKEN/tables/$TABLE_ID/records?page_size=$PAGE_SIZE" \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
;;
|
||||
create_record)
|
||||
if [ -z "$APP_TOKEN" ] || [ -z "$TABLE_ID" ] || [ -z "$4" ]; then
|
||||
echo "参数错误:请传入app_token、table_id和fields JSON"
|
||||
exit 1
|
||||
fi
|
||||
FIELDS="$4"
|
||||
curl -s -X POST "https://open.feishu.cn/open-apis/bitable/v1/apps/$APP_TOKEN/tables/$TABLE_ID/records" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"fields\":$FIELDS}"
|
||||
;;
|
||||
update_record)
|
||||
if [ -z "$APP_TOKEN" ] || [ -z "$TABLE_ID" ] || [ -z "$RECORD_ID" ] || [ -z "$5" ]; then
|
||||
echo "参数错误:请传入app_token、table_id、record_id和fields JSON"
|
||||
exit 1
|
||||
fi
|
||||
FIELDS="$5"
|
||||
curl -s -X PUT "https://open.feishu.cn/open-apis/bitable/v1/apps/$APP_TOKEN/tables/$TABLE_ID/records/$RECORD_ID" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"fields\":$FIELDS}"
|
||||
;;
|
||||
delete_record)
|
||||
if [ -z "$APP_TOKEN" ] || [ -z "$TABLE_ID" ] || [ -z "$RECORD_ID" ]; then
|
||||
echo "参数错误:请传入app_token、table_id和record_id"
|
||||
exit 1
|
||||
fi
|
||||
curl -s -X DELETE "https://open.feishu.cn/open-apis/bitable/v1/apps/$APP_TOKEN/tables/$TABLE_ID/records/$RECORD_ID" \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
;;
|
||||
*)
|
||||
echo "支持的操作:list_tables / list_records / create_record / update_record / delete_record"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
Loading…
Reference in New Issue
Block a user