mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-14 00:24:07 -08:00
2b74b6238e
* 🔥 Deprecate numberStepSize * 🔥 Deprecate color in non-FA nodes * ⚡ Minor node name fixes * 📦 Update package-lock.json * ⏪ Restore Merge node color * 👕 Fix lint
71 lines
1.7 KiB
TypeScript
71 lines
1.7 KiB
TypeScript
import { ITriggerFunctions } from 'n8n-core';
|
|
import {
|
|
INodeType,
|
|
INodeTypeDescription,
|
|
ITriggerResponse,
|
|
} from 'n8n-workflow';
|
|
|
|
type eventType = 'Instance started' | undefined;
|
|
|
|
export class N8nTrigger implements INodeType {
|
|
description: INodeTypeDescription = {
|
|
displayName: 'n8n Trigger',
|
|
name: 'n8nTrigger',
|
|
icon: 'file:n8nTrigger.svg',
|
|
group: ['trigger'],
|
|
version: 1,
|
|
description: 'Handle events from your n8n instance',
|
|
eventTriggerDescription: '',
|
|
defaults: {
|
|
name: 'n8n Trigger',
|
|
},
|
|
inputs: [],
|
|
outputs: ['main'],
|
|
properties: [
|
|
{
|
|
displayName: 'Events',
|
|
name: 'events',
|
|
type: 'multiOptions',
|
|
required: true,
|
|
default: [],
|
|
description: 'Specifies under which conditions an execution should happen: <b>Instance started</b>: Triggers when this n8n instance is started or re-started',
|
|
options: [
|
|
{
|
|
name: 'Instance started',
|
|
value: 'init',
|
|
description: 'Triggers when this n8n instance is started or re-started',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
};
|
|
|
|
|
|
async trigger(this: ITriggerFunctions): Promise<ITriggerResponse> {
|
|
const events = this.getNodeParameter('events', []) as string[];
|
|
|
|
const activationMode = this.getActivationMode();
|
|
|
|
if (events.includes(activationMode)) {
|
|
let event: eventType;
|
|
if (activationMode === 'init') {
|
|
event = 'Instance started';
|
|
}
|
|
this.emit([
|
|
this.helpers.returnJsonArray([
|
|
{ event, timestamp: (new Date()).toISOString(), workflow_id: this.getWorkflow().id },
|
|
]),
|
|
]);
|
|
}
|
|
|
|
const self = this;
|
|
async function manualTriggerFunction() {
|
|
self.emit([self.helpers.returnJsonArray([{ event: 'Manual execution', timestamp: (new Date()).toISOString(), workflow_id: self.getWorkflow().id }])]);
|
|
}
|
|
|
|
return {
|
|
manualTriggerFunction,
|
|
};
|
|
}
|
|
}
|