{
  "name": "Marketing AI Copilot",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "marketing-copilot/chat",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "webhook_trigger",
      "name": "Webhook Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        100,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.openai.com/v1/chat/completions",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $env.OPENAI_API_KEY }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"model\": \"gpt-4\",\n  \"temperature\": 0.3,\n  \"max_tokens\": 500,\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"\u0422\u044b \u2014 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0442\u043e\u0440 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.\\n\\n\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0442\u0438\u043f\u044b:\\n- CREATE_CAMPAIGN: \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u043e\u0432\u0443\u044e \u043a\u0430\u043c\u043f\u0430\u043d\u0438\u044e\\n- ASK_GUIDELINES: \u0432\u043e\u043f\u0440\u043e\u0441 \u043e \u0433\u0430\u0439\u0434\u043b\u0430\u0439\u043d\u0430\u0445\\n- CONFIRM: \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435\\n- REJECT: \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0435\\n- UNKNOWN: \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e\\n\\n\u041e\u0442\u0432\u0435\u0442\u044c \u0422\u041e\u041b\u042c\u041a\u041e \u043e\u0434\u043d\u0438\u043c \u0441\u043b\u043e\u0432\u043e\u043c \u2014 \u0442\u0438\u043f \u0437\u0430\u043f\u0440\u043e\u0441\u0430.\"\n    },\n    {\n      \"role\": \"user\",\n      \"content\": \"{{ $json.body.message }}\"\n    }\n  ]\n}",
        "options": {}
      },
      "id": "router_agent",
      "name": "Router Agent",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        320,
        300
      ]
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": false,
                  "leftValue": "",
                  "typeValidation": "loose"
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.choices[0].message.content }}",
                    "rightValue": "CREATE_CAMPAIGN",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "Create Campaign"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": false,
                  "leftValue": "",
                  "typeValidation": "loose"
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.choices[0].message.content }}",
                    "rightValue": "ASK_GUIDELINES",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "Ask Guidelines"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": false,
                  "leftValue": "",
                  "typeValidation": "loose"
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.choices[0].message.content }}",
                    "rightValue": "CONFIRM",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "Confirm"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": false,
                  "leftValue": "",
                  "typeValidation": "loose"
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.choices[0].message.content }}",
                    "rightValue": "REJECT",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "Reject"
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra"
        }
      },
      "id": "intent_switch",
      "name": "Intent Switch",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3,
      "position": [
        540,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.APP_URL }}/api/n8n/webhook",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"action\": \"get_guidelines\",\n  \"data\": {}\n}",
        "options": {}
      },
      "id": "rag_agent",
      "name": "RAG Agent",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        760,
        100
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.APP_URL }}/api/n8n/webhook",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"action\": \"search_campaigns\",\n  \"data\": {\n    \"limit\": 3\n  }\n}",
        "options": {}
      },
      "id": "search_campaigns",
      "name": "Search Past Campaigns",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        980,
        100
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.openai.com/v1/chat/completions",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $env.OPENAI_API_KEY }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"model\": \"gpt-4\",\n  \"temperature\": 0.7,\n  \"max_tokens\": 2000,\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"\u0422\u044b \u2014 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u043c\u0430\u0440\u043a\u0435\u0442\u0438\u043d\u0433\u043e\u0432\u044b\u0445 \u043a\u0430\u043c\u043f\u0430\u043d\u0438\u0439 \u0434\u043b\u044f \u042f\u043d\u0434\u0435\u043a\u0441 Go.\\n\\n\u0421\u043e\u0437\u0434\u0430\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u043a\u0430\u043c\u043f\u0430\u043d\u0438\u0438 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 JSON:\\n{\\n  \\\"name\\\": \\\"\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\\\",\\n  \\\"type\\\": \\\"promo|retention|reactivation\\\",\\n  \\\"segment\\\": \\\"\u0441\u0435\u0433\u043c\u0435\u043d\u0442\\\",\\n  \\\"region\\\": \\\"\u0440\u0435\u0433\u0438\u043e\u043d\\\",\\n  \\\"offer\\\": {\\n    \\\"type\\\": \\\"percentage_discount\\\",\\n    \\\"value\\\": \u0447\u0438\u0441\u043b\u043e,\\n    \\\"promo_code\\\": \\\"\u041a\u041e\u0414\\\"\\n  },\\n  \\\"channels\\\": [\\\"push\\\", \\\"email\\\"]\\n}\"\n    },\n    {\n      \"role\": \"user\",\n      \"content\": \"\u0417\u0430\u043f\u0440\u043e\u0441: {{ $('Webhook Trigger').item.json.body.message }}\\n\\n\u0413\u0430\u0439\u0434\u043b\u0430\u0439\u043d\u044b: {{ JSON.stringify($('RAG Agent').item.json.guidelines) }}\\n\\n\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u0430\u043c\u043f\u0430\u043d\u0438\u0439: {{ JSON.stringify($('Search Past Campaigns').item.json.campaigns) }}\"\n    }\n  ]\n}",
        "options": {}
      },
      "id": "generator_agent",
      "name": "Generator Agent",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        1200,
        100
      ]
    },
    {
      "parameters": {
        "jsCode": "const response = $input.first().json;\nconst content = response.choices?.[0]?.message?.content || '{}';\n\nlet campaign;\ntry {\n  // \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c JSON \u0438\u0437 \u043e\u0442\u0432\u0435\u0442\u0430\n  const jsonMatch = content.match(/\\{[\\s\\S]*\\}/);\n  campaign = jsonMatch ? JSON.parse(jsonMatch[0]) : {};\n} catch (e) {\n  campaign = {};\n}\n\nconst result = {\n  valid: true,\n  errors: [],\n  warnings: [],\n  campaign\n};\n\n// \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0441\u043a\u0438\u0434\u043a\u0438\nconst discount = campaign.offer?.value;\nif (typeof discount === 'number') {\n  if (discount > 50) {\n    result.valid = false;\n    result.errors.push(`\u0421\u043a\u0438\u0434\u043a\u0430 ${discount}% \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c 50%`);\n  } else if (discount > 30) {\n    result.warnings.push(`\u0421\u043a\u0438\u0434\u043a\u0430 ${discount}% \u043d\u0430 \u0432\u0435\u0440\u0445\u043d\u0435\u0439 \u0433\u0440\u0430\u043d\u0438\u0446\u0435 \u043c\u0430\u0440\u0436\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438`);\n  }\n}\n\n// \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u043b\u0435\u0439\nif (!campaign.name) {\n  result.valid = false;\n  result.errors.push('\u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u0430\u043c\u043f\u0430\u043d\u0438\u0438');\n}\n\nreturn result;"
      },
      "id": "validator_agent",
      "name": "Validator Agent",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1420,
        100
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "valid-check",
              "leftValue": "={{ $json.valid }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "equals"
              }
            }
          ]
        },
        "options": {}
      },
      "id": "validation_check",
      "name": "Validation Check",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        1640,
        100
      ]
    },
    {
      "parameters": {
        "jsCode": "const data = $input.first().json;\nconst campaign = data.campaign;\nconst warnings = data.warnings || [];\n\nlet message = `\u2705 \u0413\u043e\u0442\u043e\u0432\u043e! \u0412\u043e\u0442 \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c:\\n\\n`;\nmessage += `**${campaign.name || '\u041d\u043e\u0432\u0430\u044f \u043a\u0430\u043c\u043f\u0430\u043d\u0438\u044f'}**\\n`;\nmessage += `\u2022 \u0420\u0435\u0433\u0438\u043e\u043d: ${campaign.region || '\u041d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d'}\\n`;\nmessage += `\u2022 \u0421\u0435\u0433\u043c\u0435\u043d\u0442: ${campaign.segment || '\u041d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d'}\\n`;\nmessage += `\u2022 \u0421\u043a\u0438\u0434\u043a\u0430: ${campaign.offer?.value || 0}%\\n`;\nmessage += `\u2022 \u041f\u0440\u043e\u043c\u043e\u043a\u043e\u0434: ${campaign.offer?.promo_code || '\u041d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d'}\\n`;\nmessage += `\u2022 \u041a\u0430\u043d\u0430\u043b\u044b: ${(campaign.channels || []).join(', ') || '\u041d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u044b'}\\n\\n`;\n\nif (warnings.length > 0) {\n  message += `\u26a0\ufe0f **\u041f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044f:**\\n`;\n  warnings.forEach(w => message += `\u2022 ${w}\\n`);\n  message += '\\n';\n}\n\nmessage += `\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u044d\u0442\u0443 \u043a\u0430\u043c\u043f\u0430\u043d\u0438\u044e? \u041e\u0442\u0432\u0435\u0442\u044c\u0442\u0435 \"\u0434\u0430\" \u0434\u043b\u044f \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f.`;\n\nreturn {\n  success: true,\n  message,\n  campaign_preview: campaign,\n  requires_confirmation: true\n};"
      },
      "id": "format_success",
      "name": "Format Success Response",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1860,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "const data = $input.first().json;\nconst errors = data.errors || [];\n\nlet message = `\u274c \u041d\u0435 \u043c\u043e\u0433\u0443 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u0430\u043c\u043f\u0430\u043d\u0438\u044e:\\n\\n`;\nerrors.forEach(e => message += `\u2022 ${e}\\n`);\nmessage += `\\n\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u0441\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0438\u0440\u0443\u0439\u0442\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b.`;\n\nreturn {\n  success: false,\n  message,\n  errors\n};"
      },
      "id": "format_error",
      "name": "Format Error Response",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1860,
        200
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.openai.com/v1/chat/completions",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $env.OPENAI_API_KEY }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"model\": \"gpt-4\",\n  \"temperature\": 0.5,\n  \"max_tokens\": 1000,\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"\u0422\u044b \u2014 \u044d\u043a\u0441\u043f\u0435\u0440\u0442 \u043f\u043e \u043c\u0430\u0440\u043a\u0435\u0442\u0438\u043d\u0433\u043e\u0432\u044b\u043c \u0433\u0430\u0439\u0434\u043b\u0430\u0439\u043d\u0430\u043c \u042f\u043d\u0434\u0435\u043a\u0441 Go.\\n\\n\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430:\\n- \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u043a\u0438\u0434\u043a\u0430: 30% (\u043e\u0431\u044b\u0447\u043d\u044b\u0435), 40% (\u0440\u0435\u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u044f), 50% (\u043d\u043e\u0432\u044b\u0435 \u0440\u044b\u043d\u043a\u0438)\\n- \u041f\u0440\u043e\u043c\u043e\u043a\u043e\u0434\u044b \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0442 \u0434\u043e 14 \u0434\u043d\u0435\u0439\\n- \u041d\u0435\u043b\u044c\u0437\u044f \u0441\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u043c\u043e\u043a\u043e\u0434\u044b\\n- \u0417\u0430\u043f\u0440\u0435\u0449\u0435\u043d\u044b \u0444\u0440\u0430\u0437\u044b: \\\"\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0435\u0433\u043e\u0434\u043d\u044f\\\", \\\"\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0448\u0430\u043d\u0441\\\"\\n\\n\u041e\u0442\u0432\u0435\u0447\u0430\u0439 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043a\u0440\u0430\u0442\u043a\u043e \u0438 \u043f\u043e \u0434\u0435\u043b\u0443.\"\n    },\n    {\n      \"role\": \"user\",\n      \"content\": \"{{ $('Webhook Trigger').item.json.body.message }}\"\n    }\n  ]\n}",
        "options": {}
      },
      "id": "guidelines_response",
      "name": "Guidelines Response",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        760,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const response = $input.first().json;\nconst content = response.choices?.[0]?.message?.content || '\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0442\u0432\u0435\u0442';\n\nreturn {\n  success: true,\n  message: content\n};"
      },
      "id": "format_guidelines",
      "name": "Format Guidelines",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        980,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.APP_URL }}/api/n8n/webhook",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"action\": \"create_campaign\",\n  \"data\": {{ JSON.stringify($('Webhook Trigger').item.json.body.context?.pendingCampaign || {}) }}\n}",
        "options": {}
      },
      "id": "confirm_create",
      "name": "Confirm Create",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        760,
        480
      ]
    },
    {
      "parameters": {
        "jsCode": "const result = $input.first().json;\n\nif (result.success && result.campaign) {\n  return {\n    success: true,\n    message: `\u2705 \u041a\u0430\u043c\u043f\u0430\u043d\u0438\u044f \"${result.campaign.name}\" \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0430!\\n\\n\u041e\u043d\u0430 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u043a\u0430\u043c\u043f\u0430\u043d\u0438\u0439 \u043d\u0430 \u0434\u0430\u0448\u0431\u043e\u0440\u0434\u0435.`\n  };\n}\n\nreturn {\n  success: false,\n  message: '\u274c \u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u0430\u043c\u043f\u0430\u043d\u0438\u044e. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0435\u0449\u0451 \u0440\u0430\u0437.'\n};"
      },
      "id": "format_confirm",
      "name": "Format Confirm Response",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        980,
        480
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "message",
              "value": "\u0425\u043e\u0440\u043e\u0448\u043e, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b. \u0427\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0445\u043e\u0442\u0438\u0442\u0435 \u0441\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c?"
            }
          ],
          "boolean": [
            {
              "name": "success",
              "value": true
            }
          ]
        },
        "options": {}
      },
      "id": "reject_response",
      "name": "Reject Response",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3,
      "position": [
        760,
        640
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "message",
              "value": "\u041d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u043e\u043d\u044f\u043b \u0437\u0430\u043f\u0440\u043e\u0441. \u042f \u043c\u043e\u0433\u0443 \u043f\u043e\u043c\u043e\u0447\u044c:\n\u2022 \u0421\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u043e\u0432\u0443\u044e \u043c\u0430\u0440\u043a\u0435\u0442\u0438\u043d\u0433\u043e\u0432\u0443\u044e \u043a\u0430\u043c\u043f\u0430\u043d\u0438\u044e\n\u2022 \u041e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043e \u0433\u0430\u0439\u0434\u043b\u0430\u0439\u043d\u0430\u0445 \u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f\u0445\n\u2022 \u041d\u0430\u0439\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0443\u0441\u043f\u0435\u0448\u043d\u044b\u0445 \u043a\u0430\u043c\u043f\u0430\u043d\u0438\u0439\n\n\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u043e\u043f\u0438\u0441\u0430\u0442\u044c, \u043a\u0430\u043a\u0443\u044e \u043a\u0430\u043c\u043f\u0430\u043d\u0438\u044e \u0445\u043e\u0442\u0438\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c."
            }
          ],
          "boolean": [
            {
              "name": "success",
              "value": true
            }
          ]
        },
        "options": {}
      },
      "id": "unknown_response",
      "name": "Unknown Response",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3,
      "position": [
        760,
        800
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json }}",
        "options": {}
      },
      "id": "respond_webhook",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        1200,
        480
      ]
    }
  ],
  "connections": {
    "Webhook Trigger": {
      "main": [
        [
          {
            "node": "Router Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Router Agent": {
      "main": [
        [
          {
            "node": "Intent Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Intent Switch": {
      "main": [
        [
          {
            "node": "RAG Agent",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Guidelines Response",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Confirm Create",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Reject Response",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Unknown Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "RAG Agent": {
      "main": [
        [
          {
            "node": "Search Past Campaigns",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search Past Campaigns": {
      "main": [
        [
          {
            "node": "Generator Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generator Agent": {
      "main": [
        [
          {
            "node": "Validator Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validator Agent": {
      "main": [
        [
          {
            "node": "Validation Check",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validation Check": {
      "main": [
        [
          {
            "node": "Format Success Response",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Format Error Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Success Response": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Error Response": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Guidelines Response": {
      "main": [
        [
          {
            "node": "Format Guidelines",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Guidelines": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Confirm Create": {
      "main": [
        [
          {
            "node": "Format Confirm Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Confirm Response": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reject Response": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Unknown Response": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "timezone": "Europe/Moscow",
    "saveExecutionProgress": true
  },
  "versionId": "1",
  "tags": []
}