2023-03-09 09:13:15 -08:00
|
|
|
import type {
|
|
|
|
ITriggerFunctions,
|
|
|
|
INodeType,
|
|
|
|
INodeTypeDescription,
|
|
|
|
ITriggerResponse,
|
|
|
|
} from 'n8n-workflow';
|
2021-04-24 14:14:06 -07:00
|
|
|
|
|
|
|
type eventType = 'Workflow activated' | 'Workflow updated' | undefined;
|
|
|
|
type activationType = 'activate' | 'update';
|
|
|
|
|
|
|
|
export class WorkflowTrigger implements INodeType {
|
|
|
|
description: INodeTypeDescription = {
|
|
|
|
displayName: 'Workflow Trigger',
|
|
|
|
name: 'workflowTrigger',
|
|
|
|
icon: 'fa:network-wired',
|
2024-06-06 04:34:30 -07:00
|
|
|
iconColor: 'orange-red',
|
2021-04-24 14:14:06 -07:00
|
|
|
group: ['trigger'],
|
|
|
|
version: 1,
|
|
|
|
description: 'Triggers based on various lifecycle events, like when a workflow is activated',
|
:sparkles: Improve Waiting Webhook call state in WF Canvas (#2430)
* N8N-2586 Improve Waiting Webhook call state in WF Canvas
* N8N-2586 Added watcher for showing Webhook's Node Tooltip on execution
* N8N-2586 Show helping tooltip for trigger node if wokrflow is running, it is a trigger node, if it is only one trigger node in WF
* N8N-2586 Rework/Move logic to computed property, Created getter for ActveTriggerNodesInWokrflow, Add style to trigger node's tooltip, remove comments
* N8N-2586 Added EventTriggerDescription prop in INodeTypeDescription Interface, Updated Logic for TriggerNode Tooltip based on the new prop
* N8N-2586 Add new use cases/watcher to show Trigger Nodes Tooltip / If has issues, if paused, if wokrlfow is running, Refactor Getter
* N8N-2586 Added z-index to tooltip, Added new Scenario for Tooltip if it is Draged&Droped on the WF
* N8N-2586 Refactor computed property for draged nodes
* N8N-2586 Fixed Conflicts
* N8N-2586 Fixed Tooltip
* N8N-2586 Dont show tooltip on core trigger nodes that execute automatically
* N8N-2586 Fixed Webhook tooltip when adding/deleting canvas during WF execution
* N8N-2586 Updated Logic, Simplify the code
* N8N-2586 Simplify Code
* N8N-2586 Added check for nodetype
* update dragging to use local state
* N8N-2586 Added eventTriggerDescription to Interval Node
* add comment, use new getter
* update to always check
Co-authored-by: Mutasem <mutdmour@gmail.com>
2021-11-25 14:33:41 -08:00
|
|
|
eventTriggerDescription: '',
|
2022-06-20 12:39:24 -07:00
|
|
|
mockManualExecution: true,
|
2022-01-21 09:00:00 -08:00
|
|
|
activationMessage: 'Your workflow will now trigger executions on the event you have defined.',
|
2021-04-24 14:14:06 -07:00
|
|
|
defaults: {
|
|
|
|
name: 'Workflow Trigger',
|
|
|
|
color: '#ff6d5a',
|
|
|
|
},
|
|
|
|
inputs: [],
|
|
|
|
outputs: ['main'],
|
|
|
|
properties: [
|
|
|
|
{
|
|
|
|
displayName: 'Events',
|
|
|
|
name: 'events',
|
|
|
|
type: 'multiOptions',
|
|
|
|
required: true,
|
|
|
|
default: [],
|
2021-11-25 09:10:06 -08:00
|
|
|
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>
|
2022-05-06 14:01:25 -07:00
|
|
|
</ul>`,
|
2021-04-24 14:14:06 -07:00
|
|
|
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([
|
2022-08-17 08:50:24 -07:00
|
|
|
{ event, timestamp: new Date().toISOString(), workflow_id: this.getWorkflow().id },
|
2021-04-24 14:14:06 -07:00
|
|
|
]),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2023-01-13 09:11:56 -08:00
|
|
|
const manualTriggerFunction = async () => {
|
|
|
|
this.emit([
|
|
|
|
this.helpers.returnJsonArray([
|
2022-08-17 08:50:24 -07:00
|
|
|
{
|
|
|
|
event: 'Manual execution',
|
|
|
|
timestamp: new Date().toISOString(),
|
2023-01-13 09:11:56 -08:00
|
|
|
workflow_id: this.getWorkflow().id,
|
2022-08-17 08:50:24 -07:00
|
|
|
},
|
|
|
|
]),
|
|
|
|
]);
|
2023-01-13 09:11:56 -08:00
|
|
|
};
|
2021-04-24 14:14:06 -07:00
|
|
|
|
|
|
|
return {
|
|
|
|
manualTriggerFunction,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|