mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat(Slack Node): Add option to include link to workflow in Slack node (#6611)
* feat(Slack Node): Add “automated by” message to Slack node’s post message Signed-off-by: Oleg Ivaniv <me@olegivaniv.com> * Pass instanceBaseUrl to node context Signed-off-by: Oleg Ivaniv <me@olegivaniv.com> * Move `includeLinkToWorkflow` to options Signed-off-by: Oleg Ivaniv <me@olegivaniv.com> * keep "includeLinkToWorkflow" hidden * Only append the message for version 2.1 and up Signed-off-by: Oleg Ivaniv <me@olegivaniv.com> --------- Signed-off-by: Oleg Ivaniv <me@olegivaniv.com> Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
This commit is contained in:
@@ -7,7 +7,7 @@ import type {
|
||||
IOAuth2Options,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
import { NodeOperationError, jsonParse } from 'n8n-workflow';
|
||||
|
||||
import get from 'lodash/get';
|
||||
|
||||
@@ -130,6 +130,64 @@ export async function slackApiRequestAllItems(
|
||||
return returnData;
|
||||
}
|
||||
|
||||
export function getMessageContent(
|
||||
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
|
||||
i: number,
|
||||
) {
|
||||
const nodeVersion = this.getNode().typeVersion;
|
||||
|
||||
const includeLinkToWorkflow = this.getNodeParameter(
|
||||
'otherOptions.includeLinkToWorkflow',
|
||||
i,
|
||||
nodeVersion >= 2.1 ? true : false,
|
||||
) as IDataObject;
|
||||
|
||||
const { id } = this.getWorkflow();
|
||||
const automatedMessage = `_Automated with this <${this.getInstanceBaseUrl()}workflow/${id}|n8n workflow>_`;
|
||||
const messageType = this.getNodeParameter('messageType', i) as string;
|
||||
|
||||
let content: IDataObject = {};
|
||||
const text = this.getNodeParameter('text', i, '') as string;
|
||||
switch (messageType) {
|
||||
case 'text':
|
||||
content = {
|
||||
text: includeLinkToWorkflow ? `${text}\n${automatedMessage}` : text,
|
||||
};
|
||||
break;
|
||||
case 'block':
|
||||
content = jsonParse(this.getNodeParameter('blocksUi', i) as string);
|
||||
|
||||
if (includeLinkToWorkflow && Array.isArray(content.blocks)) {
|
||||
content.blocks.push({
|
||||
type: 'section',
|
||||
text: {
|
||||
type: 'mrkdwn',
|
||||
text: automatedMessage,
|
||||
},
|
||||
});
|
||||
}
|
||||
if (text) {
|
||||
content.text = text;
|
||||
}
|
||||
break;
|
||||
case 'attachment':
|
||||
content = { attachments: this.getNodeParameter('attachments', i) } as IDataObject;
|
||||
if (includeLinkToWorkflow && Array.isArray(content.attachments)) {
|
||||
content.attachments.push({
|
||||
text: automatedMessage,
|
||||
});
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`The message type "${messageType}" is not known!`,
|
||||
);
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
// tslint:disable-next-line:no-any
|
||||
export function validateJSON(json: string | undefined): any {
|
||||
let result;
|
||||
|
||||
Reference in New Issue
Block a user