Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding blocks to slack message update #2182

Merged
merged 16 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions packages/cli/src/CredentialsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */

import { Credentials, NodeExecuteFunctions } from 'n8n-core';

// eslint-disable-next-line import/no-extraneous-dependencies
import { get } from 'lodash';
import { NodeVersionedType } from 'n8n-nodes-base';

import {
Expand Down Expand Up @@ -633,8 +634,10 @@ export class CredentialsHelper extends ICredentialsHelper {
mode,
);

let response: INodeExecutionData[][] | null | undefined;

try {
await routingNode.runNode(
response = await routingNode.runNode(
inputData,
runIndex,
nodeTypeCopy,
Expand Down Expand Up @@ -683,6 +686,24 @@ export class CredentialsHelper extends ICredentialsHelper {
};
}

if (
credentialTestFunction.testRequest.rules &&
Array.isArray(credentialTestFunction.testRequest.rules)
) {
// Special testing rules are defined so check all in order
for (const rule of credentialTestFunction.testRequest.rules) {
if (rule.type === 'responseSuccessBody') {
const responseData = response![0][0].json;
if (get(responseData, rule.properties.key) === rule.properties.value) {
return {
status: 'Error',
message: rule.properties.message,
};
}
}
}
}

return {
status: 'OK',
message: 'Connection successful!',
Expand Down
26 changes: 25 additions & 1 deletion packages/nodes-base/credentials/SlackApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {
IAuthenticateBearer,
IAuthenticateQueryAuth,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';


export class SlackApi implements ICredentialType {
name = 'slackApi';
displayName = 'Slack API';
Expand All @@ -17,4 +19,26 @@ export class SlackApi implements ICredentialType {
required: true,
},
];
authenticate: IAuthenticateBearer = {
type: 'bearer',
properties: {
tokenPropertyName: 'accessToken',
},
};
test: ICredentialTestRequest = {
request: {
baseURL: 'https://slack.com',
url: '/api/users.profile.get',
},
rules: [
{
type: 'responseSuccessBody',
properties: {
key: 'ok',
value: false,
message: 'Invalid access token',
},
},
],
};
}
Loading