first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
import type {
|
||||
ITriggerFunctions,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
ITriggerResponse,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeConnectionTypes } from 'n8n-workflow';
|
||||
|
||||
type eventType = 'Workflow activated' | 'Workflow updated' | undefined;
|
||||
type activationType = 'activate' | 'update';
|
||||
|
||||
export class WorkflowTrigger implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Workflow Trigger',
|
||||
hidden: true,
|
||||
name: 'workflowTrigger',
|
||||
icon: 'fa:network-wired',
|
||||
iconColor: 'orange-red',
|
||||
group: ['trigger'],
|
||||
version: 1,
|
||||
description: 'Triggers based on various lifecycle events, like when a workflow is activated',
|
||||
eventTriggerDescription: '',
|
||||
mockManualExecution: true,
|
||||
activationMessage: 'Your workflow will now trigger executions on the event you have defined.',
|
||||
defaults: {
|
||||
name: 'Workflow Trigger',
|
||||
color: '#ff6d5a',
|
||||
},
|
||||
inputs: [],
|
||||
outputs: [NodeConnectionTypes.Main],
|
||||
properties: [
|
||||
{
|
||||
displayName:
|
||||
"This node is deprecated and would not be updated in the future. Please use 'n8n Trigger' node instead.",
|
||||
name: 'oldVersionNotice',
|
||||
type: 'notice',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Events',
|
||||
name: 'events',
|
||||
type: 'multiOptions',
|
||||
required: true,
|
||||
default: [],
|
||||
description: `Specifies under which conditions an execution should happen:
|
||||
<ul>
|
||||
<li><b>Active Workflow Updated</b>: Triggers when this workflow is updated</li>
|
||||
<li><b>Workflow Activated</b>: Triggers when this workflow is activated</li>
|
||||
</ul>`,
|
||||
options: [
|
||||
{
|
||||
name: 'Active Workflow Updated',
|
||||
value: 'update',
|
||||
description: 'Triggers when this workflow is updated',
|
||||
},
|
||||
{
|
||||
name: 'Workflow Activated',
|
||||
value: 'activate',
|
||||
description: 'Triggers when this workflow is activated',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
async trigger(this: ITriggerFunctions): Promise<ITriggerResponse> {
|
||||
const events = this.getNodeParameter('events', []) as activationType[];
|
||||
|
||||
const activationMode = this.getActivationMode() as activationType;
|
||||
|
||||
if (events.includes(activationMode)) {
|
||||
let event: eventType;
|
||||
if (activationMode === 'activate') {
|
||||
event = 'Workflow activated';
|
||||
}
|
||||
if (activationMode === 'update') {
|
||||
event = 'Workflow updated';
|
||||
}
|
||||
this.emit([
|
||||
this.helpers.returnJsonArray([
|
||||
{ event, timestamp: new Date().toISOString(), workflow_id: this.getWorkflow().id },
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
const manualTriggerFunction = async () => {
|
||||
this.emit([
|
||||
this.helpers.returnJsonArray([
|
||||
{
|
||||
event: 'Manual execution',
|
||||
timestamp: new Date().toISOString(),
|
||||
workflow_id: this.getWorkflow().id,
|
||||
},
|
||||
]),
|
||||
]);
|
||||
};
|
||||
|
||||
return {
|
||||
manualTriggerFunction,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user