n8n-nodes-base 0.212.0 → 0.212.1

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.
Files changed (111) hide show
  1. package/dist/credentials/Aws.credentials.d.ts +1 -1
  2. package/dist/credentials/SlackOAuth2Api.credentials.js +6 -0
  3. package/dist/credentials/SlackOAuth2Api.credentials.js.map +1 -1
  4. package/dist/known/credentials.json +4 -2
  5. package/dist/nodes/BambooHr/v1/actions/Interfaces.d.ts +10 -10
  6. package/dist/nodes/Bitwarden/descriptions/CollectionDescription.d.ts +1 -1
  7. package/dist/nodes/Bitwarden/descriptions/GroupDescription.d.ts +3 -3
  8. package/dist/nodes/Bitwarden/descriptions/MemberDescription.d.ts +3 -3
  9. package/dist/nodes/Code/utils.d.ts +1 -1
  10. package/dist/nodes/CompareDatasets/GenericFunctions.d.ts +1 -1
  11. package/dist/nodes/ERPNext/utils.d.ts +2 -2
  12. package/dist/nodes/Google/Analytics/v2/actions/node.type.d.ts +5 -5
  13. package/dist/nodes/Google/Sheet/v1/GoogleSheet.d.ts +2 -2
  14. package/dist/nodes/Google/Sheet/v2/helpers/GoogleSheets.types.d.ts +14 -14
  15. package/dist/nodes/Html/types.d.ts +1 -1
  16. package/dist/nodes/HttpRequest/GenericFunctions.d.ts +1 -1
  17. package/dist/nodes/Jenkins/Jenkins.node.d.ts +1 -1
  18. package/dist/nodes/Mattermost/v1/actions/Interfaces.d.ts +10 -10
  19. package/dist/nodes/Merge/v2/GenericFunctions.d.ts +9 -9
  20. package/dist/nodes/MongoDb/mongoDb.types.d.ts +2 -2
  21. package/dist/nodes/Notion/GenericFunctions.d.ts +1 -1
  22. package/dist/nodes/Odoo/GenericFunctions.d.ts +1 -1
  23. package/dist/nodes/SeaTable/Interfaces.d.ts +1 -1
  24. package/dist/nodes/SeaTable/Schema.d.ts +1 -1
  25. package/dist/nodes/SendGrid/MailDescription.d.ts +2 -2
  26. package/dist/nodes/Slack/Slack.node.d.ts +3 -12
  27. package/dist/nodes/Slack/Slack.node.js +9 -997
  28. package/dist/nodes/Slack/Slack.node.js.map +1 -1
  29. package/dist/nodes/Slack/{ChannelDescription.d.ts → V1/ChannelDescription.d.ts} +0 -0
  30. package/dist/nodes/Slack/{ChannelDescription.js → V1/ChannelDescription.js} +0 -0
  31. package/dist/nodes/Slack/V1/ChannelDescription.js.map +1 -0
  32. package/dist/nodes/Slack/{FileDescription.d.ts → V1/FileDescription.d.ts} +0 -0
  33. package/dist/nodes/Slack/{FileDescription.js → V1/FileDescription.js} +0 -0
  34. package/dist/nodes/Slack/V1/FileDescription.js.map +1 -0
  35. package/dist/nodes/Slack/{GenericFunctions.d.ts → V1/GenericFunctions.d.ts} +0 -0
  36. package/dist/nodes/Slack/{GenericFunctions.js → V1/GenericFunctions.js} +0 -0
  37. package/dist/nodes/Slack/V1/GenericFunctions.js.map +1 -0
  38. package/dist/nodes/Slack/{MessageDescription.d.ts → V1/MessageDescription.d.ts} +0 -0
  39. package/dist/nodes/Slack/{MessageDescription.js → V1/MessageDescription.js} +0 -0
  40. package/dist/nodes/Slack/V1/MessageDescription.js.map +1 -0
  41. package/dist/nodes/Slack/{MessageInterface.d.ts → V1/MessageInterface.d.ts} +0 -0
  42. package/dist/nodes/Slack/{MessageInterface.js → V1/MessageInterface.js} +0 -0
  43. package/dist/nodes/Slack/V1/MessageInterface.js.map +1 -0
  44. package/dist/nodes/Slack/{ReactionDescription.d.ts → V1/ReactionDescription.d.ts} +0 -0
  45. package/dist/nodes/Slack/{ReactionDescription.js → V1/ReactionDescription.js} +0 -0
  46. package/dist/nodes/Slack/V1/ReactionDescription.js.map +1 -0
  47. package/dist/nodes/Slack/V1/SlackV1.node.d.ts +14 -0
  48. package/dist/nodes/Slack/V1/SlackV1.node.js +1012 -0
  49. package/dist/nodes/Slack/V1/SlackV1.node.js.map +1 -0
  50. package/dist/nodes/Slack/{StarDescription.d.ts → V1/StarDescription.d.ts} +0 -0
  51. package/dist/nodes/Slack/{StarDescription.js → V1/StarDescription.js} +0 -0
  52. package/dist/nodes/Slack/V1/StarDescription.js.map +1 -0
  53. package/dist/nodes/Slack/{UserDescription.d.ts → V1/UserDescription.d.ts} +0 -0
  54. package/dist/nodes/Slack/{UserDescription.js → V1/UserDescription.js} +0 -0
  55. package/dist/nodes/Slack/V1/UserDescription.js.map +1 -0
  56. package/dist/nodes/Slack/{UserGroupDescription.d.ts → V1/UserGroupDescription.d.ts} +0 -0
  57. package/dist/nodes/Slack/{UserGroupDescription.js → V1/UserGroupDescription.js} +0 -0
  58. package/dist/nodes/Slack/V1/UserGroupDescription.js.map +1 -0
  59. package/dist/nodes/Slack/{UserProfileDescription.d.ts → V1/UserProfileDescription.d.ts} +0 -0
  60. package/dist/nodes/Slack/{UserProfileDescription.js → V1/UserProfileDescription.js} +0 -0
  61. package/dist/nodes/Slack/V1/UserProfileDescription.js.map +1 -0
  62. package/dist/nodes/Slack/V2/ChannelDescription.d.ts +3 -0
  63. package/dist/nodes/Slack/V2/ChannelDescription.js +1420 -0
  64. package/dist/nodes/Slack/V2/ChannelDescription.js.map +1 -0
  65. package/dist/nodes/Slack/V2/FileDescription.d.ts +3 -0
  66. package/dist/nodes/Slack/V2/FileDescription.js +270 -0
  67. package/dist/nodes/Slack/V2/FileDescription.js.map +1 -0
  68. package/dist/nodes/Slack/V2/GenericFunctions.d.ts +5 -0
  69. package/dist/nodes/Slack/V2/GenericFunctions.js +95 -0
  70. package/dist/nodes/Slack/V2/GenericFunctions.js.map +1 -0
  71. package/dist/nodes/Slack/V2/MessageDescription.d.ts +3 -0
  72. package/dist/nodes/Slack/V2/MessageDescription.js +1109 -0
  73. package/dist/nodes/Slack/V2/MessageDescription.js.map +1 -0
  74. package/dist/nodes/Slack/V2/MessageInterface.d.ts +5 -0
  75. package/dist/nodes/Slack/V2/MessageInterface.js +3 -0
  76. package/dist/nodes/Slack/V2/MessageInterface.js.map +1 -0
  77. package/dist/nodes/Slack/V2/ReactionDescription.d.ts +3 -0
  78. package/dist/nodes/Slack/V2/ReactionDescription.js +131 -0
  79. package/dist/nodes/Slack/V2/ReactionDescription.js.map +1 -0
  80. package/dist/nodes/Slack/V2/SlackV2.node.d.ts +19 -0
  81. package/dist/nodes/Slack/V2/SlackV2.node.js +908 -0
  82. package/dist/nodes/Slack/V2/SlackV2.node.js.map +1 -0
  83. package/dist/nodes/Slack/V2/StarDescription.d.ts +3 -0
  84. package/dist/nodes/Slack/V2/StarDescription.js +257 -0
  85. package/dist/nodes/Slack/V2/StarDescription.js.map +1 -0
  86. package/dist/nodes/Slack/V2/UserDescription.d.ts +3 -0
  87. package/dist/nodes/Slack/V2/UserDescription.js +281 -0
  88. package/dist/nodes/Slack/V2/UserDescription.js.map +1 -0
  89. package/dist/nodes/Slack/V2/UserGroupDescription.d.ts +3 -0
  90. package/dist/nodes/Slack/V2/UserGroupDescription.js +313 -0
  91. package/dist/nodes/Slack/V2/UserGroupDescription.js.map +1 -0
  92. package/dist/nodes/Supabase/Supabase.node.d.ts +1 -1
  93. package/dist/nodes/SyncroMSP/v1/actions/Interfaces.d.ts +10 -10
  94. package/dist/nodes/TheHive/QueryFunctions.d.ts +1 -1
  95. package/dist/nodes/Todoist/GenericFunctions.d.ts +1 -1
  96. package/dist/nodes/Wise/GenericFunctions.d.ts +6 -6
  97. package/dist/nodes/WooCommerce/GenericFunctions.d.ts +1 -1
  98. package/dist/tsconfig.tsbuildinfo +1 -1
  99. package/dist/types/credentials.json +1 -1
  100. package/dist/types/nodes.json +3 -2
  101. package/package.json +1 -1
  102. package/dist/nodes/Slack/ChannelDescription.js.map +0 -1
  103. package/dist/nodes/Slack/FileDescription.js.map +0 -1
  104. package/dist/nodes/Slack/GenericFunctions.js.map +0 -1
  105. package/dist/nodes/Slack/MessageDescription.js.map +0 -1
  106. package/dist/nodes/Slack/MessageInterface.js.map +0 -1
  107. package/dist/nodes/Slack/ReactionDescription.js.map +0 -1
  108. package/dist/nodes/Slack/StarDescription.js.map +0 -1
  109. package/dist/nodes/Slack/UserDescription.js.map +0 -1
  110. package/dist/nodes/Slack/UserGroupDescription.js.map +0 -1
  111. package/dist/nodes/Slack/UserProfileDescription.js.map +0 -1
@@ -1,1013 +1,25 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.Slack = void 0;
7
4
  const n8n_workflow_1 = require("n8n-workflow");
8
- const ChannelDescription_1 = require("./ChannelDescription");
9
- const MessageDescription_1 = require("./MessageDescription");
10
- const StarDescription_1 = require("./StarDescription");
11
- const FileDescription_1 = require("./FileDescription");
12
- const ReactionDescription_1 = require("./ReactionDescription");
13
- const UserGroupDescription_1 = require("./UserGroupDescription");
14
- const UserDescription_1 = require("./UserDescription");
15
- const UserProfileDescription_1 = require("./UserProfileDescription");
16
- const GenericFunctions_1 = require("./GenericFunctions");
17
- const moment_1 = __importDefault(require("moment"));
18
- class Slack {
5
+ const SlackV1_node_1 = require("./V1/SlackV1.node");
6
+ const SlackV2_node_1 = require("./V2/SlackV2.node");
7
+ class Slack extends n8n_workflow_1.VersionedNodeType {
19
8
  constructor() {
20
- this.description = {
9
+ const baseDescription = {
21
10
  displayName: 'Slack',
22
11
  name: 'slack',
23
12
  icon: 'file:slack.svg',
24
13
  group: ['output'],
25
- version: 1,
26
14
  subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
27
15
  description: 'Consume Slack API',
28
- defaults: {
29
- name: 'Slack',
30
- },
31
- inputs: ['main'],
32
- outputs: ['main'],
33
- credentials: [
34
- {
35
- name: 'slackApi',
36
- required: true,
37
- displayOptions: {
38
- show: {
39
- authentication: ['accessToken'],
40
- },
41
- },
42
- },
43
- {
44
- name: 'slackOAuth2Api',
45
- required: true,
46
- displayOptions: {
47
- show: {
48
- authentication: ['oAuth2'],
49
- },
50
- },
51
- },
52
- ],
53
- properties: [
54
- {
55
- displayName: 'Authentication',
56
- name: 'authentication',
57
- type: 'options',
58
- options: [
59
- {
60
- name: 'Access Token',
61
- value: 'accessToken',
62
- },
63
- {
64
- name: 'OAuth2',
65
- value: 'oAuth2',
66
- },
67
- ],
68
- default: 'accessToken',
69
- },
70
- {
71
- displayName: 'Resource',
72
- name: 'resource',
73
- type: 'options',
74
- noDataExpression: true,
75
- options: [
76
- {
77
- name: 'Channel',
78
- value: 'channel',
79
- },
80
- {
81
- name: 'File',
82
- value: 'file',
83
- },
84
- {
85
- name: 'Message',
86
- value: 'message',
87
- },
88
- {
89
- name: 'Reaction',
90
- value: 'reaction',
91
- },
92
- {
93
- name: 'Star',
94
- value: 'star',
95
- },
96
- {
97
- name: 'User',
98
- value: 'user',
99
- },
100
- {
101
- name: 'User Group',
102
- value: 'userGroup',
103
- },
104
- {
105
- name: 'User Profile',
106
- value: 'userProfile',
107
- },
108
- ],
109
- default: 'message',
110
- },
111
- ...ChannelDescription_1.channelOperations,
112
- ...ChannelDescription_1.channelFields,
113
- ...MessageDescription_1.messageOperations,
114
- ...MessageDescription_1.messageFields,
115
- ...StarDescription_1.starOperations,
116
- ...StarDescription_1.starFields,
117
- ...FileDescription_1.fileOperations,
118
- ...FileDescription_1.fileFields,
119
- ...ReactionDescription_1.reactionOperations,
120
- ...ReactionDescription_1.reactionFields,
121
- ...UserDescription_1.userOperations,
122
- ...UserDescription_1.userFields,
123
- ...UserGroupDescription_1.userGroupOperations,
124
- ...UserGroupDescription_1.userGroupFields,
125
- ...UserProfileDescription_1.userProfileOperations,
126
- ...UserProfileDescription_1.userProfileFields,
127
- ],
16
+ defaultVersion: 2,
128
17
  };
129
- this.methods = {
130
- loadOptions: {
131
- async getUsers() {
132
- const returnData = [];
133
- const users = await GenericFunctions_1.slackApiRequestAllItems.call(this, 'members', 'GET', '/users.list');
134
- for (const user of users) {
135
- const userName = user.name;
136
- const userId = user.id;
137
- returnData.push({
138
- name: userName,
139
- value: userId,
140
- });
141
- }
142
- returnData.sort((a, b) => {
143
- if (a.name < b.name) {
144
- return -1;
145
- }
146
- if (a.name > b.name) {
147
- return 1;
148
- }
149
- return 0;
150
- });
151
- return returnData;
152
- },
153
- async getChannels() {
154
- const returnData = [];
155
- const qs = { types: 'public_channel,private_channel', limit: 1000 };
156
- const channels = await GenericFunctions_1.slackApiRequestAllItems.call(this, 'channels', 'GET', '/conversations.list', {}, qs);
157
- for (const channel of channels) {
158
- const channelName = channel.name;
159
- const channelId = channel.id;
160
- returnData.push({
161
- name: channelName,
162
- value: channelId,
163
- });
164
- }
165
- returnData.sort((a, b) => {
166
- if (a.name < b.name) {
167
- return -1;
168
- }
169
- if (a.name > b.name) {
170
- return 1;
171
- }
172
- return 0;
173
- });
174
- return returnData;
175
- },
176
- async getTeamFields() {
177
- const returnData = [];
178
- const { profile: { fields }, } = await GenericFunctions_1.slackApiRequest.call(this, 'GET', '/team.profile.get');
179
- for (const field of fields) {
180
- const fieldName = field.label;
181
- const fieldId = field.id;
182
- returnData.push({
183
- name: fieldName,
184
- value: fieldId,
185
- });
186
- }
187
- return returnData;
188
- },
189
- },
18
+ const nodeVersions = {
19
+ 1: new SlackV1_node_1.SlackV1(baseDescription),
20
+ 2: new SlackV2_node_1.SlackV2(baseDescription),
190
21
  };
191
- }
192
- async execute() {
193
- const items = this.getInputData();
194
- const returnData = [];
195
- const length = items.length;
196
- let qs;
197
- let responseData;
198
- const authentication = this.getNodeParameter('authentication', 0);
199
- const resource = this.getNodeParameter('resource', 0);
200
- const operation = this.getNodeParameter('operation', 0);
201
- for (let i = 0; i < length; i++) {
202
- try {
203
- responseData = {
204
- error: 'Resource ' + resource + ' / operation ' + operation + ' not found!',
205
- };
206
- qs = {};
207
- if (resource === 'channel') {
208
- if (operation === 'archive') {
209
- const channel = this.getNodeParameter('channelId', i);
210
- const body = {
211
- channel,
212
- };
213
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/conversations.archive', body, qs);
214
- }
215
- if (operation === 'close') {
216
- const channel = this.getNodeParameter('channelId', i);
217
- const body = {
218
- channel,
219
- };
220
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/conversations.close', body, qs);
221
- }
222
- if (operation === 'create') {
223
- const channel = this.getNodeParameter('channelId', i);
224
- const additionalFields = this.getNodeParameter('additionalFields', i);
225
- const body = {
226
- name: channel,
227
- };
228
- if (additionalFields.isPrivate) {
229
- body.is_private = additionalFields.isPrivate;
230
- }
231
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/conversations.create', body, qs);
232
- responseData = responseData.channel;
233
- }
234
- if (operation === 'kick') {
235
- const channel = this.getNodeParameter('channelId', i);
236
- const userId = this.getNodeParameter('userId', i);
237
- const body = {
238
- channel,
239
- user: userId,
240
- };
241
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/conversations.kick', body, qs);
242
- }
243
- if (operation === 'join') {
244
- const channel = this.getNodeParameter('channelId', i);
245
- const body = {
246
- channel,
247
- };
248
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/conversations.join', body, qs);
249
- responseData = responseData.channel;
250
- }
251
- if (operation === 'get') {
252
- const channel = this.getNodeParameter('channelId', i);
253
- qs.channel = channel;
254
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/conversations.info', {}, qs);
255
- responseData = responseData.channel;
256
- }
257
- if (operation === 'getAll') {
258
- const returnAll = this.getNodeParameter('returnAll', i);
259
- const filters = this.getNodeParameter('filters', i);
260
- if (filters.types) {
261
- qs.types = filters.types.join(',');
262
- }
263
- if (filters.excludeArchived) {
264
- qs.exclude_archived = filters.excludeArchived;
265
- }
266
- if (returnAll) {
267
- responseData = await GenericFunctions_1.slackApiRequestAllItems.call(this, 'channels', 'GET', '/conversations.list', {}, qs);
268
- }
269
- else {
270
- qs.limit = this.getNodeParameter('limit', i);
271
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'GET', '/conversations.list', {}, qs);
272
- responseData = responseData.channels;
273
- }
274
- }
275
- if (operation === 'history') {
276
- const channel = this.getNodeParameter('channelId', i);
277
- const returnAll = this.getNodeParameter('returnAll', i);
278
- const filters = this.getNodeParameter('filters', i);
279
- qs.channel = channel;
280
- if (filters.inclusive) {
281
- qs.inclusive = filters.inclusive;
282
- }
283
- if (filters.latest) {
284
- qs.latest = new Date(filters.latest).getTime() / 1000;
285
- }
286
- if (filters.oldest) {
287
- qs.oldest = new Date(filters.oldest).getTime() / 1000;
288
- }
289
- if (returnAll) {
290
- responseData = await GenericFunctions_1.slackApiRequestAllItems.call(this, 'messages', 'GET', '/conversations.history', {}, qs);
291
- }
292
- else {
293
- qs.limit = this.getNodeParameter('limit', i);
294
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'GET', '/conversations.history', {}, qs);
295
- responseData = responseData.messages;
296
- }
297
- }
298
- if (operation === 'invite') {
299
- const channel = this.getNodeParameter('channelId', i);
300
- const userIds = this.getNodeParameter('userIds', i).join(',');
301
- const body = {
302
- channel,
303
- users: userIds,
304
- };
305
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/conversations.invite', body, qs);
306
- responseData = responseData.channel;
307
- }
308
- if (operation === 'leave') {
309
- const channel = this.getNodeParameter('channelId', i);
310
- const body = {
311
- channel,
312
- };
313
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/conversations.leave', body, qs);
314
- }
315
- if (operation === 'member') {
316
- const returnAll = this.getNodeParameter('returnAll', 0);
317
- const resolveData = this.getNodeParameter('resolveData', 0);
318
- qs.channel = this.getNodeParameter('channelId', i);
319
- if (returnAll) {
320
- responseData = await GenericFunctions_1.slackApiRequestAllItems.call(this, 'members', 'GET', '/conversations.members', {}, qs);
321
- responseData = responseData.map((member) => ({ member }));
322
- }
323
- else {
324
- qs.limit = this.getNodeParameter('limit', i);
325
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'GET', '/conversations.members', {}, qs);
326
- responseData = responseData.members.map((member) => ({ member }));
327
- }
328
- if (resolveData) {
329
- const data = [];
330
- for (const { member } of responseData) {
331
- const { user } = await GenericFunctions_1.slackApiRequest.call(this, 'GET', '/users.info', {}, { user: member });
332
- data.push(user);
333
- }
334
- responseData = data;
335
- }
336
- }
337
- if (operation === 'open') {
338
- const options = this.getNodeParameter('options', i);
339
- const body = {};
340
- if (options.channelId) {
341
- body.channel = options.channelId;
342
- }
343
- if (options.returnIm) {
344
- body.return_im = options.returnIm;
345
- }
346
- if (options.users) {
347
- body.users = options.users.join(',');
348
- }
349
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/conversations.open', body, qs);
350
- responseData = responseData.channel;
351
- }
352
- if (operation === 'rename') {
353
- const channel = this.getNodeParameter('channelId', i);
354
- const name = this.getNodeParameter('name', i);
355
- const body = {
356
- channel,
357
- name,
358
- };
359
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/conversations.rename', body, qs);
360
- responseData = responseData.channel;
361
- }
362
- if (operation === 'replies') {
363
- const channel = this.getNodeParameter('channelId', i);
364
- const ts = this.getNodeParameter('ts', i);
365
- const returnAll = this.getNodeParameter('returnAll', i);
366
- const filters = this.getNodeParameter('filters', i);
367
- qs.channel = channel;
368
- qs.ts = ts;
369
- if (filters.inclusive) {
370
- qs.inclusive = filters.inclusive;
371
- }
372
- if (filters.latest) {
373
- qs.latest = new Date(filters.latest).getTime() / 1000;
374
- }
375
- if (filters.oldest) {
376
- qs.oldest = new Date(filters.oldest).getTime() / 1000;
377
- }
378
- if (returnAll) {
379
- responseData = await GenericFunctions_1.slackApiRequestAllItems.call(this, 'messages', 'GET', '/conversations.replies', {}, qs);
380
- }
381
- else {
382
- qs.limit = this.getNodeParameter('limit', i);
383
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'GET', '/conversations.replies', {}, qs);
384
- responseData = responseData.messages;
385
- }
386
- }
387
- if (operation === 'setPurpose') {
388
- const channel = this.getNodeParameter('channelId', i);
389
- const purpose = this.getNodeParameter('purpose', i);
390
- const body = {
391
- channel,
392
- purpose,
393
- };
394
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/conversations.setPurpose', body, qs);
395
- responseData = responseData.channel;
396
- }
397
- if (operation === 'setTopic') {
398
- const channel = this.getNodeParameter('channelId', i);
399
- const topic = this.getNodeParameter('topic', i);
400
- const body = {
401
- channel,
402
- topic,
403
- };
404
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/conversations.setTopic', body, qs);
405
- responseData = responseData.channel;
406
- }
407
- if (operation === 'unarchive') {
408
- const channel = this.getNodeParameter('channelId', i);
409
- const body = {
410
- channel,
411
- };
412
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/conversations.unarchive', body, qs);
413
- }
414
- }
415
- if (resource === 'message') {
416
- if (['post', 'postEphemeral'].includes(operation)) {
417
- const channel = this.getNodeParameter('channel', i);
418
- const { sendAsUser } = this.getNodeParameter('otherOptions', i);
419
- const text = this.getNodeParameter('text', i);
420
- const body = {
421
- channel,
422
- text,
423
- };
424
- let action = 'postMessage';
425
- if (operation === 'postEphemeral') {
426
- body.user = this.getNodeParameter('user', i);
427
- action = 'postEphemeral';
428
- }
429
- const jsonParameters = this.getNodeParameter('jsonParameters', i);
430
- if (authentication === 'accessToken' && sendAsUser !== '') {
431
- body.username = sendAsUser;
432
- }
433
- if (!jsonParameters) {
434
- const attachments = this.getNodeParameter('attachments', i, []);
435
- const blocksUi = this.getNodeParameter('blocksUi', i, [])
436
- .blocksValues;
437
- for (const attachment of attachments) {
438
- if (attachment.fields !== undefined) {
439
- if (attachment.fields.item !== undefined) {
440
- attachment.fields = attachment.fields.item;
441
- }
442
- else {
443
- delete attachment.fields;
444
- }
445
- }
446
- }
447
- body.attachments = attachments;
448
- if (blocksUi) {
449
- const blocks = [];
450
- for (const blockUi of blocksUi) {
451
- const block = {};
452
- const elements = [];
453
- block.block_id = blockUi.blockId;
454
- block.type = blockUi.type;
455
- if (block.type === 'actions') {
456
- const elementsUi = blockUi.elementsUi
457
- .elementsValues;
458
- if (elementsUi) {
459
- for (const elementUi of elementsUi) {
460
- const element = {};
461
- if (elementUi.actionId === '') {
462
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Action ID must be set', {
463
- itemIndex: i,
464
- });
465
- }
466
- if (elementUi.text === '') {
467
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Text must be set', {
468
- itemIndex: i,
469
- });
470
- }
471
- element.action_id = elementUi.actionId;
472
- element.type = elementUi.type;
473
- element.text = {
474
- text: elementUi.text,
475
- type: 'plain_text',
476
- emoji: elementUi.emoji,
477
- };
478
- if (elementUi.url) {
479
- element.url = elementUi.url;
480
- }
481
- if (elementUi.value) {
482
- element.value = elementUi.value;
483
- }
484
- if (elementUi.style !== 'default') {
485
- element.style = elementUi.style;
486
- }
487
- const confirmUi = elementUi.confirmUi
488
- .confirmValue;
489
- if (confirmUi) {
490
- const confirm = {};
491
- const titleUi = confirmUi.titleUi
492
- .titleValue;
493
- const textUi = confirmUi.textUi.textValue;
494
- const confirmTextUi = confirmUi.confirmTextUi
495
- .confirmValue;
496
- const denyUi = confirmUi.denyUi.denyValue;
497
- const style = confirmUi.style;
498
- if (titleUi) {
499
- confirm.title = {
500
- type: 'plain_text',
501
- text: titleUi.text,
502
- emoji: titleUi.emoji,
503
- };
504
- }
505
- if (textUi) {
506
- confirm.text = {
507
- type: 'plain_text',
508
- text: textUi.text,
509
- emoji: textUi.emoji,
510
- };
511
- }
512
- if (confirmTextUi) {
513
- confirm.confirm = {
514
- type: 'plain_text',
515
- text: confirmTextUi.text,
516
- emoji: confirmTextUi.emoji,
517
- };
518
- }
519
- if (denyUi) {
520
- confirm.deny = {
521
- type: 'plain_text',
522
- text: denyUi.text,
523
- emoji: denyUi.emoji,
524
- };
525
- }
526
- if (style !== 'default') {
527
- confirm.style = style;
528
- }
529
- element.confirm = confirm;
530
- }
531
- elements.push(element);
532
- }
533
- block.elements = elements;
534
- }
535
- }
536
- else if (block.type === 'section') {
537
- const textUi = blockUi.textUi.textValue;
538
- if (textUi) {
539
- const textData = {};
540
- if (textUi.type === 'plainText') {
541
- textData.type = 'plain_text';
542
- textData.emoji = textUi.emoji;
543
- }
544
- else {
545
- textData.type = 'mrkdwn';
546
- textData.verbatim = textUi.verbatim;
547
- }
548
- textData.text = textUi.text;
549
- block.text = textData;
550
- }
551
- else {
552
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Property text must be defined', { itemIndex: i });
553
- }
554
- const fieldsUi = blockUi.fieldsUi
555
- .fieldsValues;
556
- if (fieldsUi) {
557
- const fields = [];
558
- for (const fieldUi of fieldsUi) {
559
- const field = {};
560
- if (fieldUi.type === 'plainText') {
561
- field.type = 'plain_text';
562
- field.emoji = fieldUi.emoji;
563
- }
564
- else {
565
- field.type = 'mrkdwn';
566
- field.verbatim = fieldUi.verbatim;
567
- }
568
- field.text = fieldUi.text;
569
- fields.push(field);
570
- }
571
- if (fields.length > 0) {
572
- block.fields = fields;
573
- }
574
- }
575
- const accessoryUi = blockUi.accessoryUi
576
- .accessoriesValues;
577
- if (accessoryUi) {
578
- const accessory = {};
579
- if (accessoryUi.type === 'button') {
580
- accessory.type = 'button';
581
- accessory.text = {
582
- text: accessoryUi.text,
583
- type: 'plain_text',
584
- emoji: accessoryUi.emoji,
585
- };
586
- if (accessoryUi.url) {
587
- accessory.url = accessoryUi.url;
588
- }
589
- if (accessoryUi.value) {
590
- accessory.value = accessoryUi.value;
591
- }
592
- if (accessoryUi.style !== 'default') {
593
- accessory.style = accessoryUi.style;
594
- }
595
- const confirmUi = accessoryUi.confirmUi
596
- .confirmValue;
597
- if (confirmUi) {
598
- const confirm = {};
599
- const titleUi = confirmUi.titleUi
600
- .titleValue;
601
- const textUiFromConfirm = confirmUi.textUi
602
- .textValue;
603
- const confirmTextUi = confirmUi.confirmTextUi
604
- .confirmValue;
605
- const denyUi = confirmUi.denyUi.denyValue;
606
- const style = confirmUi.style;
607
- if (titleUi) {
608
- confirm.title = {
609
- type: 'plain_text',
610
- text: titleUi.text,
611
- emoji: titleUi.emoji,
612
- };
613
- }
614
- if (textUiFromConfirm) {
615
- confirm.text = {
616
- type: 'plain_text',
617
- text: textUiFromConfirm.text,
618
- emoji: textUiFromConfirm.emoji,
619
- };
620
- }
621
- if (confirmTextUi) {
622
- confirm.confirm = {
623
- type: 'plain_text',
624
- text: confirmTextUi.text,
625
- emoji: confirmTextUi.emoji,
626
- };
627
- }
628
- if (denyUi) {
629
- confirm.deny = {
630
- type: 'plain_text',
631
- text: denyUi.text,
632
- emoji: denyUi.emoji,
633
- };
634
- }
635
- if (style !== 'default') {
636
- confirm.style = style;
637
- }
638
- accessory.confirm = confirm;
639
- }
640
- }
641
- block.accessory = accessory;
642
- }
643
- }
644
- blocks.push(block);
645
- }
646
- body.blocks = blocks;
647
- }
648
- }
649
- else {
650
- const attachmentsJson = this.getNodeParameter('attachmentsJson', i, '');
651
- const blocksJson = this.getNodeParameter('blocksJson', i, []);
652
- if (attachmentsJson !== '' && (0, GenericFunctions_1.validateJSON)(attachmentsJson) === undefined) {
653
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Attachments it is not a valid json', {
654
- itemIndex: i,
655
- });
656
- }
657
- if (blocksJson !== '' && (0, GenericFunctions_1.validateJSON)(blocksJson) === undefined) {
658
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Blocks it is not a valid json', {
659
- itemIndex: i,
660
- });
661
- }
662
- if (attachmentsJson !== '') {
663
- body.attachments = attachmentsJson;
664
- }
665
- if (blocksJson !== '') {
666
- body.blocks = blocksJson;
667
- }
668
- }
669
- const otherOptions = this.getNodeParameter('otherOptions', i);
670
- Object.assign(body, otherOptions);
671
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', `/chat.${action}`, body, qs);
672
- }
673
- if (operation === 'update') {
674
- const channel = this.getNodeParameter('channelId', i);
675
- const text = this.getNodeParameter('text', i);
676
- const ts = this.getNodeParameter('ts', i);
677
- const attachments = this.getNodeParameter('attachments', i, []);
678
- const body = {
679
- channel,
680
- text,
681
- ts,
682
- };
683
- for (const attachment of attachments) {
684
- if (attachment.fields !== undefined) {
685
- if (attachment.fields.item !== undefined) {
686
- attachment.fields = attachment.fields.item;
687
- }
688
- else {
689
- delete attachment.fields;
690
- }
691
- }
692
- }
693
- body.attachments = attachments;
694
- const jsonParameters = this.getNodeParameter('jsonParameters', i, false);
695
- if (jsonParameters) {
696
- const blocksJson = this.getNodeParameter('blocksJson', i, []);
697
- if (blocksJson !== '' && (0, GenericFunctions_1.validateJSON)(blocksJson) === undefined) {
698
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Blocks it is not a valid json', {
699
- itemIndex: i,
700
- });
701
- }
702
- if (blocksJson !== '') {
703
- body.blocks = blocksJson;
704
- }
705
- const attachmentsJson = this.getNodeParameter('attachmentsJson', i, '');
706
- if (attachmentsJson !== '' && (0, GenericFunctions_1.validateJSON)(attachmentsJson) === undefined) {
707
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Attachments it is not a valid json', {
708
- itemIndex: i,
709
- });
710
- }
711
- if (attachmentsJson !== '') {
712
- body.attachments = attachmentsJson;
713
- }
714
- }
715
- const updateFields = this.getNodeParameter('updateFields', i);
716
- Object.assign(body, updateFields);
717
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/chat.update', body, qs);
718
- }
719
- if (operation === 'delete') {
720
- const channel = this.getNodeParameter('channelId', i);
721
- const timestamp = this.getNodeParameter('timestamp', i);
722
- const body = {
723
- channel,
724
- ts: timestamp,
725
- };
726
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/chat.delete', body, qs);
727
- }
728
- if (operation === 'getPermalink') {
729
- const channel = this.getNodeParameter('channelId', i);
730
- const timestamp = this.getNodeParameter('timestamp', i);
731
- const query = {
732
- channel,
733
- message_ts: timestamp,
734
- };
735
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'GET', '/chat.getPermalink', {}, query);
736
- }
737
- }
738
- if (resource === 'reaction') {
739
- const channel = this.getNodeParameter('channelId', i);
740
- const timestamp = this.getNodeParameter('timestamp', i);
741
- if (operation === 'add') {
742
- const name = this.getNodeParameter('name', i);
743
- const body = {
744
- channel,
745
- name,
746
- timestamp,
747
- };
748
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/reactions.add', body, qs);
749
- }
750
- if (operation === 'remove') {
751
- const name = this.getNodeParameter('name', i);
752
- const body = {
753
- channel,
754
- name,
755
- timestamp,
756
- };
757
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/reactions.remove', body, qs);
758
- }
759
- if (operation === 'get') {
760
- qs.channel = channel;
761
- qs.timestamp = timestamp;
762
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'GET', '/reactions.get', {}, qs);
763
- }
764
- }
765
- if (resource === 'star') {
766
- if (operation === 'add') {
767
- const options = this.getNodeParameter('options', i);
768
- const body = {};
769
- if (options.channelId) {
770
- body.channel = options.channelId;
771
- }
772
- if (options.fileId) {
773
- body.file = options.fileId;
774
- }
775
- if (options.fileComment) {
776
- body.file_comment = options.fileComment;
777
- }
778
- if (options.timestamp) {
779
- body.timestamp = options.timestamp;
780
- }
781
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/stars.add', body, qs);
782
- }
783
- if (operation === 'delete') {
784
- const options = this.getNodeParameter('options', i);
785
- const body = {};
786
- if (options.channelId) {
787
- body.channel = options.channelId;
788
- }
789
- if (options.fileId) {
790
- body.file = options.fileId;
791
- }
792
- if (options.fileComment) {
793
- body.file_comment = options.fileComment;
794
- }
795
- if (options.timestamp) {
796
- body.timestamp = options.timestamp;
797
- }
798
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/stars.remove', body, qs);
799
- }
800
- if (operation === 'getAll') {
801
- const returnAll = this.getNodeParameter('returnAll', i);
802
- if (returnAll) {
803
- responseData = await GenericFunctions_1.slackApiRequestAllItems.call(this, 'items', 'GET', '/stars.list', {}, qs);
804
- }
805
- else {
806
- qs.limit = this.getNodeParameter('limit', i);
807
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'GET', '/stars.list', {}, qs);
808
- responseData = responseData.items;
809
- }
810
- }
811
- }
812
- if (resource === 'file') {
813
- if (operation === 'upload') {
814
- const options = this.getNodeParameter('options', i);
815
- const binaryData = this.getNodeParameter('binaryData', i);
816
- const body = {};
817
- if (options.channelIds) {
818
- body.channels = options.channelIds.join(',');
819
- }
820
- if (options.fileName) {
821
- body.filename = options.fileName;
822
- }
823
- if (options.initialComment) {
824
- body.initial_comment = options.initialComment;
825
- }
826
- if (options.threadTs) {
827
- body.thread_ts = options.threadTs;
828
- }
829
- if (options.title) {
830
- body.title = options.title;
831
- }
832
- if (binaryData) {
833
- const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
834
- if (items[i].binary === undefined ||
835
- items[i].binary[binaryPropertyName] === undefined) {
836
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), `No binary data property "${binaryPropertyName}" does not exists on item!`, { itemIndex: i });
837
- }
838
- const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
839
- body.file = {
840
- value: binaryDataBuffer,
841
- options: {
842
- filename: items[i].binary[binaryPropertyName].fileName,
843
- contentType: items[i].binary[binaryPropertyName].mimeType,
844
- },
845
- };
846
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/files.upload', {}, qs, { 'Content-Type': 'multipart/form-data' }, { formData: body });
847
- responseData = responseData.file;
848
- }
849
- else {
850
- const fileContent = this.getNodeParameter('fileContent', i);
851
- body.content = fileContent;
852
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/files.upload', body, qs, { 'Content-Type': 'application/x-www-form-urlencoded' }, { form: body });
853
- responseData = responseData.file;
854
- }
855
- }
856
- if (operation === 'getAll') {
857
- const returnAll = this.getNodeParameter('returnAll', i);
858
- const filters = this.getNodeParameter('filters', i);
859
- if (filters.channelId) {
860
- qs.channel = filters.channelId;
861
- }
862
- if (filters.showFilesHidden) {
863
- qs.show_files_hidden_by_limit = filters.showFilesHidden;
864
- }
865
- if (filters.tsFrom) {
866
- qs.ts_from = filters.tsFrom;
867
- }
868
- if (filters.tsTo) {
869
- qs.ts_to = filters.tsTo;
870
- }
871
- if (filters.types) {
872
- qs.types = filters.types.join(',');
873
- }
874
- if (filters.userId) {
875
- qs.user = filters.userId;
876
- }
877
- if (returnAll) {
878
- responseData = await GenericFunctions_1.slackApiRequestAllItems.call(this, 'files', 'GET', '/files.list', {}, qs);
879
- }
880
- else {
881
- qs.count = this.getNodeParameter('limit', i);
882
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'GET', '/files.list', {}, qs);
883
- responseData = responseData.files;
884
- }
885
- }
886
- if (operation === 'get') {
887
- const fileId = this.getNodeParameter('fileId', i);
888
- qs.file = fileId;
889
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'GET', '/files.info', {}, qs);
890
- responseData = responseData.file;
891
- }
892
- }
893
- if (resource === 'user') {
894
- if (operation === 'info') {
895
- qs.user = this.getNodeParameter('user', i);
896
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'GET', '/users.info', {}, qs);
897
- responseData = responseData.user;
898
- }
899
- if (operation === 'getAll') {
900
- const returnAll = this.getNodeParameter('returnAll', i);
901
- if (returnAll) {
902
- responseData = await GenericFunctions_1.slackApiRequestAllItems.call(this, 'members', 'GET', '/users.list', {}, qs);
903
- }
904
- else {
905
- qs.limit = this.getNodeParameter('limit', i);
906
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'GET', '/users.list', {}, qs);
907
- responseData = responseData.members;
908
- }
909
- }
910
- if (operation === 'getPresence') {
911
- qs.user = this.getNodeParameter('user', i);
912
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'GET', '/users.getPresence', {}, qs);
913
- }
914
- }
915
- if (resource === 'userGroup') {
916
- if (operation === 'create') {
917
- const name = this.getNodeParameter('name', i);
918
- const additionalFields = this.getNodeParameter('additionalFields', i);
919
- const body = {
920
- name,
921
- };
922
- Object.assign(body, additionalFields);
923
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/usergroups.create', body, qs);
924
- responseData = responseData.usergroup;
925
- }
926
- if (operation === 'enable') {
927
- const userGroupId = this.getNodeParameter('userGroupId', i);
928
- const additionalFields = this.getNodeParameter('additionalFields', i);
929
- const body = {
930
- usergroup: userGroupId,
931
- };
932
- Object.assign(body, additionalFields);
933
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/usergroups.enable', body, qs);
934
- responseData = responseData.usergroup;
935
- }
936
- if (operation === 'disable') {
937
- const userGroupId = this.getNodeParameter('userGroupId', i);
938
- const additionalFields = this.getNodeParameter('additionalFields', i);
939
- const body = {
940
- usergroup: userGroupId,
941
- };
942
- Object.assign(body, additionalFields);
943
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/usergroups.disable', body, qs);
944
- responseData = responseData.usergroup;
945
- }
946
- if (operation === 'getAll') {
947
- const returnAll = this.getNodeParameter('returnAll', i);
948
- const additionalFields = this.getNodeParameter('additionalFields', i);
949
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'GET', '/usergroups.list', {}, additionalFields);
950
- responseData = responseData.usergroups;
951
- if (!returnAll) {
952
- const limit = this.getNodeParameter('limit', i);
953
- responseData = responseData.slice(0, limit);
954
- }
955
- }
956
- if (operation === 'update') {
957
- const userGroupId = this.getNodeParameter('userGroupId', i);
958
- const updateFields = this.getNodeParameter('updateFields', i);
959
- const body = {
960
- usergroup: userGroupId,
961
- };
962
- Object.assign(body, updateFields);
963
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/usergroups.update', body, qs);
964
- responseData = responseData.usergroup;
965
- }
966
- }
967
- if (resource === 'userProfile') {
968
- if (operation === 'update') {
969
- const additionalFields = this.getNodeParameter('additionalFields', i);
970
- const timezone = this.getTimezone();
971
- const body = {};
972
- Object.assign(body, additionalFields);
973
- if (body.status_expiration === undefined) {
974
- body.status_expiration = 0;
975
- }
976
- else {
977
- body.status_expiration = moment_1.default.tz(body.status_expiration, timezone).unix();
978
- }
979
- if (body.customFieldUi) {
980
- const customFields = body.customFieldUi
981
- .customFieldValues;
982
- body.fields = {};
983
- for (const customField of customFields) {
984
- body.fields[customField.id] = {
985
- value: customField.value,
986
- alt: customField.alt,
987
- };
988
- }
989
- }
990
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/users.profile.set', { profile: body }, qs);
991
- responseData = responseData.profile;
992
- }
993
- if (operation === 'get') {
994
- const additionalFields = this.getNodeParameter('additionalFields', i);
995
- responseData = await GenericFunctions_1.slackApiRequest.call(this, 'POST', '/users.profile.get', undefined, additionalFields);
996
- responseData = responseData.profile;
997
- }
998
- }
999
- const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(responseData), { itemData: { item: i } });
1000
- returnData.push(...executionData);
1001
- }
1002
- catch (error) {
1003
- if (this.continueOnFail()) {
1004
- returnData.push({ json: { error: error.message } });
1005
- continue;
1006
- }
1007
- throw error;
1008
- }
1009
- }
1010
- return this.prepareOutputData(returnData);
22
+ super(nodeVersions, baseDescription);
1011
23
  }
1012
24
  }
1013
25
  exports.Slack = Slack;