n8n-dingtalk 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,19 @@
1
+ Copyright <YEAR> <COPYRIGHT HOLDER>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # n8n-dingtalk
2
+
3
+ [![NPM badge](https://img.shields.io/npm/v/n8n-dingtalk.svg)](https://www.npmjs.com/package/n8n-dingtalk)
4
+
5
+ For [钉钉](https://dingtalk.com)
6
+
7
+ ## 功能
8
+
9
+ ### 机器人
10
+
11
+ #### 自定义机器人
12
+
13
+ [文档](https://open.dingtalk.com/document/group/custom-robot-access)
14
+
15
+ 0. JSON格式
16
+ <img width="352" alt="image" src="https://user-images.githubusercontent.com/509251/193441704-a109656a-87cc-4597-ba11-d03d968fff40.png">
17
+
18
+
19
+ 1. text类型
20
+ <img width="357" alt="image" src="https://user-images.githubusercontent.com/509251/193441488-848868b4-fdf4-4f4c-a331-a042af46d9dd.png">
21
+
22
+ 2. link类型
23
+ <img width="350" alt="image" src="https://user-images.githubusercontent.com/509251/193441511-4a31d827-ee1b-4f4d-91d7-61373903e7c9.png">
24
+
25
+ 3. markdown类型
26
+ <img width="380" alt="image" src="https://user-images.githubusercontent.com/509251/193441552-f47d40cd-061f-4bf8-b2c9-78f662809243.png">
27
+
28
+ > 自定义机器人在 `text` / `markdown` 场景下,填写“被@人的手机号”或“被@人的用户Userid”后,插件会自动把对应的 `@手机号` / `@userid` 追加到消息正文中,确保钉钉实际触发 @ 效果。
29
+
30
+ 4. 整体跳转ActionCard类型
31
+ <img width="360" alt="image" src="https://user-images.githubusercontent.com/509251/193441654-c36e5a81-0321-4043-9688-b648a04521bf.png">
32
+
33
+ 5. 独立跳转ActionCard类型
34
+ <img width="357" alt="image" src="https://user-images.githubusercontent.com/509251/193441661-633fda05-464d-4297-b657-4077d0725be0.png">
35
+
36
+ 6. FeedCard类型
37
+ <img width="350" alt="image" src="https://user-images.githubusercontent.com/509251/193441683-807cb657-abae-4ac9-9ad1-01616e0fdba0.png">
38
+
39
+
40
+ ## 本地安装
41
+
42
+ 1. 启动n8n`npx n8n`
43
+
44
+ 2. 下载插件并开启编译
45
+
46
+ ```shell
47
+ $ cd ~/git
48
+ $ git clone https://github.com/ruanjf/n8n-nodes-dingtalk.git
49
+ $ cd n8n-nodes-dingtalk
50
+ $ npm run dev
51
+ ```
52
+
53
+ 3. 安装本地依赖
54
+
55
+ ```shell
56
+ $ cd ~/.n8n/nodes/
57
+ $ npm install ../../git/n8n-nodes-dingtalk
58
+ ```
59
+
60
+ 4. 重启`n8n`
61
+
62
+ ## 示例workflow
63
+
64
+ 导入demo
65
+ [test/dingding-workflow-robot.json](https://github.com/ruanjf/n8n-nodes-dingtalk/raw/main/test/dingding-workflow-robot.json)
66
+
67
+ ## License
68
+
69
+ [MIT](https://github.com/ruanjf/n8n-nodes-dingtalk/blob/main/LICENSE.md)
@@ -0,0 +1,6 @@
1
+ import { ICredentialType, INodeProperties } from 'n8n-workflow';
2
+ export declare class DingTalkApi implements ICredentialType {
3
+ name: string;
4
+ displayName: string;
5
+ properties: INodeProperties[];
6
+ }
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DingTalkApi = void 0;
4
+ class DingTalkApi {
5
+ constructor() {
6
+ this.name = 'dingTalkApi';
7
+ this.displayName = 'Dingtalk API';
8
+ this.properties = [
9
+ {
10
+ displayName: 'Type',
11
+ name: 'type',
12
+ type: 'options',
13
+ options: [
14
+ {
15
+ name: 'AccessKey',
16
+ value: 'access_key',
17
+ description: 'AccessKey',
18
+ action: 'AccessKey',
19
+ },
20
+ {
21
+ name: 'Webhook',
22
+ value: 'webhook',
23
+ description: 'Webhook',
24
+ action: 'Webhook',
25
+ },
26
+ ],
27
+ default: 'access_key',
28
+ },
29
+ {
30
+ displayName: 'WebhookUrl',
31
+ name: 'webhookUrl',
32
+ type: 'string',
33
+ default: '',
34
+ displayOptions: {
35
+ show: {
36
+ type: ['webhook'],
37
+ },
38
+ },
39
+ },
40
+ {
41
+ displayName: 'WebhookSign',
42
+ name: 'webhookSign',
43
+ type: 'string',
44
+ default: '',
45
+ displayOptions: {
46
+ show: {
47
+ type: ['webhook'],
48
+ },
49
+ },
50
+ },
51
+ {
52
+ displayName: 'Endpoint',
53
+ name: 'endpoint',
54
+ type: 'string',
55
+ default: '',
56
+ displayOptions: {
57
+ show: {
58
+ type: ['access_key'],
59
+ },
60
+ },
61
+ },
62
+ {
63
+ displayName: 'Access Key Id',
64
+ name: 'accessKeyId',
65
+ type: 'string',
66
+ default: '',
67
+ displayOptions: {
68
+ show: {
69
+ type: ['access_key'],
70
+ },
71
+ },
72
+ },
73
+ {
74
+ displayName: 'Access Key Secret',
75
+ name: 'accessKeySecret',
76
+ type: 'string',
77
+ typeOptions: {
78
+ password: true,
79
+ },
80
+ default: '',
81
+ displayOptions: {
82
+ show: {
83
+ type: ['access_key'],
84
+ },
85
+ },
86
+ },
87
+ {
88
+ displayName: 'Region Id',
89
+ name: 'regionId',
90
+ type: 'string',
91
+ default: 'central',
92
+ displayOptions: {
93
+ show: {
94
+ type: ['access_key'],
95
+ },
96
+ },
97
+ },
98
+ {
99
+ displayName: 'Port',
100
+ name: 'port',
101
+ type: 'number',
102
+ default: 3306,
103
+ },
104
+ {
105
+ displayName: 'Connect Timeout',
106
+ name: 'connectTimeout',
107
+ type: 'number',
108
+ default: 10000,
109
+ description: 'The milliseconds before a timeout occurs during the initial connection to the MySQL server',
110
+ },
111
+ {
112
+ displayName: 'SSL',
113
+ name: 'ssl',
114
+ type: 'boolean',
115
+ default: false,
116
+ },
117
+ {
118
+ displayName: 'CA Certificate',
119
+ name: 'caCertificate',
120
+ typeOptions: {
121
+ alwaysOpenEditWindow: true,
122
+ password: true,
123
+ },
124
+ displayOptions: {
125
+ show: {
126
+ ssl: [true],
127
+ },
128
+ },
129
+ type: 'string',
130
+ default: '',
131
+ },
132
+ {
133
+ displayName: 'Client Private Key',
134
+ name: 'clientPrivateKey',
135
+ typeOptions: {
136
+ alwaysOpenEditWindow: true,
137
+ password: true,
138
+ },
139
+ displayOptions: {
140
+ show: {
141
+ ssl: [true],
142
+ },
143
+ },
144
+ type: 'string',
145
+ default: '',
146
+ },
147
+ {
148
+ displayName: 'Client Certificate',
149
+ name: 'clientCertificate',
150
+ typeOptions: {
151
+ alwaysOpenEditWindow: true,
152
+ password: true,
153
+ },
154
+ displayOptions: {
155
+ show: {
156
+ ssl: [true],
157
+ },
158
+ },
159
+ type: 'string',
160
+ default: '',
161
+ },
162
+ ];
163
+ }
164
+ }
165
+ exports.DingTalkApi = DingTalkApi;
166
+ //# sourceMappingURL=DingTalkApi.credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DingTalkApi.credentials.js","sourceRoot":"","sources":["../../credentials/DingTalkApi.credentials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1B,QAAQ,EAAE,IAAI;iBACd;gBACD,cAAc,EAAE;oBACf,IAAI,EAAE;wBACL,GAAG,EAAE,CAAC,IAAI,CAAC;qBACX;iBACD;gBACD,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,EAAE;aACX;YACD;gBACC,WAAW,EAAE,oBAAoB;gBACjC,IAAI,EAAE,mBAAmB;gBACzB,WAAW,EAAE;oBACZ,oBAAoB,EAAE,IAAI;oBAC1B,QAAQ,EAAE,IAAI;iBACd;gBACD,cAAc,EAAE;oBACf,IAAI,EAAE;wBACL,GAAG,EAAE,CAAC,IAAI,CAAC;qBACX;iBACD;gBACD,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,EAAE;aACX;SACD,CAAC;IACH,CAAC;CAAA;AAhKD,kCAgKC"}
@@ -0,0 +1,6 @@
1
+ import { ICredentialType, INodeProperties } from 'n8n-workflow';
2
+ export declare class DingTalkCompanyApi implements ICredentialType {
3
+ name: string;
4
+ displayName: string;
5
+ properties: INodeProperties[];
6
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DingTalkCompanyApi = void 0;
4
+ class DingTalkCompanyApi {
5
+ constructor() {
6
+ this.name = 'dingTalkCompanyApi';
7
+ this.displayName = 'DingtalkCompany API';
8
+ this.properties = [
9
+ {
10
+ displayName: 'Robot Code',
11
+ name: 'robotCode',
12
+ type: 'string',
13
+ default: '',
14
+ required: true,
15
+ },
16
+ {
17
+ displayName: 'Access Key Id',
18
+ name: 'accessKeyId',
19
+ type: 'string',
20
+ default: '',
21
+ required: true,
22
+ },
23
+ {
24
+ displayName: 'Access Key Secret',
25
+ name: 'accessKeySecret',
26
+ type: 'string',
27
+ typeOptions: {
28
+ password: true,
29
+ },
30
+ default: '',
31
+ required: true,
32
+ },
33
+ {
34
+ displayName: 'protocol',
35
+ name: 'protocol',
36
+ type: 'string',
37
+ default: '',
38
+ required: true,
39
+ },
40
+ {
41
+ displayName: 'region id',
42
+ name: 'regionId',
43
+ type: 'string',
44
+ default: '',
45
+ required: true,
46
+ },
47
+ ];
48
+ }
49
+ }
50
+ exports.DingTalkCompanyApi = DingTalkCompanyApi;
51
+ //# sourceMappingURL=DingTalkCompanyApi.credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DingTalkCompanyApi.credentials.js","sourceRoot":"","sources":["../../credentials/DingTalkCompanyApi.credentials.ts"],"names":[],"mappings":";;;AAEA,MAAa,kBAAkB;IAA/B;QACC,SAAI,GAAG,oBAAoB,CAAC;QAC5B,gBAAW,GAAG,qBAAqB,CAAC;QAEpC,eAAU,GAAsB;YAC/B;gBACC,WAAW,EAAE,YAAY;gBACzB,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,EAAE;gBACX,QAAQ,EAAE,IAAI;aACd;YACD;gBACC,WAAW,EAAE,eAAe;gBAC5B,IAAI,EAAE,aAAa;gBACnB,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,EAAE;gBACX,QAAQ,EAAE,IAAI;aACd;YACD;gBACC,WAAW,EAAE,mBAAmB;gBAChC,IAAI,EAAE,iBAAiB;gBACvB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE;oBACZ,QAAQ,EAAE,IAAI;iBACd;gBACD,OAAO,EAAE,EAAE;gBACX,QAAQ,EAAE,IAAI;aACd;YACD;gBACC,WAAW,EAAE,UAAU;gBACvB,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,EAAE;gBACX,QAAQ,EAAE,IAAI;aACd;YACD;gBACC,WAAW,EAAE,WAAW;gBACxB,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,EAAE;gBACX,QAAQ,EAAE,IAAI;aACd;SACD,CAAC;IACH,CAAC;CAAA;AA5CD,gDA4CC"}
@@ -0,0 +1,6 @@
1
+ import { ICredentialType, INodeProperties } from 'n8n-workflow';
2
+ export declare class DingTalkCustomRobotApi implements ICredentialType {
3
+ name: string;
4
+ displayName: string;
5
+ properties: INodeProperties[];
6
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DingTalkCustomRobotApi = void 0;
4
+ class DingTalkCustomRobotApi {
5
+ constructor() {
6
+ this.name = 'dingTalkCustomRobotApi';
7
+ this.displayName = 'DingTalkCustomRobot API';
8
+ this.properties = [
9
+ {
10
+ displayName: 'WebhookUrl',
11
+ name: 'webhookUrl',
12
+ type: 'string',
13
+ default: '',
14
+ required: true,
15
+ },
16
+ {
17
+ displayName: 'WebhookSign',
18
+ name: 'webhookSign',
19
+ type: 'string',
20
+ default: null,
21
+ },
22
+ ];
23
+ }
24
+ }
25
+ exports.DingTalkCustomRobotApi = DingTalkCustomRobotApi;
26
+ //# sourceMappingURL=DingTalkCustomRobotApi.credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DingTalkCustomRobotApi.credentials.js","sourceRoot":"","sources":["../../credentials/DingTalkCustomRobotApi.credentials.ts"],"names":[],"mappings":";;;AAEA,MAAa,sBAAsB;IAAnC;QACC,SAAI,GAAG,wBAAwB,CAAC;QAChC,gBAAW,GAAG,yBAAyB,CAAC;QAExC,eAAU,GAAsB;YAC/B;gBACC,WAAW,EAAE,YAAY;gBACzB,IAAI,EAAE,YAAY;gBAClB,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,EAAE;gBACX,QAAQ,EAAE,IAAI;aACd;YACD;gBACC,WAAW,EAAE,aAAa;gBAC1B,IAAI,EAAE,aAAa;gBACnB,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,IAAI;aACb;SACD,CAAC;IACH,CAAC;CAAA;AAnBD,wDAmBC"}
@@ -0,0 +1,6 @@
1
+ import { IExecuteFunctions } from 'n8n-core';
2
+ import { INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
3
+ export declare class DingTalk implements INodeType {
4
+ description: INodeTypeDescription;
5
+ execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
6
+ }
@@ -0,0 +1,298 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.DingTalk = void 0;
30
+ const n8n_workflow_1 = require("n8n-workflow");
31
+ const crypto_1 = __importDefault(require("crypto"));
32
+ const axios_1 = __importDefault(require("axios"));
33
+ const client_1 = __importStar(require("@alicloud/dingtalk/dist/robot_1_0/client")), $RobotClient = client_1;
34
+ const OpenApi = __importStar(require("@alicloud/openapi-client"));
35
+ const Util = __importStar(require("@alicloud/tea-util"));
36
+ class DingTalk {
37
+ constructor() {
38
+ this.description = {
39
+ displayName: 'DingDing',
40
+ name: 'DingTalk',
41
+ icon: 'file:dingtalk.svg',
42
+ group: ['input'],
43
+ version: 1,
44
+ subtitle: '={{$parameter["type"]}}',
45
+ description: 'DingDing API',
46
+ defaults: {
47
+ name: 'Ding Ding',
48
+ },
49
+ inputs: ['main'],
50
+ outputs: ['main'],
51
+ credentials: [
52
+ {
53
+ name: 'dingtalkApi',
54
+ required: true,
55
+ displayOptions: {
56
+ show: {
57
+ type: ['dingtalk'],
58
+ },
59
+ },
60
+ },
61
+ {
62
+ name: 'dingTalkCustomRobotApi',
63
+ required: true,
64
+ displayOptions: {
65
+ show: {
66
+ type: ['customRobot'],
67
+ },
68
+ },
69
+ },
70
+ ],
71
+ properties: [
72
+ {
73
+ displayName: 'Type',
74
+ name: 'type',
75
+ type: 'options',
76
+ required: true,
77
+ noDataExpression: true,
78
+ options: [
79
+ {
80
+ name: '自定义机器人',
81
+ value: 'customRobot',
82
+ description: '自定义机器人存在限流, 每分钟20次',
83
+ action: '自定义机器人',
84
+ },
85
+ {
86
+ name: 'Webhook',
87
+ value: 'webhook',
88
+ action: 'Webhook',
89
+ },
90
+ ],
91
+ default: 'customRobot',
92
+ },
93
+ {
94
+ displayName: '消息类型',
95
+ name: 'msgtype',
96
+ type: 'options',
97
+ required: true,
98
+ noDataExpression: true,
99
+ options: [
100
+ {
101
+ name: 'ActionCard类型',
102
+ value: 'actionCard',
103
+ },
104
+ {
105
+ name: 'FeedCard类型',
106
+ value: 'feedCard',
107
+ },
108
+ {
109
+ name: 'Link类型',
110
+ value: 'link',
111
+ },
112
+ {
113
+ name: 'Markdown类型',
114
+ value: 'markdown',
115
+ },
116
+ {
117
+ name: 'Text类型',
118
+ value: 'text',
119
+ },
120
+ ],
121
+ default: 'text',
122
+ },
123
+ {
124
+ displayName: '被@人的手机号',
125
+ name: 'atMobiles',
126
+ type: 'string',
127
+ default: '',
128
+ displayOptions: {
129
+ show: {
130
+ type: ['customRobot'],
131
+ msgtype: ['text'],
132
+ },
133
+ },
134
+ },
135
+ {
136
+ displayName: '被@人的用户Userid',
137
+ name: 'atUserIds',
138
+ type: 'string',
139
+ default: '',
140
+ displayOptions: {
141
+ show: {
142
+ type: ['customRobot'],
143
+ msgtype: ['text'],
144
+ },
145
+ },
146
+ },
147
+ {
148
+ displayName: '是否@所有人',
149
+ name: 'isAtAll',
150
+ type: 'boolean',
151
+ default: false,
152
+ placeholder: '',
153
+ displayOptions: {
154
+ show: {
155
+ type: ['customRobot'],
156
+ msgtype: ['text'],
157
+ },
158
+ },
159
+ },
160
+ {
161
+ displayName: '消息内容',
162
+ name: 'content',
163
+ type: 'json',
164
+ default: '',
165
+ required: true,
166
+ placeholder: '',
167
+ displayOptions: {
168
+ show: {
169
+ type: ['customRobot'],
170
+ },
171
+ },
172
+ },
173
+ ],
174
+ };
175
+ }
176
+ async execute() {
177
+ const type = this.getNodeParameter('type', 0);
178
+ if (type === 'customRobot') {
179
+ const credentials = await this.getCredentials('dingTalkCustomRobot');
180
+ const timestamp = Date.parse(new Date().toString());
181
+ const stringToSign = `${timestamp}\n${credentials.webhookSign}`;
182
+ const signBase64 = crypto_1.default
183
+ .createHmac('sha256', credentials.webhookSign)
184
+ .update(stringToSign)
185
+ .digest('base64');
186
+ const sign = encodeURIComponent(signBase64);
187
+ const url = credentials.webhookSign
188
+ ? `${credentials.webhookUrl}&timestamp=${timestamp}&sign=${sign}`
189
+ : credentials.webhookUrl;
190
+ const result = [];
191
+ const items = this.getInputData();
192
+ let item;
193
+ for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
194
+ try {
195
+ item = items[itemIndex];
196
+ const msgtype = this.getNodeParameter('msgtype', itemIndex);
197
+ const content = this.getNodeParameter('content', itemIndex);
198
+ const data = { msgtype };
199
+ if ('text' === msgtype || 'markdown' === msgtype) {
200
+ const atMobiles = this.getNodeParameter('atMobiles', itemIndex);
201
+ const atUserIds = this.getNodeParameter('atUserIds', itemIndex);
202
+ const isAtAll = this.getNodeParameter('isAtAll', itemIndex);
203
+ const at = { isAtAll };
204
+ data.at = { isAtAll };
205
+ if (atMobiles && atMobiles.length > 0) {
206
+ at.atMobiles = atMobiles;
207
+ }
208
+ if (atUserIds && atUserIds.length > 0) {
209
+ at.atUserIds = atUserIds;
210
+ }
211
+ data.at = at;
212
+ if ('text' === msgtype) {
213
+ data.text = { content };
214
+ }
215
+ else if ('markdown' === msgtype) {
216
+ data.link = content;
217
+ }
218
+ }
219
+ else if ('link' === msgtype) {
220
+ data.link = content;
221
+ }
222
+ else if ('actionCard' === msgtype) {
223
+ data.actionCard = content;
224
+ }
225
+ else if ('feedCard' === msgtype) {
226
+ data.feedCard = content;
227
+ }
228
+ const res = await axios_1.default.post(url, data, {
229
+ headers: {
230
+ 'Content-Type': 'application/json',
231
+ },
232
+ });
233
+ result.push({ json: res.data });
234
+ }
235
+ catch (error) {
236
+ if (this.continueOnFail()) {
237
+ result.push({
238
+ json: this.getInputData(itemIndex)[0].json,
239
+ error,
240
+ pairedItem: itemIndex,
241
+ });
242
+ }
243
+ else {
244
+ if (error.context) {
245
+ error.context.itemIndex = itemIndex;
246
+ throw error;
247
+ }
248
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, {
249
+ itemIndex,
250
+ });
251
+ }
252
+ }
253
+ }
254
+ return this.prepareOutputData(result);
255
+ }
256
+ const rbClient = new client_1.default(new OpenApi.Config({
257
+ endpoint: 'your endpoint',
258
+ accessKeyId: 'your access key id',
259
+ accessKeySecret: 'your access key secret',
260
+ type: 'access_key',
261
+ regionId: 'cn-hangzhou',
262
+ }));
263
+ const runtimeObject = new Util.RuntimeOptions({});
264
+ const items = this.getInputData();
265
+ let item;
266
+ for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
267
+ try {
268
+ item = items[itemIndex];
269
+ const req = new $RobotClient.SendRobotDingMessageRequest();
270
+ rbClient.sendRobotDingMessage(req);
271
+ const binaryPropertyName = this.getNodeParameter('binaryPropertyName', itemIndex);
272
+ if (item.binary === undefined || item.binary[binaryPropertyName] === undefined) {
273
+ continue;
274
+ }
275
+ const binaryPropertyOutputName = this.getNodeParameter('binaryPropertyOutputName', itemIndex, binaryPropertyName);
276
+ const inputEncoding = this.getNodeParameter('inputEncoding', itemIndex);
277
+ const outputEncoding = this.getNodeParameter('outputEncoding', itemIndex);
278
+ }
279
+ catch (error) {
280
+ if (this.continueOnFail()) {
281
+ items.push({ json: this.getInputData(itemIndex)[0].json, error, pairedItem: itemIndex });
282
+ }
283
+ else {
284
+ if (error.context) {
285
+ error.context.itemIndex = itemIndex;
286
+ throw error;
287
+ }
288
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, {
289
+ itemIndex,
290
+ });
291
+ }
292
+ }
293
+ }
294
+ return this.prepareOutputData(items);
295
+ }
296
+ }
297
+ exports.DingTalk = DingTalk;
298
+ //# sourceMappingURL=DingTalk.node.js.map