UNPKG

n8n-nodes-discord

Version:

nodes to trigger workflows from Discord or send interactive messages. Uses the components API which allows to create dialogs (e.g. attach buttons and wait for the user to click on them)

89 lines 3.59 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Discord = void 0; const Discord_node_options_1 = require("./Discord.node.options"); const bot_1 = __importDefault(require("./bot")); const helpers_1 = require("./bot/helpers"); if (!process.send) (0, bot_1.default)(); const nodeDescription = { displayName: 'Discord Send', name: 'discord', group: ['discord'], version: 1, description: 'Sends messages, embeds and prompts to Discord', defaults: { name: 'Discord Send', }, icon: 'file:discord.svg', inputs: ['main'], outputs: ['main'], credentials: [ { name: 'discordApi', required: true, }, ], properties: Discord_node_options_1.options, }; class Discord { constructor() { this.description = nodeDescription; this.methods = { loadOptions: { async getChannels() { return await (0, helpers_1.getChannels)(this).catch((e) => e); }, async getRoles() { return await (0, helpers_1.getRoles)(this).catch((e) => e); }, }, }; } async execute() { const executionId = this.getExecutionId(); const returnData = []; const credentials = (await this.getCredentials('discordApi').catch((e) => e)); await (0, helpers_1.connection)(credentials).catch((e) => { throw new Error(e); }); const items = this.getInputData(); for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { const nodeParameters = {}; Object.keys(this.getNode().parameters).forEach((key) => { nodeParameters[key] = this.getNodeParameter(key, itemIndex, ''); }); nodeParameters.executionId = executionId; nodeParameters.apiKey = credentials.apiKey; nodeParameters.baseUrl = credentials.baseUrl; if (nodeParameters.channelId || nodeParameters.executionId) { const res = await (0, helpers_1.ipcRequest)(`send:${['select', 'button'].includes(nodeParameters.type) ? 'prompt' : nodeParameters.type === 'none' ? 'action' : nodeParameters.type}`, nodeParameters).catch((e) => { throw new Error(e); }); returnData.push({ json: { value: res === null || res === void 0 ? void 0 : res.value, channelId: res === null || res === void 0 ? void 0 : res.channelId, userId: res === null || res === void 0 ? void 0 : res.userId, userName: res === null || res === void 0 ? void 0 : res.userName, userTag: res === null || res === void 0 ? void 0 : res.userTag, messageId: res === null || res === void 0 ? void 0 : res.messageId, action: res === null || res === void 0 ? void 0 : res.action, }, }); } if (nodeParameters.placeholder) await new Promise((resolve) => setTimeout(resolve, 1000)); } return this.prepareOutputData(returnData); } } exports.Discord = Discord; //# sourceMappingURL=Discord.node.js.map