{
  "name": "ezGPT - Request Form",
  "active": false,
  "nodes": [
    {
      "id": "form-trigger",
      "name": "Request Form",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.5,
      "position": [
        240,
        300
      ],
      "webhookId": "e6901bb6-ae25-4af5-a766-f92e76bb5ea1",
      "parameters": {
        "authentication": "none",
        "formTitle": "Учебная заявка",
        "formDescription": "Только вымышленные данные. Письмо и запись в CRM не создаются.",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Имя",
              "fieldName": "name",
              "fieldType": "text",
              "requiredField": true
            },
            {
              "fieldLabel": "Email",
              "fieldName": "email",
              "fieldType": "email",
              "requiredField": true
            },
            {
              "fieldLabel": "Тип обращения",
              "fieldName": "request_type",
              "fieldType": "dropdown",
              "fieldOptions": {
                "values": [
                  {
                    "option": "Консультация"
                  },
                  {
                    "option": "Поддержка"
                  }
                ]
              },
              "requiredField": true
            },
            {
              "fieldLabel": "Описание задачи",
              "fieldName": "message",
              "fieldType": "textarea",
              "requiredField": true
            }
          ]
        },
        "responseMode": "lastNode",
        "options": {
          "path": "ezgpt-demo-request",
          "buttonLabel": "Проверить заявку",
          "useWorkflowTimezone": false
        }
      }
    },
    {
      "id": "validate-request",
      "name": "Validate Request",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        500,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const input = $input.first().json;\nconst text = key => typeof input[key] === 'string' ? input[key].trim() : '';\nconst name = text('name');\nconst email = text('email').toLowerCase();\nconst requestType = text('request_type');\nconst message = text('message');\nconst errors = [];\nif (name.length < 2 || name.length > 80) errors.push('name_length');\nif (email.length > 254 || !/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(email)) {\n  errors.push('email_format');\n}\nif (!['Консультация', 'Поддержка'].includes(requestType)) {\n  errors.push('request_type_not_allowed');\n}\nif (message.length < 10 || message.length > 1000) errors.push('message_length');\nconst labels = {\n  name_length: 'Имя: от 2 до 80 символов.',\n  email_format: 'Email: проверьте адрес.',\n  request_type_not_allowed: 'Тип: выберите Консультация или Поддержка.',\n  message_length: 'Описание: от 10 до 1000 символов.',\n};\nconst status = errors.length ? 'needs_review' : 'ready';\nreturn [{ json: {\n  request_id: 'demo-' + $execution.id,\n  name, email, request_type: requestType, message,\n  submitted_at: input.submittedAt,\n  form_mode: input.formMode,\n  status, errors,\n  completion_title: status === 'ready' ? 'Проверка пройдена' : 'Исправьте поля',\n  completion_message: status === 'ready'\n    ? 'Учебная заявка проверена. Письмо и запись в CRM не создавались.'\n    : errors.map(key => labels[key]).join(' '),\n  action_performed: false,\n} }];"
      }
    },
    {
      "id": "show-result",
      "name": "Show Result",
      "type": "n8n-nodes-base.form",
      "typeVersion": 2.5,
      "position": [
        760,
        300
      ],
      "parameters": {
        "operation": "completion",
        "respondWith": "text",
        "completionTitle": "={{ $json.completion_title }}",
        "completionMessage": "={{ $json.completion_message }}",
        "options": {}
      }
    }
  ],
  "connections": {
    "Request Form": {
      "main": [
        [
          {
            "node": "Validate Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Request": {
      "main": [
        [
          {
            "node": "Show Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveDataSuccessExecution": "all",
    "saveDataErrorExecution": "all",
    "timezone": "UTC"
  },
  "pinData": {}
}
