2023-12-13 07:00:51 -08:00
|
|
|
import {
|
|
|
|
FORM_TRIGGER_PATH_IDENTIFIER,
|
2024-08-29 06:55:53 -07:00
|
|
|
NodeConnectionType,
|
2023-12-13 07:00:51 -08:00
|
|
|
type INodeType,
|
|
|
|
type INodeTypeBaseDescription,
|
|
|
|
type INodeTypeDescription,
|
|
|
|
type IWebhookFunctions,
|
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
|
|
|
import {
|
|
|
|
formDescription,
|
|
|
|
formFields,
|
|
|
|
formRespondMode,
|
|
|
|
formTitle,
|
|
|
|
formTriggerPanel,
|
|
|
|
webhookPath,
|
|
|
|
} from '../common.descriptions';
|
|
|
|
import { formWebhook } from '../utils';
|
|
|
|
|
|
|
|
const descriptionV1: INodeTypeDescription = {
|
|
|
|
displayName: 'n8n Form Trigger',
|
|
|
|
name: 'formTrigger',
|
|
|
|
icon: 'file:form.svg',
|
|
|
|
group: ['trigger'],
|
|
|
|
version: 1,
|
|
|
|
description: 'Runs the flow when an n8n generated webform is submitted',
|
|
|
|
defaults: {
|
|
|
|
name: 'n8n Form Trigger',
|
|
|
|
},
|
2024-09-16 01:58:32 -07:00
|
|
|
|
2023-12-13 07:00:51 -08:00
|
|
|
inputs: [],
|
2024-08-29 06:55:53 -07:00
|
|
|
outputs: [NodeConnectionType.Main],
|
2023-12-13 07:00:51 -08:00
|
|
|
webhooks: [
|
|
|
|
{
|
|
|
|
name: 'setup',
|
|
|
|
httpMethod: 'GET',
|
|
|
|
responseMode: 'onReceived',
|
|
|
|
isFullPath: true,
|
|
|
|
path: `={{$parameter["path"]}}/${FORM_TRIGGER_PATH_IDENTIFIER}`,
|
|
|
|
ndvHideUrl: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'default',
|
|
|
|
httpMethod: 'POST',
|
|
|
|
responseMode: '={{$parameter["responseMode"]}}',
|
|
|
|
responseData: '={{$parameter["responseMode"] === "lastNode" ? "noData" : undefined}}',
|
|
|
|
isFullPath: true,
|
|
|
|
path: `={{$parameter["path"]}}/${FORM_TRIGGER_PATH_IDENTIFIER}`,
|
|
|
|
ndvHideMethod: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
eventTriggerDescription: 'Waiting for you to submit the form',
|
|
|
|
activationMessage: 'You can now make calls to your production Form URL.',
|
|
|
|
triggerPanel: formTriggerPanel,
|
|
|
|
properties: [
|
|
|
|
webhookPath,
|
|
|
|
formTitle,
|
|
|
|
formDescription,
|
|
|
|
formFields,
|
|
|
|
formRespondMode,
|
|
|
|
{
|
|
|
|
displayName: 'Options',
|
|
|
|
name: 'options',
|
|
|
|
type: 'collection',
|
2024-07-29 05:27:23 -07:00
|
|
|
placeholder: 'Add option',
|
2023-12-13 07:00:51 -08:00
|
|
|
default: {},
|
|
|
|
displayOptions: {
|
|
|
|
hide: {
|
|
|
|
responseMode: ['responseNode'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
displayName: 'Form Submitted Text',
|
|
|
|
name: 'formSubmittedText',
|
|
|
|
description: 'The text displayed to users after they filled the form',
|
|
|
|
type: 'string',
|
|
|
|
default: 'Your response has been recorded',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
export class FormTriggerV1 implements INodeType {
|
|
|
|
description: INodeTypeDescription;
|
|
|
|
|
|
|
|
constructor(baseDescription: INodeTypeBaseDescription) {
|
|
|
|
this.description = {
|
|
|
|
...baseDescription,
|
|
|
|
...descriptionV1,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
async webhook(this: IWebhookFunctions) {
|
2024-01-17 07:08:50 -08:00
|
|
|
return await formWebhook(this);
|
2023-12-13 07:00:51 -08:00
|
|
|
}
|
|
|
|
}
|