n8n
Version:
n8n Workflow Automation Tool
81 lines • 3.74 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SlackIntegration = void 0;
const di_1 = require("@n8n/di");
const agent_chat_integration_1 = require("../agent-chat-integration");
const esm_loader_1 = require("../esm-loader");
let SlackIntegration = class SlackIntegration extends agent_chat_integration_1.AgentChatIntegration {
constructor() {
super(...arguments);
this.type = 'slack';
this.credentialTypes = ['slackApi', 'slackOAuth2Api'];
this.displayLabel = 'Slack';
this.displayIcon = 'slack';
this.supportedComponents = [
'section',
'button',
'select',
'radio_select',
'divider',
'image',
'fields',
];
}
async createAdapter(ctx) {
const botToken = this.extractBotToken(ctx.credential);
const signingSecret = this.extractSigningSecret(ctx.credential);
const { createSlackAdapter } = await (0, esm_loader_1.loadSlackAdapter)();
return createSlackAdapter({ botToken, signingSecret });
}
handleUnauthenticatedWebhook(body) {
if (!body || typeof body !== 'object')
return undefined;
const evt = body;
if (evt.type === 'url_verification' && typeof evt.challenge === 'string') {
return { status: 200, body: { challenge: evt.challenge } };
}
return undefined;
}
extractBotToken(credential) {
let token;
if (typeof credential.accessToken === 'string' && credential.accessToken) {
token = credential.accessToken;
}
if (!token) {
const tokenData = credential.oauthTokenData;
const oauthToken = tokenData?.access_token ?? tokenData?.accessToken;
if (typeof oauthToken === 'string' && oauthToken) {
token = oauthToken;
}
}
if (!token) {
throw new Error('Could not extract a bot token from the Slack credential. ' +
'Please ensure the credential has a valid access token.');
}
if (!token.startsWith('xoxb-')) {
const prefix = token.split('-')[0] ?? 'unknown';
throw new Error(`The Slack credential contains a "${prefix}-" token, but agent integrations require a Bot User OAuth Token ("xoxb-"). ` +
'You can find this in your Slack app under OAuth & Permissions → Bot User OAuth Token.');
}
return token;
}
extractSigningSecret(credential) {
const secret = credential.signatureSecret;
if (typeof secret === 'string' && secret) {
return secret;
}
throw new Error('The Slack credential is missing a signing secret, which is required for agent integrations. ' +
'Edit the credential and add your Slack app\'s "Signing Secret" (found under Basic Information in the Slack API dashboard).');
}
};
exports.SlackIntegration = SlackIntegration;
exports.SlackIntegration = SlackIntegration = __decorate([
(0, di_1.Service)()
], SlackIntegration);
//# sourceMappingURL=slack-integration.js.map