Skip to content

Commit 80837dd

Browse files
LBP97541135c121914yuPeter-FrontEndFinleyGexqvvu
committed
add WeCom Smart Sheet toolset (labring#329)
* feat: add WeCom Smart Sheet toolset * perf: init tool (labring#319) * add gpt5.2 * perf: init tool * perf: init tool * perf: init tool * rename gpt 5.2 * rename gpt 5.2 * rename gpt 5.2 * add init batch (labring#320) * add gpt5.2 * add init * remove invalid code * Add gemini3 model (labring#323) * add gpt5.2 * remove invalid code * gemini3 * perf: mongo and redis reconnect (labring#325) * perf: mongo and redis reconnect * perf: mongo and redis reconnect * perf: redis * feat:markdownTransform tool indent&ordered&indent (labring#322) * feat:markdownTransform tool indent&ordered&indent * chore: add version description --------- Co-authored-by: Finley Ge <finleyge@fastgpt.io> * fix: oracle db operation (labring#326) * Revert "fix: oracle db operation (labring#326)" (labring#327) This reverts commit 21ec59a. * update model provider (labring#328) * feat: wecom corp token tool (labring#330) * feat: get wecom corp id tool * feat: update wecomCorpId readme * chore: restore the index.ts file to template raw * chore: update wecom logo * fix: remove wecom corpId tool secret input * fix: remove useless params for get wecom auth token --------- Co-authored-by: Archer <545436317@qq.com> Co-authored-by: Peter-FrontEnd <74163300+Peter-FrontEnd@users.noreply.github.com> Co-authored-by: Finley Ge <finleyge@fastgpt.io> Co-authored-by: Roy <whoeverimf5@gmail.com> Co-authored-by: Finley Ge <32237950+FinleyGe@users.noreply.github.com>
1 parent e402277 commit 80837dd

File tree

30 files changed

+1613
-32
lines changed

30 files changed

+1613
-32
lines changed

lib/invoke/wecom/getAuthToken.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import { FastGPTBaseURL } from '../const';
55
import { getAccessToken } from '../accessToken';
66

77
// 参数校验
8-
const getCorpTokenParamsSchema = z.object({
9-
corpId: z.string().min(1, 'corpId is required')
10-
});
8+
const getCorpTokenParamsSchema = z.object({});
119

1210
type getCorpTokenParams = z.infer<typeof getCorpTokenParamsSchema>;
1311

@@ -38,10 +36,7 @@ async function getCorpToken(
3836
headers: {
3937
'content-type': 'application/json',
4038
authorization: `Bearer ${access_token}`
41-
},
42-
body: JSON.stringify({
43-
corpId: validated.corpId
44-
})
39+
}
4540
});
4641

4742
if (!response.ok) {

modules/tool/packages/wecomCorpId/config.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import { defineTool } from '@tool/type';
2-
import {
3-
FlowNodeInputTypeEnum,
4-
FlowNodeOutputTypeEnum,
5-
WorkflowIOValueTypeEnum
6-
} from '@tool/type/fastgpt';
2+
import { WorkflowIOValueTypeEnum } from '@tool/type/fastgpt';
73
import { ToolTagEnum } from '@tool/type/tags';
84

95
export default defineTool({
@@ -18,7 +14,6 @@ export default defineTool({
1814
},
1915
toolDescription:
2016
'Get WeChat Work (WeCom) authorization token by corpId. Returns access_token and expires_in.',
21-
secretInputConfig: [],
2217
versionList: [
2318
{
2419
value: '0.1.0',
Lines changed: 6 additions & 19 deletions
Loading
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# 企业微信智能表插件 (WeCom Smart Sheet Plugin)
2+
3+
这是一个功能强大的企业微信智能表管理工具集,专为 FastGPT 设计。它支持从文档创建到子表、视图、字段及记录的全生命周期管理,并提供了“极简”与“高级”两种模式以适应不同的使用场景。
4+
5+
## 核心工具分类
6+
7+
### 1. 文档与结构管理
8+
- **新增智能表 (wecomSmartSheetDoc)**: 在指定空间创建新的智能表格文档。
9+
- **智能表子表管理 (wecomSmartSheetTable)**: 管理文档内的子表,支持新增、删除、更新和获取子表信息。
10+
- **智能表视图管理 (wecomSmartSheetView)**: 支持对子表视图进行增删改查,涵盖表格、看板、画册等多种视图类型。
11+
12+
### 2. 字段管理 (Fields)
13+
- **极简版字段 (wecomSmartSheetFieldSimple)**:
14+
- **特点**: 通过下拉选项和简单输入即可创建字段。
15+
- **自动化**: 自动处理不同字段类型的底层 JSON 结构(如日期、评分等默认配置)。
16+
- **高级版字段 (wecomSmartSheetFieldAdvanced)**:
17+
- **特点**: 支持直接输入 JSON 配置。
18+
- **场景**: 适合需要精细控制字段属性(如特定校验规则、复杂引用等)的高级用户。
19+
20+
### 3. 记录管理 (Records)
21+
- **极简版记录 (wecomSmartSheetRecordSimple)**:
22+
- **特点**: 支持直接传入键值对(Field Title: Value)。
23+
- **自动化**: 自动查询字段类型并进行必要的数据转换(如文本、链接等)。
24+
- **高级版记录 (wecomSmartSheetRecordAdvanced)**:
25+
- **特点**: 支持企微原生的记录 JSON 格式。
26+
- **场景**: 适合批量操作或需要精确控制单元格格式的场景。
27+
28+
## 配置说明
29+
30+
本工具集已优化为**无需手动激活**。您只需要在工作流中提供以下参数:
31+
32+
1. **accessToken**: 企业微信的调用凭证。
33+
2. **docid**: 目标智能表的文档 ID(部分创建工具除外)。
34+
3. **sheet_id**: 目标子表的 ID。
35+
36+
## 快速开始
37+
38+
1. **创建文档**: 使用 `wecomSmartSheetDoc` 创建一个新表。
39+
2. **管理结构**: 使用 `wecomSmartSheetTable``wecomSmartSheetView` 构建您的数据模型。
40+
3. **配置字段**: 推荐初学者使用 `wecomSmartSheetFieldSimple` 快速添加字段。
41+
4. **操作数据**: 使用 `wecomSmartSheetRecordSimple` 进行日常的数据录入和查询。
42+
43+
## API 参考
44+
45+
本插件基于企业微信官方 API 构建:
46+
- [智能表概览](https://developer.work.weixin.qq.com/document/path/96601)
47+
- [新增文档 API](https://developer.work.weixin.qq.com/document/path/97464)
48+
- [视图管理 API](https://developer.work.weixin.qq.com/document/path/100199)
49+
50+
---
51+
*由 FastGPT 团队维护*
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { defineTool } from '@tool/type';
2+
import { FlowNodeInputTypeEnum, WorkflowIOValueTypeEnum } from '@tool/type/fastgpt';
3+
4+
export default defineTool({
5+
name: {
6+
'zh-CN': '新增智能表',
7+
en: 'Create Smart Sheet'
8+
},
9+
description: {
10+
'zh-CN': '管理企微智能表文档,支持新建智能表。',
11+
en: 'Manage WeCom Smart Sheet documents, supporting the creation of new smart sheets.'
12+
},
13+
toolDescription: 'Create a new WeCom Smart Sheet document.',
14+
15+
versionList: [
16+
{
17+
value: '0.1.0',
18+
description: 'Initial version',
19+
inputs: [
20+
{
21+
key: 'accessToken',
22+
label: '调用凭证 (access_token)',
23+
description: '企业微信的调用凭证',
24+
required: true,
25+
valueType: WorkflowIOValueTypeEnum.string,
26+
renderTypeList: [FlowNodeInputTypeEnum.input, FlowNodeInputTypeEnum.reference],
27+
toolDescription: 'The access token for WeCom API'
28+
},
29+
{
30+
key: 'doc_name',
31+
label: '文档名称',
32+
description: '要新建的文档名称',
33+
required: true,
34+
valueType: WorkflowIOValueTypeEnum.string,
35+
renderTypeList: [FlowNodeInputTypeEnum.input, FlowNodeInputTypeEnum.reference],
36+
toolDescription: 'The name of the document to create'
37+
},
38+
{
39+
key: 'spaceid',
40+
label: '空间 ID (spaceid)',
41+
description: '可选,指定存储的空间 ID',
42+
required: false,
43+
valueType: WorkflowIOValueTypeEnum.string,
44+
renderTypeList: [FlowNodeInputTypeEnum.input, FlowNodeInputTypeEnum.reference],
45+
toolDescription: 'Optional space ID where the document will be created'
46+
},
47+
{
48+
key: 'fatherid',
49+
label: '父目录 ID (fatherid)',
50+
description: '可选,父目录 fileid,根目录时为空间 spaceid',
51+
required: false,
52+
valueType: WorkflowIOValueTypeEnum.string,
53+
renderTypeList: [FlowNodeInputTypeEnum.input, FlowNodeInputTypeEnum.reference],
54+
toolDescription: 'Optional father directory ID'
55+
},
56+
{
57+
key: 'admin_users',
58+
label: '管理员列表',
59+
description: '可选,文档管理员的 userid 列表,多个用逗号隔开',
60+
required: false,
61+
valueType: WorkflowIOValueTypeEnum.string,
62+
renderTypeList: [FlowNodeInputTypeEnum.input, FlowNodeInputTypeEnum.reference],
63+
toolDescription:
64+
'Optional list of user IDs for document administrators, separated by commas'
65+
}
66+
],
67+
outputs: [
68+
{
69+
key: 'docid',
70+
label: '文档 ID',
71+
description: '新建文档的唯一标识',
72+
valueType: WorkflowIOValueTypeEnum.string
73+
},
74+
{
75+
key: 'url',
76+
label: '文档链接',
77+
description: '新建文档的访问链接',
78+
valueType: WorkflowIOValueTypeEnum.string
79+
}
80+
]
81+
}
82+
]
83+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import config from './config';
2+
import { InputType, OutputType, tool as toolCb } from './src';
3+
import { exportTool } from '@tool/utils/tool';
4+
5+
export default exportTool({
6+
toolCb,
7+
InputType,
8+
OutputType,
9+
config
10+
});
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { z } from 'zod';
2+
import axios from 'axios';
3+
4+
export const InputType = z.object({
5+
accessToken: z.string(),
6+
doc_name: z.string(),
7+
spaceid: z.string().optional().nullable(),
8+
fatherid: z.string().optional().nullable(),
9+
admin_users: z.string().optional().nullable()
10+
});
11+
12+
export const OutputType = z.object({
13+
docid: z.string().optional(),
14+
url: z.string().optional(),
15+
result: z.any().optional()
16+
});
17+
18+
const WECOM_API_BASE = 'https://qyapi.weixin.qq.com/cgi-bin';
19+
20+
export async function tool(props: z.infer<typeof InputType>): Promise<z.infer<typeof OutputType>> {
21+
const { accessToken, doc_name, spaceid, fatherid, admin_users } = props;
22+
23+
const client = axios.create({
24+
baseURL: WECOM_API_BASE,
25+
params: { access_token: accessToken }
26+
});
27+
28+
const response = await client.post('/wedoc/smartsheet/create_doc', {
29+
doc_name,
30+
doc_type: 10, // 10: 智能表格
31+
spaceid: spaceid || undefined,
32+
fatherid: fatherid || undefined,
33+
admin_users: admin_users
34+
? admin_users
35+
.split(',')
36+
.filter(Boolean)
37+
.map((u) => u.trim())
38+
: undefined
39+
});
40+
41+
const data = response.data;
42+
if (data.errcode !== 0) {
43+
throw new Error(`WeCom API error: ${data.errmsg} (${data.errcode})`);
44+
}
45+
46+
return {
47+
docid: data.docid,
48+
url: data.url,
49+
result: data
50+
};
51+
}

0 commit comments

Comments
 (0)