n8n
Version:
n8n Workflow Automation Tool
123 lines • 5.67 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");
const slack_operations_1 = require("./slack-operations");
let SlackIntegration = class SlackIntegration extends agent_chat_integration_1.AgentChatIntegration {
constructor() {
super(...arguments);
this.type = 'slack';
this.credentialTypes = ['slackApi'];
this.displayLabel = 'Slack';
this.displayIcon = 'slack';
this.builderGuidance = {
capabilities: [
'Receive Slack mentions and messages as agent triggers.',
'Respond in the latest Slack thread, DM, or channel conversation context.',
'Send DMs and channel messages, search users/channels, and add emoji reactions.',
'Render rich interaction cards in Slack messages.',
],
useIntegrationWhen: [
'The agent should be chatted with from Slack, invoked with @mentions, or keep conversing in Slack threads.',
'The agent needs Slack message context, user/channel lookup, DMs, channel messages, emoji reactions, or rich UI in Slack.',
'The agent should communicate as the connected Slack bot rather than merely call Slack as a backend API.',
],
useNodeToolWhen: [
'Slack is only a backend API step in a broader task and the agent does not need Slack conversation context.',
'The user asks for a one-off Slack operation from another trigger and does not need the agent connected as a Slack chat surface.',
],
};
this.supportedComponents = [
'section',
'button',
'select',
'radio_select',
'divider',
'image',
'fields',
];
this.contextQueries = [
'get_current_message_context',
'get_current_subject',
'get_current_user',
'get_current_channel_info',
'get_user',
'get_channel_info',
'search_users',
'search_channels',
];
this.actions = [
'respond',
'send_dm',
'send_channel_message',
'add_reaction',
];
}
async executeContextQuery(params) {
return await (0, slack_operations_1.executeSlackContextQuery)({
chat: params.chat,
query: params.query,
input: params.input,
});
}
async executeAction(params) {
return await (0, slack_operations_1.executeSlackAction)({
chat: params.chat,
descriptor: params.descriptor,
action: params.action,
input: params.input,
currentMessageContext: params.currentMessageContext,
});
}
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) {
const token = typeof credential.accessToken === 'string' && credential.accessToken
? credential.accessToken
: undefined;
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