mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
✨ Feature/slack node extended (#1239)
* Added reaction method to message * Increased limit for channels on getChannels, removed unused fields in the code * Using own operation for reactions * Registering reaction fields and operations * Added Operation "Reaction" to Slack.node.ts * Fixing variable name for emoji * now removing reaction on "remove" instead of "add" * Using GET for reactions.get and passing arguments as query * Added members operation * Fixed typo in timestamp * Added user.info and user.getPresence * Fixed: wrong operation name * ⚡ Improvements to #1238 * ⚡ Add field resolve data when retrieving channel members * ⚡ Minor improvements to Slack-Node Co-authored-by: Andreas Scherren <ascherren@brightfuture.de> Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
@@ -32,6 +32,16 @@ import {
|
||||
fileOperations,
|
||||
} from './FileDescription';
|
||||
|
||||
import {
|
||||
reactionFields,
|
||||
reactionOperations,
|
||||
} from './ReactionDescription';
|
||||
|
||||
import {
|
||||
userFields,
|
||||
userOperations,
|
||||
} from './UserDescription';
|
||||
|
||||
import {
|
||||
userProfileFields,
|
||||
userProfileOperations,
|
||||
@@ -46,6 +56,7 @@ import {
|
||||
import {
|
||||
IAttachment,
|
||||
} from './MessageInterface';
|
||||
|
||||
import moment = require('moment');
|
||||
|
||||
interface Attachment {
|
||||
@@ -163,10 +174,18 @@ export class Slack implements INodeType {
|
||||
name: 'Message',
|
||||
value: 'message',
|
||||
},
|
||||
{
|
||||
name: 'Reaction',
|
||||
value: 'reaction',
|
||||
},
|
||||
{
|
||||
name: 'Star',
|
||||
value: 'star',
|
||||
},
|
||||
{
|
||||
name: 'User',
|
||||
value: 'user',
|
||||
},
|
||||
{
|
||||
name: 'User Profile',
|
||||
value: 'userProfile',
|
||||
@@ -184,6 +203,10 @@ export class Slack implements INodeType {
|
||||
...starFields,
|
||||
...fileOperations,
|
||||
...fileFields,
|
||||
...reactionOperations,
|
||||
...reactionFields,
|
||||
...userOperations,
|
||||
...userFields,
|
||||
...userProfileOperations,
|
||||
...userProfileFields,
|
||||
],
|
||||
@@ -217,7 +240,7 @@ export class Slack implements INodeType {
|
||||
// select them easily
|
||||
async getChannels(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const qs = { types: 'public_channel,private_channel' };
|
||||
const qs = { types: 'public_channel,private_channel', limit: 1000 };
|
||||
const channels = await slackApiRequestAllItems.call(this, 'channels', 'GET', '/conversations.list', {}, qs);
|
||||
for (const channel of channels) {
|
||||
const channelName = channel.name;
|
||||
@@ -265,7 +288,7 @@ export class Slack implements INodeType {
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
responseData = { error: 'Resource ' + resource + ' / operation ' + operation + ' not found!'};
|
||||
responseData = { error: 'Resource ' + resource + ' / operation ' + operation + ' not found!' };
|
||||
qs = {};
|
||||
if (resource === 'channel') {
|
||||
//https://api.slack.com/methods/conversations.archive
|
||||
@@ -383,6 +406,29 @@ export class Slack implements INodeType {
|
||||
};
|
||||
responseData = await slackApiRequest.call(this, 'POST', '/conversations.leave', body, qs);
|
||||
}
|
||||
//https://api.slack.com/methods/conversations.members
|
||||
if (operation === 'member') {
|
||||
const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
|
||||
const resolveData = this.getNodeParameter('resolveData', 0) as boolean;
|
||||
qs.channel = this.getNodeParameter('channelId', i) as string;
|
||||
if (returnAll) {
|
||||
responseData = await slackApiRequestAllItems.call(this, 'members', 'GET', '/conversations.members', {}, qs);
|
||||
responseData = responseData.map((member: string) => ({ member }));
|
||||
} else {
|
||||
qs.limit = this.getNodeParameter('limit', i) as number;
|
||||
responseData = await slackApiRequest.call(this, 'GET', '/conversations.members', {}, qs);
|
||||
responseData = responseData.members.map((member: string) => ({ member }));
|
||||
}
|
||||
|
||||
if (resolveData) {
|
||||
const data: IDataObject[] = [];
|
||||
for (const { member } of responseData) {
|
||||
const { user } = await slackApiRequest.call(this, 'GET', '/users.info', {}, { user: member });
|
||||
data.push(user);
|
||||
}
|
||||
responseData = data;
|
||||
}
|
||||
}
|
||||
//https://api.slack.com/methods/conversations.open
|
||||
if (operation === 'open') {
|
||||
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||
@@ -745,6 +791,36 @@ export class Slack implements INodeType {
|
||||
responseData = await slackApiRequest.call(this, 'POST', '/chat.update', body, qs);
|
||||
}
|
||||
}
|
||||
if (resource === 'reaction') {
|
||||
const channel = this.getNodeParameter('channelId', i) as string;
|
||||
const timestamp = this.getNodeParameter('timestamp', i) as string;
|
||||
//https://api.slack.com/methods/reactions.add
|
||||
if (operation === 'add') {
|
||||
const name = this.getNodeParameter('name', i) as string;
|
||||
const body: IDataObject = {
|
||||
channel,
|
||||
name,
|
||||
timestamp,
|
||||
};
|
||||
responseData = await slackApiRequest.call(this, 'POST', '/reactions.add', body, qs);
|
||||
}
|
||||
//https://api.slack.com/methods/reactions.remove
|
||||
if (operation === 'remove') {
|
||||
const name = this.getNodeParameter('name', i) as string;
|
||||
const body: IDataObject = {
|
||||
channel,
|
||||
name,
|
||||
timestamp,
|
||||
};
|
||||
responseData = await slackApiRequest.call(this, 'POST', '/reactions.remove', body, qs);
|
||||
}
|
||||
//https://api.slack.com/methods/reactions.get
|
||||
if (operation === 'get') {
|
||||
qs.channel = channel;
|
||||
qs.timestamp = timestamp;
|
||||
responseData = await slackApiRequest.call(this, 'GET', '/reactions.get', {}, qs);
|
||||
}
|
||||
}
|
||||
if (resource === 'star') {
|
||||
//https://api.slack.com/methods/stars.add
|
||||
if (operation === 'add') {
|
||||
@@ -879,6 +955,19 @@ export class Slack implements INodeType {
|
||||
responseData = responseData.file;
|
||||
}
|
||||
}
|
||||
if (resource === 'user') {
|
||||
//https://api.slack.com/methods/users.info
|
||||
if (operation === 'info') {
|
||||
qs.user = this.getNodeParameter('user', i) as string;
|
||||
responseData = await slackApiRequest.call(this, 'GET', '/users.info', {}, qs);
|
||||
responseData = responseData.user;
|
||||
}
|
||||
//https://api.slack.com/methods/users.getPresence
|
||||
if (operation === 'getPresence') {
|
||||
qs.user = this.getNodeParameter('user', i) as string;
|
||||
responseData = await slackApiRequest.call(this, 'GET', '/users.getPresence', {}, qs);
|
||||
}
|
||||
}
|
||||
if (resource === 'userProfile') {
|
||||
//https://api.slack.com/methods/users.profile.set
|
||||
if (operation === 'update') {
|
||||
|
||||
Reference in New Issue
Block a user