mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 05:17:28 -08:00
Refactored into simple Discord node so it can be extended later
This commit is contained in:
parent
f2af8d706d
commit
f033e4c886
|
@ -1,18 +0,0 @@
|
|||
import {
|
||||
ICredentialType,
|
||||
NodePropertyTypes,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
|
||||
export class DiscordApi implements ICredentialType {
|
||||
name = 'discordApi';
|
||||
displayName = 'Discord API';
|
||||
properties = [
|
||||
{
|
||||
displayName: 'Webhook URI',
|
||||
name: 'webhookUri',
|
||||
type: 'string' as NodePropertyTypes,
|
||||
default: '',
|
||||
},
|
||||
];
|
||||
}
|
|
@ -6,27 +6,21 @@ import {
|
|||
INodeType,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export class DiscordWebhook implements INodeType {
|
||||
export class Discord implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Discord Webhook',
|
||||
name: 'discordwebhook',
|
||||
displayName: 'Discord',
|
||||
name: 'discord',
|
||||
icon: 'file:discord.png',
|
||||
group: ['output'],
|
||||
version: 1,
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
subtitle: '={{$parameter["resource"]}}',
|
||||
description: 'Sends data to Discord',
|
||||
defaults: {
|
||||
name: 'Discord Webhook',
|
||||
name: 'Discord',
|
||||
color: '#7289da',
|
||||
},
|
||||
inputs: ['main'],
|
||||
outputs: ['main'],
|
||||
credentials: [
|
||||
{
|
||||
name: 'discordApi',
|
||||
required: true,
|
||||
}
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Resource',
|
||||
|
@ -34,41 +28,14 @@ export class DiscordWebhook implements INodeType {
|
|||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Message',
|
||||
value: 'message',
|
||||
name: 'Webhook',
|
||||
value: 'webhook',
|
||||
},
|
||||
],
|
||||
default: 'message',
|
||||
default: 'webhook',
|
||||
description: 'The resource to operate on.',
|
||||
},
|
||||
|
||||
|
||||
|
||||
// ----------------------------------
|
||||
// operations
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'message',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Post',
|
||||
value: 'post',
|
||||
description: 'Post a message into a channel',
|
||||
},
|
||||
],
|
||||
default: 'post',
|
||||
description: 'The operation to perform.',
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// message
|
||||
// ----------------------------------
|
||||
|
@ -76,6 +43,23 @@ export class DiscordWebhook implements INodeType {
|
|||
// ----------------------------------
|
||||
// message:post
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Webhook URL',
|
||||
name: 'webhookUri',
|
||||
type: 'string',
|
||||
typeOptions: {
|
||||
alwaysOpenEditWindow: true,
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'webhook',
|
||||
],
|
||||
},
|
||||
},
|
||||
description: 'The webhook url',
|
||||
},
|
||||
{
|
||||
displayName: 'Text',
|
||||
name: 'text',
|
||||
|
@ -86,11 +70,8 @@ export class DiscordWebhook implements INodeType {
|
|||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'post'
|
||||
],
|
||||
resource: [
|
||||
'message',
|
||||
'webhook',
|
||||
],
|
||||
},
|
||||
},
|
||||
|
@ -106,13 +87,6 @@ export class DiscordWebhook implements INodeType {
|
|||
const returnData: IDataObject[] = [];
|
||||
let responseData;
|
||||
|
||||
const credentials = this.getCredentials('discordApi');
|
||||
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
|
||||
let operation: string;
|
||||
let resource: string;
|
||||
let requestMethod = 'POST';
|
||||
|
||||
|
@ -120,20 +94,14 @@ export class DiscordWebhook implements INodeType {
|
|||
let body: IDataObject;
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
const webhookUri = this.getNodeParameter('webhookUri', i) as string;
|
||||
body = {};
|
||||
|
||||
resource = this.getNodeParameter('resource', i) as string;
|
||||
operation = this.getNodeParameter('operation', i) as string;
|
||||
|
||||
if (resource === 'message') {
|
||||
if (operation === 'post') {
|
||||
// ----------------------------------
|
||||
// message:post
|
||||
// ----------------------------------
|
||||
|
||||
requestMethod = 'POST';
|
||||
body.content = this.getNodeParameter('text', i) as string;
|
||||
}
|
||||
if (resource === 'webhook') {
|
||||
requestMethod = 'POST';
|
||||
body.content = this.getNodeParameter('text', i) as string;
|
||||
} else {
|
||||
throw new Error(`The resource "${resource}" is not known!`);
|
||||
}
|
||||
|
@ -141,7 +109,7 @@ export class DiscordWebhook implements INodeType {
|
|||
const options = {
|
||||
method: requestMethod,
|
||||
body,
|
||||
uri: `${credentials.webhookUri}`,
|
||||
uri: `${webhookUri}`,
|
||||
headers: {
|
||||
'content-type': 'application/json; charset=utf-8'
|
||||
},
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
|
@ -51,8 +51,7 @@
|
|||
"dist/credentials/TelegramApi.credentials.js",
|
||||
"dist/credentials/TrelloApi.credentials.js",
|
||||
"dist/credentials/TwilioApi.credentials.js",
|
||||
"dist/credentials/TypeformApi.credentials.js",
|
||||
"dist/credentials/DiscordApi.credentials.js"
|
||||
"dist/credentials/TypeformApi.credentials.js"
|
||||
],
|
||||
"nodes": [
|
||||
"dist/nodes/ActiveCampaign/ActiveCampaign.node.js",
|
||||
|
@ -65,7 +64,7 @@
|
|||
"dist/nodes/Chargebee/ChargebeeTrigger.node.js",
|
||||
"dist/nodes/Cron.node.js",
|
||||
"dist/nodes/Dropbox/Dropbox.node.js",
|
||||
"dist/nodes/DiscordWebhook/DiscordWebhook.node.js",
|
||||
"dist/nodes/Discord/Discord.node.js",
|
||||
"dist/nodes/EditImage.node.js",
|
||||
"dist/nodes/EmailReadImap.node.js",
|
||||
"dist/nodes/EmailSend.node.js",
|
||||
|
|
Loading…
Reference in a new issue