🔀 Merge branch 'NeOMakinG-master'

This commit is contained in:
Jan Oberhauser 2019-10-30 14:57:27 +01:00
commit e6186d4553
3 changed files with 106 additions and 0 deletions

View file

@ -0,0 +1,105 @@
import { get } from 'lodash';
import { IExecuteFunctions } from 'n8n-core';
import {
IDataObject,
INodeTypeDescription,
INodeExecutionData,
INodeType,
} from 'n8n-workflow';
export class Discord implements INodeType {
description: INodeTypeDescription = {
displayName: 'Discord',
name: 'discord',
icon: 'file:discord.png',
group: ['output'],
version: 1,
description: 'Sends data to Discord',
defaults: {
name: 'Discord',
color: '#7289da',
},
inputs: ['main'],
outputs: ['main'],
properties: [
{
displayName: 'Webhook URL',
name: 'webhookUri',
type: 'string',
typeOptions: {
alwaysOpenEditWindow: true,
},
default: '',
description: 'The webhook url.',
},
{
displayName: 'Text',
name: 'text',
type: 'string',
typeOptions: {
alwaysOpenEditWindow: true,
},
default: '',
description: 'The text to send.',
}
],
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const returnData: IDataObject[] = [];
const requestMethod = 'POST';
// For Post
let body: IDataObject;
for (let i = 0; i < items.length; i++) {
const webhookUri = this.getNodeParameter('webhookUri', i) as string;
body = {};
body.content = this.getNodeParameter('text', i) as string;
const options = {
method: requestMethod,
body,
uri: `${webhookUri}`,
headers: {
'content-type': 'application/json; charset=utf-8'
},
json: true
};
let maxTries = 5;
do {
try {
await this.helpers.request(options);
break;
} catch (error) {
if (error.statusCode === 429) {
// Waiting rating limit
await new Promise((resolve) => {
setTimeout(async () => {
resolve();
}, get(error, 'response.body.retry_after', 150));
});
} else {
// If it's another error code then return the JSON response
throw error;
}
}
} while (--maxTries);
if (maxTries <= 0) {
throw new Error('Could not send message. Max. amount of rate-limit retries got reached.');
}
returnData.push({success: true});
}
return [this.helpers.returnJsonArray(returnData)];
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View file

@ -67,6 +67,7 @@
"dist/nodes/Chargebee/ChargebeeTrigger.node.js", "dist/nodes/Chargebee/ChargebeeTrigger.node.js",
"dist/nodes/Cron.node.js", "dist/nodes/Cron.node.js",
"dist/nodes/Dropbox/Dropbox.node.js", "dist/nodes/Dropbox/Dropbox.node.js",
"dist/nodes/Discord/Discord.node.js",
"dist/nodes/EditImage.node.js", "dist/nodes/EditImage.node.js",
"dist/nodes/EmailReadImap.node.js", "dist/nodes/EmailReadImap.node.js",
"dist/nodes/EmailSend.node.js", "dist/nodes/EmailSend.node.js",