forked from funcodingdev/n8n-nodes-wecom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeComOffice.node.ts
More file actions
222 lines (213 loc) · 7.26 KB
/
Copy pathWeComOffice.node.ts
File metadata and controls
222 lines (213 loc) · 7.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import type {
IExecuteFunctions,
ILoadOptionsFunctions,
INodeExecutionData,
INodePropertyOptions,
INodeType,
INodeTypeDescription,
} from 'n8n-workflow';
import { NodeConnectionTypes } from 'n8n-workflow';
import { weComApiRequest } from '../WeCom/shared/transport';
import { wedocDescription } from '../WeCom/resources/wedoc';
import { wefileDescription } from '../WeCom/resources/wefile';
import { mailDescription } from '../WeCom/resources/mail';
import { calendarDescription } from '../WeCom/resources/calendar';
import { meetingDescription } from '../WeCom/resources/meeting';
import { liveDescription } from '../WeCom/resources/live';
import { checkinDescription } from '../WeCom/resources/checkin';
import { approvalDescription } from '../WeCom/resources/approval';
import { journalDescription } from '../WeCom/resources/journal';
import { hrDescription } from '../WeCom/resources/hr';
import { meetingroomDescription } from '../WeCom/resources/meetingroom';
import { emergencyDescription } from '../WeCom/resources/emergency';
import { executeWedoc } from '../WeCom/resources/wedoc/execute';
import { executeWefile } from '../WeCom/resources/wefile/execute';
import { executeMail } from '../WeCom/resources/mail/execute';
import { executeCalendar } from '../WeCom/resources/calendar/execute';
import { executeMeeting } from '../WeCom/resources/meeting/execute';
import { executeLive } from '../WeCom/resources/live/execute';
import { executeCheckin } from '../WeCom/resources/checkin/execute';
import { executeApproval } from '../WeCom/resources/approval/execute';
import { executeJournal } from '../WeCom/resources/journal/execute';
import { executeHr } from '../WeCom/resources/hr/execute';
import { executeMeetingroom } from '../WeCom/resources/meetingroom/execute';
import { executeEmergency } from '../WeCom/resources/emergency/execute';
export class WeComOffice implements INodeType {
description: INodeTypeDescription = {
displayName: '企业微信-办公 (WeCom)',
name: 'weComOffice',
// eslint-disable-next-line @n8n/community-nodes/icon-validation
icon: { light: 'file:../../icons/wecom.png', dark: 'file:../../icons/wecom.dark.png' },
group: ['transform'],
version: 1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: '企业微信办公功能 - 文档、微盘、邮件、日程、会议、直播、打卡、审批、汇报、人事、会议室、紧急通知',
defaults: {
name: '企业微信-办公',
},
inputs: [NodeConnectionTypes.Main],
outputs: [NodeConnectionTypes.Main],
credentials: [
{
name: 'weComApi',
required: true,
},
],
requestDefaults: {
baseURL: 'https://qyapi.weixin.qq.com',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
},
properties: [
{
displayName: '资源',
name: 'resource',
type: 'options',
noDataExpression: true,
options: [
{
name: '文档',
value: 'wedoc',
description: '管理企业微信文档(在线文档、表格、智能表格)',
},
{
name: '微盘',
value: 'wefile',
description: '管理微盘空间和文件',
},
{
name: '邮件',
value: 'mail',
description: '管理企业邮箱(发送邮件、邮件群组、公共邮箱等)',
},
{
name: '会议',
value: 'meeting',
description: '管理企业微信会议(预约会议、会议控制、录制管理等)',
},
{
name: '直播',
value: 'live',
description: '管理企业微信直播(创建、修改、观看、统计等)',
},
{
name: '日程',
value: 'calendar',
description: '管理日历和日程(创建日历、创建日程、管理参与者等)',
},
{
name: '打卡',
value: 'checkin',
description: '管理打卡规则、打卡记录、排班等',
},
{
name: '审批',
value: 'approval',
description: '管理审批模板、审批申请、假期管理等',
},
{
name: '汇报',
value: 'journal',
description: '管理汇报记录、汇报统计等',
},
{
name: '人事助手',
value: 'hr',
description: '管理员工花名册信息',
},
{
name: '会议室',
value: 'meetingroom',
description: '管理会议室和会议室预定',
},
{
name: '紧急通知',
value: 'emergency',
description: '发起语音电话等紧急通知',
},
],
default: 'wedoc',
},
...calendarDescription,
...meetingDescription,
...liveDescription,
...wedocDescription,
...wefileDescription,
...mailDescription,
...checkinDescription,
...approvalDescription,
...journalDescription,
...hrDescription,
...meetingroomDescription,
...emergencyDescription,
],
usableAsTool: true,
};
methods = {
loadOptions: {
// 获取所有成员列表
async getAllUsers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
try {
const response = await weComApiRequest.call(this, 'GET', '/cgi-bin/user/list', {}, {
department_id: 1,
fetch_child: 1,
});
const users = response.userlist as Array<{ userid: string; name: string }>;
if (!users || !Array.isArray(users) || users.length === 0) {
return [
{
name: '暂无成员,请先添加',
value: '',
},
];
}
return users.map((user) => ({
name: `${user.name} (${user.userid})`,
value: user.userid,
}));
} catch {
return [
{
name: '获取成员列表失败',
value: '',
},
];
}
},
},
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const resource = this.getNodeParameter('resource', 0);
const operation = this.getNodeParameter('operation', 0);
let returnData: INodeExecutionData[] = [];
if (resource === 'wedoc') {
returnData = await executeWedoc.call(this, operation as string, items);
} else if (resource === 'wefile') {
returnData = await executeWefile.call(this, operation as string, items);
} else if (resource === 'mail') {
returnData = await executeMail.call(this, operation as string, items);
} else if (resource === 'calendar') {
returnData = await executeCalendar.call(this, operation as string, items);
} else if (resource === 'meeting') {
returnData = await executeMeeting.call(this, operation as string, items);
} else if (resource === 'live') {
returnData = await executeLive.call(this, operation as string, items);
} else if (resource === 'checkin') {
returnData = await executeCheckin.call(this, operation as string, items);
} else if (resource === 'approval') {
returnData = await executeApproval.call(this, operation as string, items);
} else if (resource === 'journal') {
returnData = await executeJournal.call(this, operation as string, items);
} else if (resource === 'hr') {
returnData = await executeHr.call(this, operation as string, items);
} else if (resource === 'meetingroom') {
returnData = await executeMeetingroom.call(this, operation as string, items);
} else if (resource === 'emergency') {
returnData = await executeEmergency.call(this, operation as string, items);
}
return [returnData];
}
}