From 9b6f0ee3ee60de106a05b7a6d2289161249da545 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Thu, 7 Jan 2021 02:26:17 -0500 Subject: [PATCH] :zap: Add Ephemeral Message support (#1302) * Add postEphemeral on Slack node * :zap: Add ephemeral option to message:post * :zap: Small fix Co-authored-by: davinerd --- .../nodes/Slack/MessageDescription.ts | 97 ++++++++++++++++++- packages/nodes-base/nodes/Slack/Slack.node.ts | 11 ++- 2 files changed, 106 insertions(+), 2 deletions(-) diff --git a/packages/nodes-base/nodes/Slack/MessageDescription.ts b/packages/nodes-base/nodes/Slack/MessageDescription.ts index 9953441afe..e1fd2046eb 100644 --- a/packages/nodes-base/nodes/Slack/MessageDescription.ts +++ b/packages/nodes-base/nodes/Slack/MessageDescription.ts @@ -1,4 +1,6 @@ -import { INodeProperties } from 'n8n-workflow'; +import { + INodeProperties, +} from 'n8n-workflow'; export const messageOperations = [ { @@ -34,6 +36,25 @@ export const messageFields = [ /* -------------------------------------------------------------------------- */ /* message:post */ /* -------------------------------------------------------------------------- */ + { + displayName: 'Ephemeral', + name: 'ephemeral', + type: 'boolean', + default: false, + displayOptions: { + show: { + operation: [ + 'post', + ], + resource: [ + 'message', + ], + }, + }, + description: `Ephemeral messages behave differently from regular messages on Slack.
+ They disappear when Slack reloads and won’t show up again when Slack is opened in a
+ new browser window or on a different device`, + }, { displayName: 'Channel', name: 'channel', @@ -53,6 +74,28 @@ export const messageFields = [ required: true, description: 'The channel to send the message to.', }, + { + displayName: 'User', + name: 'user', + type: 'string', + default: '', + placeholder: 'User ID', + displayOptions: { + show: { + operation: [ + 'post', + ], + resource: [ + 'message', + ], + ephemeral: [ + true, + ], + }, + }, + required: true, + description: 'The user ID to send the message to.', + }, { displayName: 'Text', name: 'text', @@ -401,6 +444,19 @@ export const messageFields = [ name: 'mrkdwn', type: 'boolean', default: true, + displayOptions: { + show: { + '/operation': [ + 'post', + ], + '/resource': [ + 'message', + ], + '/ephemeral': [ + false, + ], + }, + }, description: 'Use Slack Markdown parsing.', }, { @@ -408,6 +464,19 @@ export const messageFields = [ name: 'reply_broadcast', type: 'boolean', 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.', }, { @@ -415,6 +484,19 @@ export const messageFields = [ name: 'unfurl_links', type: 'boolean', default: false, + displayOptions: { + show: { + '/operation': [ + 'post', + ], + '/resource': [ + 'message', + ], + '/ephemeral': [ + false, + ], + }, + }, description: 'Pass true to enable unfurling of primarily text-based content.', }, { @@ -422,6 +504,19 @@ export const messageFields = [ name: 'unfurl_media', type: 'boolean', default: true, + displayOptions: { + show: { + '/operation': [ + 'post', + ], + '/resource': [ + 'message', + ], + '/ephemeral': [ + false, + ], + }, + }, description: 'Pass false to disable unfurling of media content.', }, ], diff --git a/packages/nodes-base/nodes/Slack/Slack.node.ts b/packages/nodes-base/nodes/Slack/Slack.node.ts index 096b479192..86f0504534 100644 --- a/packages/nodes-base/nodes/Slack/Slack.node.ts +++ b/packages/nodes-base/nodes/Slack/Slack.node.ts @@ -516,12 +516,20 @@ export class Slack implements INodeType { //https://api.slack.com/methods/chat.postMessage if (operation === 'post') { const channel = this.getNodeParameter('channel', i) as string; + const ephemeral = this.getNodeParameter('ephemeral', i) as boolean; const text = this.getNodeParameter('text', i) as string; const body: IDataObject = { channel, text, }; + let action = 'postMessage'; + + if (ephemeral) { + body.user = this.getNodeParameter('user', i) as string; + action = 'postEphemeral'; + } + const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean; if (authentication === 'accessToken') { @@ -752,10 +760,11 @@ export class Slack implements INodeType { body.blocks = blocksJson; } } + // Add all the other options to the request const otherOptions = this.getNodeParameter('otherOptions', i) as IDataObject; Object.assign(body, otherOptions); - responseData = await slackApiRequest.call(this, 'POST', '/chat.postMessage', body, qs); + responseData = await slackApiRequest.call(this, 'POST', `/chat.${action}`, body, qs); } //https://api.slack.com/methods/chat.update if (operation === 'update') {