{
  "name": "Nodbot - YandexGPT ticket classifier",
  "nodes": [
    {
      "parameters": {
        "path": "yandexgpt-classifier",
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "id": "dfdb9935-9192-4a90-a5b9-7b98898e1cd4",
      "name": "Webhook input",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        260
      ]
    },
    {
      "parameters": {},
      "id": "934ccd0a-47f9-446e-b8f9-01fff86496f2",
      "name": "Sanitize and build labels",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        280,
        260
      ]
    },
    {
      "parameters": {},
      "id": "7636c016-294d-4a21-a925-a2257e2fb2b8",
      "name": "Call YandexGPT classifier",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        560,
        260
      ]
    },
    {
      "parameters": {
        "jsCode": "const src = $json.body ?? $json;\nconst text = String(src.text ?? '').replace(/<[^>]*>/g, ' ').replace(/\\s+/g, ' ').trim();\nif (text.length < 10) throw new Error('ticket text is too short');\nif (text.length > 6000) throw new Error('ticket text is too long for classifier request');\n\nconst labels = Array.isArray(src.labels) && src.labels.length ? src.labels : [\n  'payment_issue', 'technical_bug', 'sales_question', 'refund_request', 'spam'\n];\nif (labels.length < 2 || labels.length > 20) throw new Error('labels count must be between 2 and 20');\n\nconst threshold = Number(src.confidence_threshold ?? 0.72);\nreturn [{\n  json: {\n    ticket_id: String(src.ticket_id ?? `ticket-${Date.now()}`),\n    classifier_body: {\n      modelUri: process.env.YANDEXGPT_CLASSIFIER_MODEL_URI,\n      taskDescription: 'Классифицируй входящую заявку поддержки по основной теме. Верни наиболее подходящий label.',\n      labels,\n      text\n    },\n    routing_policy: {\n      confidence_threshold: threshold,\n      review_label: 'human_review',\n      routes: {\n        payment_issue: 'support-payments-high-priority',\n        technical_bug: 'support-tech',\n        sales_question: 'sales-inbox',\n        refund_request: 'billing-review',\n        spam: 'closed-spam'\n      }\n    },\n    audit_key: `yandexgpt-classifier:${src.ticket_id ?? Date.now()}`\n  }\n}];"
      },
      "id": "0855e0f5-fa7e-4423-8f8f-5aaf5f2baeff",
      "name": "Route by confidence",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        840,
        260
      ]
    },
    {
      "parameters": {},
      "id": "6180ff39-04d6-4b01-bf91-c26ceac9da50",
      "name": "Update CRM or helpdesk",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        1120,
        260
      ]
    },
    {
      "parameters": {},
      "id": "fdb5e8ac-020a-4761-82d9-7cb8f06039d3",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 2,
      "position": [
        1400,
        260
      ]
    }
  ],
  "connections": {
    "Webhook input": {
      "main": [
        [
          {
            "node": "Sanitize and build labels",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sanitize and build labels": {
      "main": [
        [
          {
            "node": "Call YandexGPT classifier",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Call YandexGPT classifier": {
      "main": [
        [
          {
            "node": "Route by confidence",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route by confidence": {
      "main": [
        [
          {
            "node": "Update CRM or helpdesk",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update CRM or helpdesk": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    "nodbot",
    "production",
    "template"
  ],
  "triggerCount": 1,
  "updatedAt": "2026-05-30T00:00:00.000Z",
  "versionId": "4204ce9b-fb0a-4132-9965-b3723d1003a0",
  "meta": {
    "templateCredsSetupCompleted": false
  }
}