mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(Slack Node): Restore ability to send text in addition of blocks or attachments
This commit is contained in:
parent
b17d5f9aa0
commit
8669f95736
|
@ -331,6 +331,21 @@ export const messageFields: INodeProperties[] = [
|
||||||
hint: "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: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Notification Text',
|
||||||
|
name: 'text',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: ['post'],
|
||||||
|
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: 'This is a legacy Slack feature. Slack advises to instead use Blocks.',
|
displayName: 'This is a legacy Slack feature. Slack advises to instead use Blocks.',
|
||||||
name: 'noticeAttachments',
|
name: 'noticeAttachments',
|
||||||
|
|
|
@ -756,18 +756,25 @@ export class SlackV2 implements INodeType {
|
||||||
: (this.getNodeParameter('user', i, undefined, {
|
: (this.getNodeParameter('user', i, undefined, {
|
||||||
extractValue: true,
|
extractValue: true,
|
||||||
}) as string);
|
}) as string);
|
||||||
// @ts-ignore
|
|
||||||
if (select === 'user' && this.getNodeParameter('user', i).mode === 'username') {
|
if (
|
||||||
|
select === 'user' &&
|
||||||
|
(this.getNodeParameter('user', i) as IDataObject).mode === 'username'
|
||||||
|
) {
|
||||||
target = target.slice(0, 1) === '@' ? target : `@${target}`;
|
target = target.slice(0, 1) === '@' ? target : `@${target}`;
|
||||||
}
|
}
|
||||||
const { sendAsUser } = this.getNodeParameter('otherOptions', i) as IDataObject;
|
const { sendAsUser } = this.getNodeParameter('otherOptions', i) as IDataObject;
|
||||||
let content: IDataObject = {};
|
let content: IDataObject = {};
|
||||||
|
const text = this.getNodeParameter('text', i, '') as string;
|
||||||
switch (messageType) {
|
switch (messageType) {
|
||||||
case 'text':
|
case 'text':
|
||||||
content = { text: this.getNodeParameter('text', i) as string };
|
content = { text };
|
||||||
break;
|
break;
|
||||||
case 'block':
|
case 'block':
|
||||||
content = JSON.parse(this.getNodeParameter('blocksUi', i) as string);
|
content = JSON.parse(this.getNodeParameter('blocksUi', i) as string);
|
||||||
|
if (text) {
|
||||||
|
content.text = text;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'attachment':
|
case 'attachment':
|
||||||
content = { attachments: this.getNodeParameter('attachments', i) } as IDataObject;
|
content = { attachments: this.getNodeParameter('attachments', i) } as IDataObject;
|
||||||
|
@ -803,8 +810,8 @@ export class SlackV2 implements INodeType {
|
||||||
action = 'postEphemeral';
|
action = 'postEphemeral';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//@ts-ignore
|
|
||||||
const replyValues = otherOptions.thread_ts?.replyValues as IDataObject;
|
const replyValues = (otherOptions.thread_ts as IDataObject)?.replyValues as IDataObject;
|
||||||
Object.assign(body, replyValues);
|
Object.assign(body, replyValues);
|
||||||
delete otherOptions.thread_ts;
|
delete otherOptions.thread_ts;
|
||||||
delete otherOptions.ephemeral;
|
delete otherOptions.ephemeral;
|
||||||
|
@ -879,8 +886,11 @@ export class SlackV2 implements INodeType {
|
||||||
: (this.getNodeParameter('user', i, undefined, {
|
: (this.getNodeParameter('user', i, undefined, {
|
||||||
extractValue: true,
|
extractValue: true,
|
||||||
}) as string);
|
}) as string);
|
||||||
// @ts-ignore
|
|
||||||
if (select === 'user' && this.getNodeParameter('user', i).mode === 'username') {
|
if (
|
||||||
|
select === 'user' &&
|
||||||
|
(this.getNodeParameter('user', i) as IDataObject).mode === 'username'
|
||||||
|
) {
|
||||||
target = target.slice(0, 1) === '@' ? target : `@${target}`;
|
target = target.slice(0, 1) === '@' ? target : `@${target}`;
|
||||||
}
|
}
|
||||||
const timestamp = this.getNodeParameter('timestamp', i)?.toString() as string;
|
const timestamp = this.getNodeParameter('timestamp', i)?.toString() as string;
|
||||||
|
@ -1182,8 +1192,7 @@ export class SlackV2 implements INodeType {
|
||||||
const body: IDataObject = {};
|
const body: IDataObject = {};
|
||||||
let status;
|
let status;
|
||||||
if (options.status) {
|
if (options.status) {
|
||||||
// @ts-ignore
|
status = ((options.status as IDataObject)?.set_status as IDataObject[])[0];
|
||||||
status = options.status?.set_status[0] as IDataObject;
|
|
||||||
if (status.status_expiration === undefined) {
|
if (status.status_expiration === undefined) {
|
||||||
status.status_expiration = 0;
|
status.status_expiration = 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1199,15 +1208,16 @@ export class SlackV2 implements INodeType {
|
||||||
const customFields = (options.customFieldUi as IDataObject)
|
const customFields = (options.customFieldUi as IDataObject)
|
||||||
.customFieldValues as IDataObject[];
|
.customFieldValues as IDataObject[];
|
||||||
|
|
||||||
options.fields = {};
|
const fields: IDataObject = {};
|
||||||
|
|
||||||
for (const customField of customFields) {
|
for (const customField of customFields) {
|
||||||
//@ts-ignore
|
fields[customField.id as string] = {
|
||||||
options.fields[customField.id] = {
|
|
||||||
value: customField.value,
|
value: customField.value,
|
||||||
alt: customField.alt,
|
alt: customField.alt,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
options.fields = fields;
|
||||||
}
|
}
|
||||||
Object.assign(body, options);
|
Object.assign(body, options);
|
||||||
responseData = await slackApiRequest.call(
|
responseData = await slackApiRequest.call(
|
||||||
|
|
Loading…
Reference in a new issue