Move Slack params to other options (#1339)

*  Move Slack params to other options

*  Minor improvements to Slack Node

Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
Iván Ovejero 2021-01-15 06:42:35 -03:00 committed by GitHub
parent 6981438a38
commit 46e9af9646
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 168 deletions

View file

@ -20,6 +20,11 @@ export const messageOperations = [
value: 'post', value: 'post',
description: 'Post a message into a channel', description: 'Post a message into a channel',
}, },
{
name: 'Post (Ephemeral)',
value: 'postEphemeral',
description: 'Post an ephemeral message to a user in channel',
},
{ {
name: 'Update', name: 'Update',
value: 'update', value: 'update',
@ -34,27 +39,8 @@ export const messageOperations = [
export const messageFields = [ export const messageFields = [
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* message:post */ /* message:post/postEphemeral */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{
displayName: 'Ephemeral',
name: 'ephemeral',
type: 'boolean',
default: false,
displayOptions: {
show: {
operation: [
'post',
],
resource: [
'message',
],
},
},
description: `Ephemeral messages behave differently from regular messages on Slack.<br/>
They disappear when Slack reloads and wont show up again when Slack is opened in a <br/>
new browser window or on a different device`,
},
{ {
displayName: 'Channel', displayName: 'Channel',
name: 'channel', name: 'channel',
@ -65,6 +51,7 @@ export const messageFields = [
show: { show: {
operation: [ operation: [
'post', 'post',
'postEphemeral',
], ],
resource: [ resource: [
'message', 'message',
@ -83,14 +70,11 @@ export const messageFields = [
displayOptions: { displayOptions: {
show: { show: {
operation: [ operation: [
'post', 'postEphemeral',
], ],
resource: [ resource: [
'message', 'message',
], ],
ephemeral: [
true,
],
}, },
}, },
required: true, required: true,
@ -108,6 +92,7 @@ export const messageFields = [
show: { show: {
operation: [ operation: [
'post', 'post',
'postEphemeral',
], ],
resource: [ resource: [
'message', 'message',
@ -116,46 +101,6 @@ export const messageFields = [
}, },
description: 'The text to send.', description: 'The text to send.',
}, },
{
displayName: 'As User',
name: 'as_user',
type: 'boolean',
default: false,
displayOptions: {
show: {
authentication: [
'accessToken',
],
operation: [
'post',
],
resource: [
'message',
],
},
},
description: 'Post the message as authenticated user instead of bot. Works only with user token.',
},
{
displayName: 'User Name',
name: 'username',
type: 'string',
default: '',
displayOptions: {
show: {
as_user: [
false,
],
operation: [
'post',
],
resource: [
'message',
],
},
},
description: 'Set the bot\'s user name. This field will be ignored if you are using a user token.',
},
{ {
displayName: 'JSON parameters', displayName: 'JSON parameters',
name: 'jsonParameters', name: 'jsonParameters',
@ -165,6 +110,7 @@ export const messageFields = [
show: { show: {
operation: [ operation: [
'post', 'post',
'postEphemeral',
], ],
resource: [ resource: [
'message', 'message',
@ -184,6 +130,7 @@ export const messageFields = [
show: { show: {
operation: [ operation: [
'post', 'post',
'postEphemeral',
], ],
resource: [ resource: [
'message', 'message',
@ -375,6 +322,7 @@ export const messageFields = [
show: { show: {
operation: [ operation: [
'post', 'post',
'postEphemeral',
], ],
resource: [ resource: [
'message', 'message',
@ -389,19 +337,6 @@ export const messageFields = [
displayName: 'Icon Emoji', displayName: 'Icon Emoji',
name: 'icon_emoji', name: 'icon_emoji',
type: 'string', type: 'string',
displayOptions: {
show: {
'/as_user': [
false,
],
'/operation': [
'post',
],
'/resource': [
'message',
],
},
},
default: '', default: '',
description: 'Emoji to use as the icon for this message. Overrides icon_url.', description: 'Emoji to use as the icon for this message. Overrides icon_url.',
}, },
@ -409,19 +344,6 @@ export const messageFields = [
displayName: 'Icon URL', displayName: 'Icon URL',
name: 'icon_url', name: 'icon_url',
type: 'string', type: 'string',
displayOptions: {
show: {
'/as_user': [
false,
],
'/operation': [
'post',
],
'/resource': [
'message',
],
},
},
default: '', default: '',
description: 'URL to an image to use as the icon for this message.', description: 'URL to an image to use as the icon for this message.',
}, },
@ -444,19 +366,6 @@ export const messageFields = [
name: 'mrkdwn', name: 'mrkdwn',
type: 'boolean', type: 'boolean',
default: true, default: true,
displayOptions: {
show: {
'/operation': [
'post',
],
'/resource': [
'message',
],
'/ephemeral': [
false,
],
},
},
description: 'Use Slack Markdown parsing.', description: 'Use Slack Markdown parsing.',
}, },
{ {
@ -464,19 +373,6 @@ export const messageFields = [
name: 'reply_broadcast', name: 'reply_broadcast',
type: 'boolean', type: 'boolean',
default: false, default: false,
displayOptions: {
show: {
'/operation': [
'post',
],
'/resource': [
'message',
],
'/ephemeral': [
false,
],
},
},
description: 'Used in conjunction with thread_ts and indicates whether reply should be made visible to everyone in the channel or conversation.', description: 'Used in conjunction with thread_ts and indicates whether reply should be made visible to everyone in the channel or conversation.',
}, },
{ {
@ -484,19 +380,6 @@ export const messageFields = [
name: 'unfurl_links', name: 'unfurl_links',
type: 'boolean', type: 'boolean',
default: false, default: false,
displayOptions: {
show: {
'/operation': [
'post',
],
'/resource': [
'message',
],
'/ephemeral': [
false,
],
},
},
description: 'Pass true to enable unfurling of primarily text-based content.', description: 'Pass true to enable unfurling of primarily text-based content.',
}, },
{ {
@ -504,20 +387,21 @@ export const messageFields = [
name: 'unfurl_media', name: 'unfurl_media',
type: 'boolean', type: 'boolean',
default: true, default: true,
description: 'Pass false to disable unfurling of media content.',
},
{
displayName: 'Send as User',
name: 'sendAsUser',
type: 'string',
displayOptions: { displayOptions: {
show: { show: {
'/operation': [ '/authentication': [
'post', 'accessToken',
],
'/resource': [
'message',
],
'/ephemeral': [
false,
], ],
}, },
}, },
description: 'Pass false to disable unfurling of media content.', default: '',
description: 'The message will be sent from this username (i.e. as if this individual sent the message).',
}, },
], ],
}, },
@ -582,26 +466,6 @@ export const messageFields = [
}, },
description: `Timestamp of the message to be updated.`, description: `Timestamp of the message to be updated.`,
}, },
{
displayName: 'As User',
name: 'as_user',
type: 'boolean',
default: false,
displayOptions: {
show: {
authentication: [
'accessToken',
],
operation: [
'update',
],
resource: [
'message',
],
},
},
description: 'Pass true to update the message as the authed user. Works only with user token.',
},
{ {
displayName: 'Update Fields', displayName: 'Update Fields',
name: 'updateFields', name: 'updateFields',

View file

@ -514,9 +514,9 @@ export class Slack implements INodeType {
} }
if (resource === 'message') { if (resource === 'message') {
//https://api.slack.com/methods/chat.postMessage //https://api.slack.com/methods/chat.postMessage
if (operation === 'post') { if (['post', 'postEphemeral'].includes(operation)) {
const channel = this.getNodeParameter('channel', i) as string; const channel = this.getNodeParameter('channel', i) as string;
const ephemeral = this.getNodeParameter('ephemeral', i) as boolean; const { sendAsUser } = this.getNodeParameter('otherOptions', i) as IDataObject;
const text = this.getNodeParameter('text', i) as string; const text = this.getNodeParameter('text', i) as string;
const body: IDataObject = { const body: IDataObject = {
channel, channel,
@ -525,19 +525,15 @@ export class Slack implements INodeType {
let action = 'postMessage'; let action = 'postMessage';
if (ephemeral) { if (operation === 'postEphemeral') {
body.user = this.getNodeParameter('user', i) as string; body.user = this.getNodeParameter('user', i) as string;
action = 'postEphemeral'; action = 'postEphemeral';
} }
const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean; const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
if (authentication === 'accessToken') { if (authentication === 'accessToken' && sendAsUser !== '') {
body.as_user = this.getNodeParameter('as_user', i) as boolean; body.username = sendAsUser;
}
if (body.as_user === false) {
body.username = this.getNodeParameter('username', i) as string;
delete body.as_user;
} }
if (!jsonParameters) { if (!jsonParameters) {