mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-20 11:22:15 +00:00
feat(Slack Node): Add block support for message updates (#8925)
This commit is contained in:
@@ -859,6 +859,72 @@ export const messageFields: INodeProperties[] = [
|
|||||||
description: 'Timestamp of the message to update',
|
description: 'Timestamp of the message to update',
|
||||||
placeholder: '1663233118.856619',
|
placeholder: '1663233118.856619',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Message Type',
|
||||||
|
name: 'messageType',
|
||||||
|
type: 'options',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: ['update'],
|
||||||
|
resource: ['message'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
description:
|
||||||
|
'Whether to send a simple text message, or use Slack’s Blocks UI builder for more sophisticated messages that include form fields, sections and more',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Simple Text Message',
|
||||||
|
value: 'text',
|
||||||
|
description: 'Supports basic Markdown',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Blocks',
|
||||||
|
value: 'block',
|
||||||
|
description:
|
||||||
|
"Combine text, buttons, form elements, dividers and more in Slack 's visual builder",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Attachments',
|
||||||
|
value: 'attachment',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'text',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Blocks',
|
||||||
|
name: 'blocksUi',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: ['update'],
|
||||||
|
resource: ['message'],
|
||||||
|
messageType: ['block'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
typeOptions: {
|
||||||
|
rows: 3,
|
||||||
|
},
|
||||||
|
description:
|
||||||
|
"Enter the JSON output from Slack's visual Block Kit Builder here. You can then use expressions to add variable content to your blocks. To create blocks, use <a target='_blank' href='https://app.slack.com/block-kit-builder'>Slack's Block Kit Builder</a>",
|
||||||
|
hint: "To create blocks, use <a target='_blank' href='https://app.slack.com/block-kit-builder'>Slack's Block Kit Builder</a>",
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Notification Text',
|
||||||
|
name: 'text',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: ['update'],
|
||||||
|
resource: ['message'],
|
||||||
|
messageType: ['block'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
description:
|
||||||
|
'Fallback text to display in slack notifications. Supports <a href="https://api.slack.com/reference/surfaces/formatting">markdown</a> by default - this can be disabled in "Options".',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Message Text',
|
displayName: 'Message Text',
|
||||||
name: 'text',
|
name: 'text',
|
||||||
@@ -868,6 +934,7 @@ export const messageFields: INodeProperties[] = [
|
|||||||
show: {
|
show: {
|
||||||
resource: ['message'],
|
resource: ['message'],
|
||||||
operation: ['update'],
|
operation: ['update'],
|
||||||
|
messageType: ['text'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -25,12 +25,7 @@ import { fileFields, fileOperations } from './FileDescription';
|
|||||||
import { reactionFields, reactionOperations } from './ReactionDescription';
|
import { reactionFields, reactionOperations } from './ReactionDescription';
|
||||||
import { userGroupFields, userGroupOperations } from './UserGroupDescription';
|
import { userGroupFields, userGroupOperations } from './UserGroupDescription';
|
||||||
import { userFields, userOperations } from './UserDescription';
|
import { userFields, userOperations } from './UserDescription';
|
||||||
import {
|
import { slackApiRequest, slackApiRequestAllItems, getMessageContent } from './GenericFunctions';
|
||||||
slackApiRequest,
|
|
||||||
slackApiRequestAllItems,
|
|
||||||
validateJSON,
|
|
||||||
getMessageContent,
|
|
||||||
} from './GenericFunctions';
|
|
||||||
|
|
||||||
export class SlackV2 implements INodeType {
|
export class SlackV2 implements INodeType {
|
||||||
description: INodeTypeDescription;
|
description: INodeTypeDescription;
|
||||||
@@ -779,6 +774,7 @@ export class SlackV2 implements INodeType {
|
|||||||
if (authentication === 'accessToken' && sendAsUser !== '' && sendAsUser !== undefined) {
|
if (authentication === 'accessToken' && sendAsUser !== '' && sendAsUser !== undefined) {
|
||||||
body.username = sendAsUser;
|
body.username = sendAsUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
||||||
let action = 'postMessage';
|
let action = 'postMessage';
|
||||||
@@ -836,27 +832,15 @@ export class SlackV2 implements INodeType {
|
|||||||
{},
|
{},
|
||||||
{ extractValue: true },
|
{ extractValue: true },
|
||||||
) as string;
|
) as string;
|
||||||
const text = this.getNodeParameter('text', i) as string;
|
|
||||||
const ts = this.getNodeParameter('ts', i)?.toString() as string;
|
const ts = this.getNodeParameter('ts', i)?.toString() as string;
|
||||||
|
const content = getMessageContent.call(this, i, nodeVersion, instanceId);
|
||||||
|
|
||||||
const body: IDataObject = {
|
const body: IDataObject = {
|
||||||
channel,
|
channel,
|
||||||
text,
|
|
||||||
ts,
|
ts,
|
||||||
|
...content,
|
||||||
};
|
};
|
||||||
|
|
||||||
const jsonParameters = this.getNodeParameter('jsonParameters', i, false);
|
|
||||||
if (jsonParameters) {
|
|
||||||
const blocksJson = this.getNodeParameter('blocksJson', i, []) as string;
|
|
||||||
|
|
||||||
if (blocksJson !== '' && validateJSON(blocksJson) === undefined) {
|
|
||||||
throw new NodeOperationError(this.getNode(), 'Blocks it is not a valid json', {
|
|
||||||
itemIndex: i,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (blocksJson !== '') {
|
|
||||||
body.blocks = blocksJson;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Add all the other options to the request
|
// Add all the other options to the request
|
||||||
const updateFields = this.getNodeParameter('updateFields', i);
|
const updateFields = this.getNodeParameter('updateFields', i);
|
||||||
Object.assign(body, updateFields);
|
Object.assign(body, updateFields);
|
||||||
|
|||||||
Reference in New Issue
Block a user