Skip to content

Commit

Permalink
fix(Slack Node): Restore ability to send text in addition of blocks o…
Browse files Browse the repository at this point in the history
…r attachments
  • Loading branch information
michael-radency authored Apr 28, 2023
1 parent b17d5f9 commit 8669f95
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
15 changes: 15 additions & 0 deletions packages/nodes-base/nodes/Slack/V2/MessageDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>",
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.',
name: 'noticeAttachments',
Expand Down
34 changes: 22 additions & 12 deletions packages/nodes-base/nodes/Slack/V2/SlackV2.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -756,18 +756,25 @@ export class SlackV2 implements INodeType {
: (this.getNodeParameter('user', i, undefined, {
extractValue: true,
}) 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}`;
}
const { sendAsUser } = this.getNodeParameter('otherOptions', i) as IDataObject;
let content: IDataObject = {};
const text = this.getNodeParameter('text', i, '') as string;
switch (messageType) {
case 'text':
content = { text: this.getNodeParameter('text', i) as string };
content = { text };
break;
case 'block':
content = JSON.parse(this.getNodeParameter('blocksUi', i) as string);
if (text) {
content.text = text;
}
break;
case 'attachment':
content = { attachments: this.getNodeParameter('attachments', i) } as IDataObject;
Expand Down Expand Up @@ -803,8 +810,8 @@ export class SlackV2 implements INodeType {
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);
delete otherOptions.thread_ts;
delete otherOptions.ephemeral;
Expand Down Expand Up @@ -879,8 +886,11 @@ export class SlackV2 implements INodeType {
: (this.getNodeParameter('user', i, undefined, {
extractValue: true,
}) 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}`;
}
const timestamp = this.getNodeParameter('timestamp', i)?.toString() as string;
Expand Down Expand Up @@ -1182,8 +1192,7 @@ export class SlackV2 implements INodeType {
const body: IDataObject = {};
let status;
if (options.status) {
// @ts-ignore
status = options.status?.set_status[0] as IDataObject;
status = ((options.status as IDataObject)?.set_status as IDataObject[])[0];
if (status.status_expiration === undefined) {
status.status_expiration = 0;
} else {
Expand All @@ -1199,15 +1208,16 @@ export class SlackV2 implements INodeType {
const customFields = (options.customFieldUi as IDataObject)
.customFieldValues as IDataObject[];

options.fields = {};
const fields: IDataObject = {};

for (const customField of customFields) {
//@ts-ignore
options.fields[customField.id] = {
fields[customField.id as string] = {
value: customField.value,
alt: customField.alt,
};
}

options.fields = fields;
}
Object.assign(body, options);
responseData = await slackApiRequest.call(
Expand Down

0 comments on commit 8669f95

Please sign in to comment.