diff --git a/packages/nodes-base/credentials/SlackOAuth2Api.credentials.ts b/packages/nodes-base/credentials/SlackOAuth2Api.credentials.ts index 8107aad016..2a97a8dac7 100644 --- a/packages/nodes-base/credentials/SlackOAuth2Api.credentials.ts +++ b/packages/nodes-base/credentials/SlackOAuth2Api.credentials.ts @@ -17,6 +17,7 @@ const userScopes = [ 'usergroups:read', 'users.profile:read', 'users.profile:write', + 'users:read', ]; export class SlackOAuth2Api implements ICredentialType { diff --git a/packages/nodes-base/nodes/Slack/Slack.node.ts b/packages/nodes-base/nodes/Slack/Slack.node.ts index b45548afa9..67c58170dc 100644 --- a/packages/nodes-base/nodes/Slack/Slack.node.ts +++ b/packages/nodes-base/nodes/Slack/Slack.node.ts @@ -1,11 +1,8 @@ import { IExecuteFunctions } from 'n8n-core'; import { - ICredentialsDecrypted, - ICredentialTestFunctions, IDataObject, ILoadOptionsFunctions, - INodeCredentialTestResult, INodeExecutionData, INodePropertyOptions, INodeType, @@ -15,23 +12,14 @@ import { } from 'n8n-workflow'; import { channelFields, channelOperations } from './ChannelDescription'; - import { messageFields, messageOperations } from './MessageDescription'; - import { starFields, starOperations } from './StarDescription'; - import { fileFields, fileOperations } from './FileDescription'; - import { reactionFields, reactionOperations } from './ReactionDescription'; - import { userGroupFields, userGroupOperations } from './UserGroupDescription'; - import { userFields, userOperations } from './UserDescription'; - import { userProfileFields, userProfileOperations } from './UserProfileDescription'; - import { slackApiRequest, slackApiRequestAllItems, validateJSON } from './GenericFunctions'; - import { IAttachment } from './MessageInterface'; import moment from 'moment'; @@ -1206,6 +1194,24 @@ export class Slack implements INodeType { responseData = await slackApiRequest.call(this, 'GET', '/users.info', {}, qs); responseData = responseData.user; } + //https://api.slack.com/methods/users.list + if (operation === 'getAll') { + const returnAll = this.getNodeParameter('returnAll', i) as boolean; + if (returnAll === true) { + responseData = await slackApiRequestAllItems.call( + this, + 'members', + 'GET', + '/users.list', + {}, + qs, + ); + } else { + qs.limit = this.getNodeParameter('limit', i) as number; + responseData = await slackApiRequest.call(this, 'GET', '/users.list', {}, qs); + responseData = responseData.members; + } + } //https://api.slack.com/methods/users.getPresence if (operation === 'getPresence') { qs.user = this.getNodeParameter('user', i) as string; diff --git a/packages/nodes-base/nodes/Slack/UserDescription.ts b/packages/nodes-base/nodes/Slack/UserDescription.ts index c22168a055..63c6badeff 100644 --- a/packages/nodes-base/nodes/Slack/UserDescription.ts +++ b/packages/nodes-base/nodes/Slack/UserDescription.ts @@ -18,6 +18,12 @@ export const userOperations: INodeProperties[] = [ description: 'Get information about a user', action: 'Get information about a user', }, + { + name: 'Get Many', + value: 'getAll', + description: 'Get a list of many users', + action: 'Get many users', + }, { name: 'Get Presence', value: 'getPresence', @@ -50,6 +56,40 @@ export const userFields: INodeProperties[] = [ required: true, description: 'The ID of the user to get information about', }, + /* -------------------------------------------------------------------------- */ + /* user:getAll */ + /* -------------------------------------------------------------------------- */ + { + displayName: 'Return All', + name: 'returnAll', + type: 'boolean', + displayOptions: { + show: { + resource: ['user'], + operation: ['getAll'], + }, + }, + default: false, + description: 'Whether to return all results or only up to a given limit', + }, + { + displayName: 'Limit', + name: 'limit', + type: 'number', + displayOptions: { + show: { + resource: ['user'], + operation: ['getAll'], + returnAll: [false], + }, + }, + typeOptions: { + minValue: 1, + maxValue: 100, + }, + default: 50, + description: 'Max number of results to return', + }, /* -------------------------------------------------------------------------- */ /* user:getPresence */ diff --git a/packages/nodes-base/nodes/Slack/UserProfileDescription.ts b/packages/nodes-base/nodes/Slack/UserProfileDescription.ts index 9b1dd702bd..b5794ba443 100644 --- a/packages/nodes-base/nodes/Slack/UserProfileDescription.ts +++ b/packages/nodes-base/nodes/Slack/UserProfileDescription.ts @@ -1,5 +1,4 @@ import { INodeProperties } from 'n8n-workflow'; -import { text } from 'express'; export const userProfileOperations: INodeProperties[] = [ {