Update operation selection on Slack-Node

This commit is contained in:
Jan Oberhauser 2019-07-14 18:43:58 +02:00
parent d4a4088703
commit c6a55113e3

View file

@ -34,32 +34,85 @@ export class Slack implements INodeType {
],
properties: [
{
displayName: 'Operation',
name: 'operation',
displayName: 'Resource',
name: 'resource',
type: 'options',
options: [
{
name: 'Create Channel',
value: 'channelsCreate',
description: 'Creates a new channel',
name: 'Channel',
value: 'channel',
},
{
name: 'Invite User',
value: 'channelsInvite',
description: 'Invites a user to a channel',
},
{
name: 'Send Message',
value: 'chatPostMessage',
description: 'Posts a message into a channel',
name: 'Message',
value: 'message',
},
],
default: 'chatPostMessage',
default: 'message',
description: 'The resource to operate on.',
},
// ----------------------------------
// operations
// ----------------------------------
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: [
'channel',
],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a new channel',
},
{
name: 'Invite',
value: 'invite',
description: 'Invite a user to a channel',
},
],
default: 'create',
description: 'The operation to perform.',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: [
'message',
],
},
},
options: [
{
name: 'Post',
value: 'post',
description: 'Post a message into a channel',
},
],
default: 'post',
description: 'The operation to perform.',
},
// ----------------------------------
// channelsCreate
// channel
// ----------------------------------
// ----------------------------------
// channel:create
// ----------------------------------
{
displayName: 'Name',
@ -70,7 +123,10 @@ export class Slack implements INodeType {
displayOptions: {
show: {
operation: [
'channelsCreate'
'create'
],
resource: [
'channel',
],
},
},
@ -78,9 +134,8 @@ export class Slack implements INodeType {
description: 'The name of the channel to create.',
},
// ----------------------------------
// channelsInvite
// channel:invite
// ----------------------------------
{
displayName: 'Channel ID',
@ -91,7 +146,10 @@ export class Slack implements INodeType {
displayOptions: {
show: {
operation: [
'channelsInvite'
'invite'
],
resource: [
'channel',
],
},
},
@ -107,7 +165,10 @@ export class Slack implements INodeType {
displayOptions: {
show: {
operation: [
'channelsInvite'
'invite'
],
resource: [
'channel',
],
},
},
@ -116,8 +177,13 @@ export class Slack implements INodeType {
},
// ----------------------------------
// chatPostMessage
// message
// ----------------------------------
// ----------------------------------
// message:post
// ----------------------------------
{
displayName: 'Channel',
@ -128,7 +194,10 @@ export class Slack implements INodeType {
displayOptions: {
show: {
operation: [
'chatPostMessage'
'post'
],
resource: [
'message',
],
},
},
@ -146,7 +215,10 @@ export class Slack implements INodeType {
displayOptions: {
show: {
operation: [
'chatPostMessage'
'post'
],
resource: [
'message',
],
},
},
@ -160,7 +232,10 @@ export class Slack implements INodeType {
displayOptions: {
show: {
operation: [
'chatPostMessage'
'post'
],
resource: [
'message',
],
},
},
@ -173,12 +248,15 @@ export class Slack implements INodeType {
default: '',
displayOptions: {
show: {
operation: [
'chatPostMessage'
],
as_user: [
false
],
operation: [
'post'
],
resource: [
'message',
],
},
},
description: 'Set the bot\'s user name.',
@ -194,7 +272,10 @@ export class Slack implements INodeType {
displayOptions: {
show: {
operation: [
'chatPostMessage'
'post'
],
resource: [
'message',
],
},
},
@ -382,7 +463,10 @@ export class Slack implements INodeType {
displayOptions: {
show: {
operation: [
'chatPostMessage'
'post'
],
resource: [
'message',
],
},
},
@ -399,6 +483,12 @@ export class Slack implements INodeType {
'/as_user': [
false
],
'/operation': [
'post'
],
'/resource': [
'message',
],
},
},
default: '',
@ -413,6 +503,12 @@ export class Slack implements INodeType {
'/as_user': [
false
],
'/operation': [
'post'
],
'/resource': [
'message',
],
},
},
default: '',
@ -478,8 +574,9 @@ export class Slack implements INodeType {
}
const baseUrl = `https://slack.com/api/`;
const operation = this.getNodeParameter('operation', 0) as string;
let requestMethod = 'GET';
let operation: string;
let resource: string;
let requestMethod = 'POST';
// For Post
let body: IDataObject;
@ -491,18 +588,34 @@ export class Slack implements INodeType {
body = {};
qs = {};
if (operation === 'channelsCreate') {
resource = this.getNodeParameter('resource', i) as string;
operation = this.getNodeParameter('operation', i) as string;
if (resource === 'channel') {
if (operation === 'create') {
// ----------------------------------
// channelsCreate
// channel:create
// ----------------------------------
requestMethod = 'POST';
endpoint = 'channels.create';
body.name = this.getNodeParameter('channel', i) as string;
} else if (operation === 'chatPostMessage') {
} else if (operation === 'invite') {
// ----------------------------------
// chatPostMessage
// channel:invite
// ----------------------------------
requestMethod = 'POST';
endpoint = 'channels.invite';
body.channel = this.getNodeParameter('channel', i) as string;
body.user = this.getNodeParameter('username', i) as string;
}
} else if (resource === 'message') {
if (operation === 'post') {
// ----------------------------------
// message:post
// ----------------------------------
requestMethod = 'POST';
@ -536,16 +649,9 @@ export class Slack implements INodeType {
// Add all the other options to the request
const otherOptions = this.getNodeParameter('otherOptions', i) as IDataObject;
Object.assign(body, otherOptions);
} else if (operation === 'channelsInvite') {
// ----------------------------------
// channelsInvite
// ----------------------------------
requestMethod = 'POST';
endpoint = 'channels.invite';
body.channel = this.getNodeParameter('channel', i) as string;
body.user = this.getNodeParameter('username', i) as string;
}
} else {
throw new Error(`The resource "${resource}" is not known!`);
}
const options = {