{
  "name": "SemGuru — проверить десять обращений",
  "nodes": [
    {
      "parameters": {
        "formTitle": "Учебная сводка",
        "formDescription": "Один номер, точка и текст на строку. Только учебные сообщения.",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Обращения",
              "fieldType": "textarea",
              "requiredField": true
            }
          ]
        },
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "51e43d17-363f-470a-bce0-305554fc4318",
      "name": "Форма",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [
        0,
        0
      ],
      "webhookId": "54a6709a-3380-444e-b217-f54adb5e92b0"
    },
    {
      "parameters": {
        "jsCode": "const raw = String($input.first().json['Обращения'] ?? '');\nconst rows = raw.trim().split(/\\r?\\n/);\nconst problems = [];\nconst seen = new Map();\nif (rows.length !== 10) problems.push('Нужно 10 строк. Сейчас: ' + rows.length + '.');\nrows.forEach((row,index) => {\n  const m = row.trim().match(/^(\\d+)\\.\\s+(.+)$/);\n  if (!m || !m[2].trim()) { problems.push('Строка ' + (index+1) + ': нужен номер, точка и текст.'); return; }\n  const id = Number(m[1]);\n  if (id < 1 || id > 10) { problems.push('В строке ' + (index+1) + ' нужен номер 1–10.'); return; }\n  if (seen.has(id)) problems.push('Номер ' + id + ' повторяется в строках ' + seen.get(id) + ' и ' + (index+1) + '.');\n  else seen.set(id,index+1);\n});\nconst absent = Array.from({length:10}, (_,i)=>i+1).filter(i=>!seen.has(i));\nif (absent.length) problems.push('Отсутствуют номера: '+absent.join(', ')+'.');\nconst safeOriginal=raw.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');\nreturn [{json:{valid:problems.length===0, reason:problems.join(' '), original:raw, safeOriginal, count:rows.length}}];"
      },
      "id": "0f5f9a25-1ee2-4ec9-814f-ec4e6d22481a",
      "name": "Проверить вход",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "4d63b735-168b-47a2-9962-ebd561164184",
              "leftValue": "={{ $json.valid }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "3f65db13-b988-4782-8651-bccb23a3c390",
      "name": "Десять разных номеров?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        440,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "return $input.all().map(item => ({json:{...item.json, stage:'Учебная обработка пройдена'}}));"
      },
      "id": "be7ecc1b-897c-4a84-8921-89bd447d0953",
      "name": "Учебная обработка",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        660,
        -120
      ]
    },
    {
      "parameters": {
        "operation": "completion",
        "respondWith": "text",
        "completionTitle": "Набор принят",
        "completionMessage": "Десять строк прошли проверку. Платного вызова в этой схеме нет.",
        "options": {}
      },
      "id": "72f74099-1fc1-4681-a84b-e75e5c233fc3",
      "name": "Ответ принят",
      "type": "n8n-nodes-base.form",
      "typeVersion": 1,
      "position": [
        900,
        -120
      ]
    },
    {
      "parameters": {
        "operation": "completion",
        "respondWith": "text",
        "completionTitle": "Нужна правка",
        "completionMessage": "={{ $json.reason + '<p>Исходный текст для исправления:</p><pre>' + $json.safeOriginal + '</pre>' }}",
        "options": {}
      },
      "id": "ce40a8c4-90d6-4639-a0bc-0c1eee516e5a",
      "name": "Исправить ввод",
      "type": "n8n-nodes-base.form",
      "typeVersion": 1,
      "position": [
        660,
        130
      ]
    }
  ],
  "connections": {
    "Форма": {
      "main": [
        [
          {
            "node": "Проверить вход",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Проверить вход": {
      "main": [
        [
          {
            "node": "Десять разных номеров?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Десять разных номеров?": {
      "main": [
        [
          {
            "node": "Учебная обработка",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Исправить ввод",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Учебная обработка": {
      "main": [
        [
          {
            "node": "Ответ принят",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}
