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