2024-08-29 06:55:53 -07:00
import {
2024-10-17 06:59:53 -07:00
ADD_FORM_NOTICE ,
type INodePropertyOptions ,
2024-08-29 06:55:53 -07:00
NodeConnectionType ,
type INodeProperties ,
type INodeType ,
type INodeTypeBaseDescription ,
type INodeTypeDescription ,
type IWebhookFunctions ,
2023-12-13 07:00:51 -08:00
} from 'n8n-workflow' ;
import { formWebhook } from '../utils' ;
import {
2024-08-30 06:28:25 -07:00
appendAttributionToForm ,
2023-12-13 07:00:51 -08:00
formDescription ,
formFields ,
formRespondMode ,
formTitle ,
formTriggerPanel ,
respondWithOptions ,
webhookPath ,
} from '../common.descriptions' ;
2024-07-29 05:58:03 -07:00
import { FORM_TRIGGER_AUTHENTICATION_PROPERTY } from '../interfaces' ;
const useWorkflowTimezone : INodeProperties = {
displayName : 'Use Workflow Timezone' ,
name : 'useWorkflowTimezone' ,
type : 'boolean' ,
default : false ,
description : "Whether to use the workflow timezone set in node's settings rather than UTC" ,
} ;
2023-12-13 07:00:51 -08:00
const descriptionV2 : INodeTypeDescription = {
displayName : 'n8n Form Trigger' ,
name : 'formTrigger' ,
icon : 'file:form.svg' ,
group : [ 'trigger' ] ,
2024-10-17 06:59:53 -07:00
version : [ 2 , 2.1 , 2.2 ] ,
description : 'Generate webforms in n8n and pass their responses to the workflow' ,
2023-12-13 07:00:51 -08:00
defaults : {
2024-10-17 06:59:53 -07:00
name : 'On form submission' ,
2023-12-13 07:00:51 -08:00
} ,
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 ,
2024-10-17 06:59:53 -07:00
path : '={{ $parameter["path"] || $parameter["options"]?.path || $webhookId }}' ,
2023-12-13 07:00:51 -08:00
ndvHideUrl : true ,
isForm : true ,
} ,
{
name : 'default' ,
httpMethod : 'POST' ,
responseMode : '={{$parameter["responseMode"]}}' ,
responseData : '={{$parameter["responseMode"] === "lastNode" ? "noData" : undefined}}' ,
isFullPath : true ,
2024-10-17 06:59:53 -07:00
path : '={{ $parameter["path"] || $parameter["options"]?.path || $webhookId }}' ,
2023-12-13 07:00:51 -08:00
ndvHideMethod : true ,
isForm : true ,
} ,
] ,
eventTriggerDescription : 'Waiting for you to submit the form' ,
activationMessage : 'You can now make calls to your production Form URL.' ,
triggerPanel : formTriggerPanel ,
2024-07-29 05:58:03 -07:00
credentials : [
{
// eslint-disable-next-line n8n-nodes-base/node-class-description-credentials-name-unsuffixed
name : 'httpBasicAuth' ,
required : true ,
displayOptions : {
show : {
[ FORM_TRIGGER_AUTHENTICATION_PROPERTY ] : [ 'basicAuth' ] ,
} ,
} ,
} ,
] ,
2023-12-13 07:00:51 -08:00
properties : [
2024-07-29 05:58:03 -07:00
{
displayName : 'Authentication' ,
name : FORM_TRIGGER_AUTHENTICATION_PROPERTY ,
type : 'options' ,
options : [
{
name : 'Basic Auth' ,
value : 'basicAuth' ,
} ,
{
name : 'None' ,
value : 'none' ,
} ,
] ,
default : 'none' ,
} ,
2024-10-17 06:59:53 -07:00
{ . . . webhookPath , displayOptions : { show : { '@version' : [ { _cnd : { lte : 2.1 } } ] } } } ,
2023-12-13 07:00:51 -08:00
formTitle ,
formDescription ,
formFields ,
2024-10-17 06:59:53 -07:00
{ . . . formRespondMode , displayOptions : { show : { '@version' : [ { _cnd : { lte : 2.1 } } ] } } } ,
{
. . . formRespondMode ,
options : ( formRespondMode . options as INodePropertyOptions [ ] ) ? . filter (
( option ) = > option . value !== 'responseNode' ,
) ,
displayOptions : { show : { '@version' : [ { _cnd : { gte : 2.2 } } ] } } ,
} ,
2023-12-13 07:00:51 -08:00
{
displayName :
"In the 'Respond to Webhook' node, select 'Respond With JSON' and set the <strong>formSubmittedText</strong> key to display a custom response in the form, or the <strong>redirectURL</strong> key to redirect users to a URL" ,
name : 'formNotice' ,
type : 'notice' ,
displayOptions : {
show : { responseMode : [ 'responseNode' ] } ,
} ,
default : '' ,
} ,
2024-10-17 06:59:53 -07:00
// notice would be shown if no Form node was connected to trigger
{
displayName : 'Build multi-step forms by adding a form page later in your workflow' ,
name : ADD_FORM_NOTICE ,
type : 'notice' ,
default : '' ,
} ,
2023-12-13 07:00:51 -08:00
{
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 : { } ,
2024-04-19 01:26:19 -07:00
options : [
2024-08-30 06:28:25 -07:00
appendAttributionToForm ,
2024-10-17 06:59:53 -07:00
{
displayName : 'Button Label' ,
description : 'The label of the submit button in the form' ,
name : 'buttonLabel' ,
type : 'string' ,
default : 'Submit' ,
} ,
{
. . . webhookPath ,
required : false ,
displayOptions : { show : { '@version' : [ { _cnd : { gte : 2.2 } } ] } } ,
} ,
2024-05-03 02:02:46 -07:00
{
. . . respondWithOptions ,
displayOptions : {
hide : {
'/responseMode' : [ 'responseNode' ] ,
} ,
} ,
} ,
2024-07-29 05:58:03 -07:00
{
displayName : 'Ignore Bots' ,
name : 'ignoreBots' ,
type : 'boolean' ,
default : false ,
description : 'Whether to ignore requests from bots like link previewers and web crawlers' ,
} ,
{
. . . useWorkflowTimezone ,
default : false ,
2024-10-17 06:59:53 -07:00
description : "Whether to use the workflow timezone in 'submittedAt' field or UTC" ,
2024-07-29 05:58:03 -07:00
displayOptions : {
show : {
'@version' : [ 2 ] ,
} ,
} ,
} ,
{
. . . useWorkflowTimezone ,
default : true ,
2024-10-17 06:59:53 -07:00
description : "Whether to use the workflow timezone in 'submittedAt' field or UTC" ,
2024-07-29 05:58:03 -07:00
displayOptions : {
show : {
'@version' : [ { _cnd : { gt : 2 } } ] ,
} ,
} ,
} ,
2024-04-19 01:26:19 -07:00
] ,
2023-12-13 07:00:51 -08:00
} ,
] ,
} ;
export class FormTriggerV2 implements INodeType {
description : INodeTypeDescription ;
constructor ( baseDescription : INodeTypeBaseDescription ) {
this . description = {
. . . baseDescription ,
. . . descriptionV2 ,
} ;
}
async webhook ( this : IWebhookFunctions ) {
2024-01-17 07:08:50 -08:00
return await formWebhook ( this ) ;
2023-12-13 07:00:51 -08:00
}
}