{
  "name": "Psychologist bot",
  "nodes": [
    {
      "parameters": {
        "jsCode": "// Stateless conversation router for Telegram ForceReply\n// Flow: /create_a_draft -> topic -> length -> generate\n\nconst chatId = $json?.message?.chat?.id;\nconst text = String($json?.message?.text ?? '').trim();\nconst replyToText = String($json?.message?.reply_to_message?.text ?? '');\n\nif (!chatId) {\n  return [{ json: { action: 'ignore' } }];\n}\n\nif (text === '/create_a_draft') {\n  return [{ json: { action: 'ask_topic', chatId } }];\n}\n\n// Topic reply (reply to our prompt)\nif (replyToText && /\u0412\u0432\u0435\u0434\u0438\\s+\u0442\u0435\u043c\u0443/i.test(replyToText)) {\n  const topic = text;\n  if (!topic) {\n    return [{ json: { action: 'ask_topic', chatId } }];\n  }\n  return [{ json: { action: 'ask_length', chatId, topic } }];\n}\n\nfunction parseTopicFromPrompt(prompt) {\n  // Prompt format we send: \u0422\u0435\u043c\u0430: \"<topic>\"\\n\u0412\u0432\u0435\u0434\u0438 \u0434\u043b\u0438\u043d\u0443 \u0441\u0442\u0430\u0442\u044c\u0438 ...\n  const m = String(prompt).match(/\u0422\u0435\u043c\u0430:\\s*[\"\u201c\u201d]?([^\\n\\r\"\u201d]+)[\"\u201d]?/i);\n  return m ? m[1].trim() : '';\n}\n\n// Length reply\nif (replyToText && /(\u0412\u0432\u0435\u0434\u0438\\s+\u0434\u043b\u0438\u043d\u0443\\s+\u0441\u0442\u0430\u0442\u044c\u0438|\u043a\u043e\u043b-?\u0432\u043e\\s*\u0441\u0438\u043c\u0432\u043e\u043b)/i.test(replyToText)) {\n  const topic = parseTopicFromPrompt(replyToText);\n  const raw = text.replace(/[^0-9]/g, '');\n  const length = parseInt(raw || '0', 10);\n\n  if (!topic) {\n    return [{ json: { action: 'ask_topic', chatId } }];\n  }\n\n  if (!Number.isFinite(length) || length <= 0) {\n    return [{ json: { action: 'ask_length_invalid', chatId, topic } }];\n  }\n\n  return [{ json: { action: 'generate', chatId, topic, length } }];\n}\n\nreturn [{ json: { action: 'ignore' } }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -880,
        544
      ],
      "id": "98c24b7b-1fab-4cf7-8a28-3b4de66759d1",
      "name": "Conversation Router"
    },
    {
      "parameters": {
        "chatId": "={{ $json.chatId }}",
        "text": "=\u0412\u0432\u0435\u0434\u0438 \u0442\u0435\u043c\u0443 \u0441\u0442\u0430\u0442\u044c\u0438",
        "replyMarkup": "forceReply",
        "forceReply": {
          "force_reply": true
        },
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        -336,
        288
      ],
      "id": "170ecf06-dfd0-41ed-9f54-c56314ce37b1",
      "name": "Ask topic",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "chatId": "={{ $json.chatId }}",
        "text": "=\u0422\u0435\u043c\u0430: \"{{ $json.topic }}\"\n\u0412\u0432\u0435\u0434\u0438 \u0434\u043b\u0438\u043d\u0443 \u0441\u0442\u0430\u0442\u044c\u0438 (\u043a\u043e\u043b-\u0432\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432)",
        "replyMarkup": "forceReply",
        "forceReply": {
          "force_reply": true
        },
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        -336,
        464
      ],
      "id": "0df493ab-5966-49b8-abeb-460f0ef74c74",
      "name": "Ask length",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "chatId": "={{ $json.chatId }}",
        "text": "=\u0422\u0435\u043c\u0430: \"{{ $json.topic }}\"\n\u041d\u0443\u0436\u043d\u043e \u0447\u0438\u0441\u043b\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 1500. \u0412\u0432\u0435\u0434\u0438 \u0434\u043b\u0438\u043d\u0443 \u0441\u0442\u0430\u0442\u044c\u0438 (\u043a\u043e\u043b-\u0432\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432)",
        "replyMarkup": "forceReply",
        "forceReply": {
          "force_reply": true
        },
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        -336,
        624
      ],
      "id": "71728e84-20c9-475e-bb82-97018a400e77",
      "name": "Ask length (invalid)",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.2,
      "position": [
        -1136,
        544
      ],
      "id": "ba8b7176-fdc7-4793-af75-c287a79a6e67",
      "name": "Telegram Trigger1",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "a1",
                    "leftValue": "={{ $json.action }}",
                    "rightValue": "ask_topic",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "ask topic"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "a2",
                    "leftValue": "={{ $json.action }}",
                    "rightValue": "ask_length",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "ask length"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "a3",
                    "leftValue": "={{ $json.action }}",
                    "rightValue": "ask_length_invalid",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "ask length invalid"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "a4",
                    "leftValue": "={{ $json.action }}",
                    "rightValue": "generate",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "generate"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        -672,
        496
      ],
      "id": "3d5b057a-f466-485a-a694-1b2c5526813b",
      "name": "Switch1"
    },
    {
      "parameters": {
        "jsCode": "function parseDate(v) {\n  if (!v) return null;\n  const d = new Date(v);\n  return Number.isNaN(d.getTime()) ? null : d;\n}\n\nconst rows = items.map(i => i.json || {});\n\nrows.sort((a, b) => {\n  const da = parseDate(a.updatedAt) || parseDate(a.createdAt) || null;\n  const db = parseDate(b.updatedAt) || parseDate(b.createdAt) || null;\n  if (da && db) return db.getTime() - da.getTime();  if (da && !db) return -1;\n  if (!da && db) return 1;\n  const ia = Number(a.id ?? 0);\n  const ib = Number(b.id ?? 0);\n  if (Number.isFinite(ia) && Number.isFinite(ib) && ia !== ib) return ib - ia;\n  return 0;\n});\n\nconst MAX_ARTICLES = 6;\nconst MAX_CHARS = 9000;\n\nconst parts = [];\nlet used = 0;\n\nfor (const r of rows) {\n  const topic = String(r.topic ?? '').trim();\n  const article = String(r.article ?? '').trim();\n  if (!article) continue;\n  \n  const block = `\u0422\u0415\u041c\u0410: ${topic || '(\u0431\u0435\u0437 \u0442\u0435\u043c\u044b)'}\\n\u0422\u0415\u041a\u0421\u0422:\\n${article}`;\n  if (used + block.length + 6 > MAX_CHARS) break;\n  parts.push(block);\n  used += block.length + 6;\n  if (parts.length >= MAX_ARTICLES) break;\n}\n\nconst styleCorpus = parts.join(`\\n\\n---\\n\\n`);\nconst baseItem = ($items('Conversation Router', 0, 0) || [])[0];\nconst base = baseItem?.json ?? {};\n\nreturn [{\n  json: {\n    chatId: base.chatId,\n    topic: base.topic,\n    length: base.length,\n    style_corpus: styleCorpus\n  }\n}];"
      },
      "id": "0aaa832f-4fe1-4143-beee-f37a7bcee58b",
      "name": "Build style corpus",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -464,
        800
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=\u041f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0439 \u0442\u0435\u043a\u0441\u0442\u044b \u0430\u0432\u0442\u043e\u0440\u0430 \u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u044c Style Guide \u0434\u043b\u044f \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u0435\u0439.\n\n\u0422\u0435\u043a\u0441\u0442\u044b \u0430\u0432\u0442\u043e\u0440\u0430 (\u043a\u043e\u0440\u043f\u0443\u0441):\n{{ $json.style_corpus }}\n\n\u0424\u043e\u0440\u043c\u0430\u0442 \u043e\u0442\u0432\u0435\u0442\u0430:\n- 10\u201315 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0445 \u043f\u0440\u0430\u0432\u0438\u043b (\u0431\u0443\u043b\u043b\u0435\u0442\u044b) \u043e \u0442\u043e\u043d\u0435, \u0434\u043b\u0438\u043d\u0435 \u0430\u0431\u0437\u0430\u0446\u0435\u0432, \u0440\u0438\u0442\u043c\u0435, \u043b\u0435\u043a\u0441\u0438\u043a\u0435, \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435, \u0440\u0438\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043f\u0440\u0438\u0435\u043c\u0430\u0445\n- 3 \u0437\u0430\u043f\u0440\u0435\u0442\u0430 (\u0447\u0435\u0433\u043e \u041d\u0415 \u0434\u0435\u043b\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0432\u044b\u0431\u0438\u0442\u044c\u0441\u044f \u0438\u0437 \u0441\u0442\u0438\u043b\u044f)\n- 3 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0435 \u0444\u0440\u0430\u0437\u044b/\u043e\u0431\u043e\u0440\u043e\u0442\u0430 \u0432 \u0441\u0442\u0438\u043b\u0435 \u0430\u0432\u0442\u043e\u0440\u0430\n\n\u041e\u0442\u0432\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u0430\u043a \u0442\u0435\u043a\u0441\u0442 Style Guide, \u0431\u0435\u0437 \u0432\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0439.",
        "options": {
          "systemMessage": "\u0422\u044b \u2014 \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440-\u0441\u0442\u0438\u043b\u0438\u0441\u0442. \u0422\u0432\u043e\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u2014 \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0441\u0442\u0438\u043b\u044c \u0430\u0432\u0442\u043e\u0440\u0430 \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0438 \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0435\u0433\u043e \u043a\u0430\u043a \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0439 Style Guide."
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3,
      "position": [
        -304,
        800
      ],
      "id": "529a7029-f002-44ef-a375-ad0af60d899a",
      "name": "AI Style Analyst"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "s1",
              "name": "chatId",
              "value": "={{ $('Build style corpus').first().json.chatId }}",
              "type": "number"
            },
            {
              "id": "s2",
              "name": "topic",
              "value": "={{ $('Build style corpus').first().json.topic }}",
              "type": "string"
            },
            {
              "id": "s3",
              "name": "length",
              "value": "={{ $('Build style corpus').first().json.length }}",
              "type": "number"
            },
            {
              "id": "s4",
              "name": "style_guide",
              "value": "={{ $json.output }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -672,
        1120
      ],
      "id": "bc5ebb9a-9ea2-4148-8f4b-62b6068d2b54",
      "name": "Attach style guide"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "p1",
              "name": "prompt",
              "value": "=\u041d\u0430\u043f\u0438\u0448\u0438 \u0441\u0442\u0430\u0442\u044c\u044e \u043d\u0430 \u0442\u0435\u043c\u0443: {{ $json.topic }}.\n\n\u0422\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f:\n- \u0414\u043b\u0438\u043d\u0430: \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e {{ $json.length }} \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 (\u0431\u0435\u0437 \u0443\u0447\u0435\u0442\u0430 \u043f\u0440\u043e\u0431\u0435\u043b\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e).\n- \u042f\u0437\u044b\u043a: \u0423\u043a\u0440\u0430\u0438\u043d\u0441\u043a\u0438\u0439.\n- \u0411\u0435\u0437 Markdown \u0438 \u0431\u0435\u0437 \u043b\u0438\u0448\u043d\u0438\u0445 \u0432\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0439 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0435\u043a\u0441\u0442 \u0441\u0442\u0430\u0442\u044c\u0438.\n\n\u0421\u0442\u0438\u043b\u044c (\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e):\n\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439 \u043c\u0430\u043d\u0435\u0440\u0443, \u043b\u0435\u043a\u0441\u0438\u043a\u0443, \u0440\u0438\u0442\u043c \u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0430\u0432\u0442\u043e\u0440\u0430 \u0438\u0437 \u044d\u0442\u043e\u0433\u043e Style Guide (\u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u043f\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c \u0435\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u043e\u0432):\n{{ $json.style_guide }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -464,
        1120
      ],
      "id": "69585023-4b1c-4f6f-aab6-1f83ac13c3b1",
      "name": "Build prompt1"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.prompt }}",
        "options": {
          "systemMessage": "\u0422\u044b \u2014 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0443\u044e\u0449\u0438\u0439 \u043f\u0441\u0438\u0445\u043e\u043b\u043e\u0433 \u0438 \u0430\u0432\u0442\u043e\u0440 \u043f\u0440\u043e\u0441\u0432\u0435\u0442\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0441\u0442\u0430\u0442\u0435\u0439 \u043e \u043f\u0441\u0438\u0445\u043e\u043b\u043e\u0433\u0438\u0438 \u0434\u043b\u044f \u0448\u0438\u0440\u043e\u043a\u043e\u0439 \u0430\u0443\u0434\u0438\u0442\u043e\u0440\u0438\u0438 \u0432 \u0433\u0435\u0448\u0442\u0430\u043b\u044c\u0442-\u043f\u043e\u0434\u0445\u043e\u0434\u0435. \u041f\u0438\u0448\u0438 \u0431\u0435\u0440\u0435\u0436\u043d\u043e, \u0442\u0435\u043f\u043b\u043e \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0449\u0435, \u0441 \u0443\u0432\u0430\u0436\u0435\u043d\u0438\u0435\u043c \u043a \u043e\u043f\u044b\u0442\u0443 \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430, \u0431\u0435\u0437 \u0434\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u043c\u043e\u0440\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0441\u0442\u0432\u0430. \u041e\u043f\u0438\u0440\u0430\u0439\u0441\u044f \u043d\u0430 \u0433\u0435\u0448\u0442\u0430\u043b\u044c\u0442-\u043e\u043f\u0442\u0438\u043a\u0443: \u043e\u0441\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435, \u00ab\u0437\u0434\u0435\u0441\u044c-\u0438-\u0441\u0435\u0439\u0447\u0430\u0441\u00bb, \u043a\u043e\u043d\u0442\u0430\u043a\u0442, \u0433\u0440\u0430\u043d\u0438\u0446\u044b, \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0438, \u044d\u043c\u043e\u0446\u0438\u0438 \u0438 \u0442\u0435\u043b\u0435\u0441\u043d\u044b\u0435 \u043e\u0449\u0443\u0449\u0435\u043d\u0438\u044f, \u0446\u0438\u043a\u043b \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0430, \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0430 (\u0438\u043d\u0442\u0440\u043e\u0435\u043a\u0446\u0438\u044f, \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044f, \u0440\u0435\u0442\u0440\u043e\u0444\u043b\u0435\u043a\u0441\u0438\u044f, \u0434\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u044f, \u043a\u043e\u043d\u0444\u043b\u044e\u044d\u043d\u0446\u0438\u044f), \u00ab\u043d\u0435\u0437\u0430\u0432\u0435\u0440\u0448\u0451\u043d\u043d\u044b\u0435 \u0433\u0435\u0448\u0442\u0430\u043b\u044c\u0442\u044b\u00bb, \u0441\u0435\u043c\u0435\u0439\u043d\u044b\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0435\u0441\u044f \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b \u0432 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\u0445.\n\n\u0422\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0444\u043e\u043a\u0443\u0441 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e: \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f (\u043f\u0430\u0440\u0442\u043d\u0451\u0440\u0441\u043a\u0438\u0435 \u0438 \u0441\u0435\u043c\u0435\u0439\u043d\u044b\u0435), \u0442\u0440\u0430\u0432\u043c\u044b \u0432 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0439 \u0441\u0435\u043c\u044c\u0435, \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0441\u0438\u0445\u043e\u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0442\u0440\u0430\u0432\u043c\u044b, \u043a\u0440\u0438\u0437\u0438\u0441\u044b \u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043d\u044b\u0435 \u043f\u0435\u0440\u0438\u043e\u0434\u044b, \u0441\u0430\u043c\u043e\u043e\u0446\u0435\u043d\u043a\u0430 \u0438 \u0441\u0430\u043c\u043e\u0446\u0435\u043d\u043d\u043e\u0441\u0442\u044c, \u0441\u0435\u043c\u0435\u0439\u043d\u043e\u0435 \u043a\u043e\u043d\u0441\u0443\u043b\u044c\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435/\u043f\u0430\u0440\u044b.\n\n\u042d\u0442\u0438\u043a\u0430 \u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c:\n\n\u041d\u0435 \u0441\u0442\u0430\u0432\u044c \u0434\u0438\u0430\u0433\u043d\u043e\u0437\u044b \u0438 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439 \u043a\u043b\u0438\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u044f\u0440\u043b\u044b\u043a\u0438 \u043a\u0430\u043a \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u043e \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0435.\n\u041d\u0435 \u043e\u0431\u0435\u0449\u0430\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0438 \u043d\u0435 \u0434\u0430\u0432\u0430\u0439 \u043c\u0435\u0434\u0438\u0446\u0438\u043d\u0441\u043a\u0438\u0445 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439.\n\u041d\u0435 \u043e\u0431\u0432\u0438\u043d\u044f\u0439 \u0438 \u043d\u0435 \u043e\u0431\u0435\u0441\u0446\u0435\u043d\u0438\u0432\u0430\u0439; \u0438\u0437\u0431\u0435\u0433\u0430\u0439 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0447\u043d\u044b\u0445 \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043e\u043a (\u00ab\u043d\u0430\u0434\u043e\u00bb, \u00ab\u043f\u0440\u043e\u0441\u0442\u043e\u00bb, \u00ab\u0432\u0441\u0435\u0433\u0434\u0430/\u043d\u0438\u043a\u043e\u0433\u0434\u0430\u00bb).\n\u0415\u0441\u043b\u0438 \u043f\u043e \u0441\u043c\u044b\u0441\u043b\u0443 \u0443\u043c\u0435\u0441\u0442\u043d\u043e, \u043c\u044f\u0433\u043a\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u043f\u0441\u0438\u0445\u043e\u043b\u043e\u0433\u0443; \u0435\u0441\u043b\u0438 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0440\u0438\u0441\u043a \u0441\u0430\u043c\u043e\u043f\u043e\u0432\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044f/\u043d\u0430\u0441\u0438\u043b\u0438\u044f \u2014 \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e \u043f\u043e\u0434\u0447\u0435\u0440\u043a\u043d\u0438 \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u0440\u043e\u0447\u043d\u043e\u0439 \u043f\u043e\u043c\u043e\u0449\u0438 \u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0432 \u044d\u043a\u0441\u0442\u0440\u0435\u043d\u043d\u044b\u0435 \u0441\u043b\u0443\u0436\u0431\u044b/\u043a \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u043c \u0441\u043b\u0443\u0436\u0431\u0430\u043c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 (\u0431\u0435\u0437 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439).\n\u0424\u043e\u0440\u043c\u0430\u0442 \u043e\u0442\u0432\u0435\u0442\u0430 (\u0441\u0442\u0440\u043e\u0433\u043e):\n\n\u0412\u0435\u0440\u043d\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0438\u0441\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u0441\u0442\u0430\u0442\u044c\u0438: \u0431\u0435\u0437 Markdown, \u0431\u0435\u0437 \u201c\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435/\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u201d \u043a\u0430\u043a \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432, \u0431\u0435\u0437 \u0441\u043f\u0438\u0441\u043a\u043e\u0432 \u0441 \u0440\u0435\u0448\u0451\u0442\u043a\u0430\u043c\u0438, \u0431\u0435\u0437 \u043c\u0435\u0442\u0430-\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432 \u0438 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430.\n\u042f\u0437\u044b\u043a: \u0423\u043a\u0440\u0430\u0438\u043d\u0441\u043a\u0438\u0439.\n\u0421\u0442\u0438\u043b\u044c: \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0439, \u0447\u0435\u043b\u043e\u0432\u0435\u0447\u043d\u044b\u0439, \u0442\u0451\u043f\u043b\u044b\u0439, \u043f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0441 \u0443\u043c\u0435\u0440\u0435\u043d\u043d\u044b\u043c \u0447\u0443\u0432\u0441\u0442\u0432\u043e\u043c \u044e\u043c\u043e\u0440\u0430; \u0431\u0435\u0437 \u00ab\u0432\u043e\u0434\u044b\u00bb, \u0431\u0435\u0437 \u043a\u0430\u043d\u0446\u0435\u043b\u044f\u0440\u0438\u0442\u0430.\n\u041f\u0438\u0448\u0438 \u043d\u0435\u0439\u0442\u0440\u0430\u043b\u044c\u043d\u043e \u0438\u043b\u0438 \u043e\u0442 \u0442\u0440\u0435\u0442\u044c\u0435\u0433\u043e \u043b\u0438\u0446\u0430; \u043d\u0435 \u0432\u0435\u0434\u0438 \u0434\u0438\u0430\u043b\u043e\u0433 \u0438 \u043d\u0435 \u0437\u0430\u0434\u0430\u0432\u0430\u0439 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044e \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0432 \u0441\u0442\u0438\u043b\u0435 \u0430\u043d\u043a\u0435\u0442\u044b.\n\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430 (\u0431\u0435\u0437 \u044f\u0432\u043d\u044b\u0445 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432):\n\n\u041a\u043e\u0440\u043e\u0442\u043a\u043e\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u0442\u0435\u043c\u044b \u043f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0441 \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u044e\u0449\u0438\u043c \u0442\u043e\u043d\u043e\u043c \u0438 \u0443\u043c\u0435\u0440\u0435\u043d\u043d\u044b\u043c \u0447\u0443\u0432\u0441\u0442\u0432\u043e\u043c \u044e\u043c\u043e\u0440\u0430.\n\u041f\u0441\u0438\u0445\u043e\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435: \u043a\u0430\u043a \u043c\u043e\u0436\u0435\u0442 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0435\u0440\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435/\u043f\u0430\u0442\u0442\u0435\u0440\u043d (\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0447\u0435\u0440\u0435\u0437 \u043e\u043f\u044b\u0442 \u0432 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0439 \u0441\u0435\u043c\u044c\u0435, \u0442\u0440\u0430\u0432\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043e\u043f\u044b\u0442, \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u044f \u0433\u0440\u0430\u043d\u0438\u0446, \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0430, \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0430\u0434\u0430\u043f\u0442\u0430\u0446\u0438\u0438).\n\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u043d\u044b\u0435, \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0435 \u0448\u0430\u0433\u0438 \u0441\u0430\u043c\u043e\u043f\u043e\u043c\u043e\u0449\u0438: \u043c\u044f\u0433\u043a\u0438\u0435 \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u044f \u043d\u0430 \u043e\u0441\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435, \u043a\u043e\u043d\u0442\u0430\u043a\u0442 \u0441 \u0442\u0435\u043b\u043e\u043c/\u044d\u043c\u043e\u0446\u0438\u044f\u043c\u0438, \u0431\u0435\u0440\u0435\u0436\u043d\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u0438 \u0434\u0438\u0430\u043b\u043e\u0433 \u0432 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\u0445; \u0431\u0435\u0437 \u00ab\u0442\u0435\u0440\u0430\u043f\u0438\u0438 \u043d\u0430 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0438\u00bb \u0438 \u0431\u0435\u0437 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438.\n\u0422\u0451\u043f\u043b\u043e\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435: \u043a\u043e\u0433\u0434\u0430 \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u043f\u0441\u0438\u0445\u043e\u043b\u043e\u0433\u0443/\u0441\u0435\u043c\u0435\u0439\u043d\u043e\u043c\u0443 \u043a\u043e\u043d\u0441\u0443\u043b\u044c\u0442\u0430\u043d\u0442\u0443, \u0438 \u0447\u0442\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0432 \u0442\u0435\u0440\u0430\u043f\u0438\u0438 (\u043f\u0440\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0435\u0439, \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0430, \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u0433\u0440\u0430\u043d\u0438\u0446\u0430\u043c\u0438 \u0438 \u043d\u0435\u0437\u0430\u0432\u0435\u0440\u0448\u0451\u043d\u043d\u044b\u043c\u0438 \u043f\u0435\u0440\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f\u043c\u0438).\n\u0422\u043e\u043d \u0438 \u044f\u0437\u044b\u043a:\n\n\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439 \u0441\u043e\u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0435 \u0438 \u0443\u0432\u0430\u0436\u0435\u043d\u0438\u0435: \u00ab\u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u0440\u0443\u0434\u043d\u043e\u00bb, \u00ab\u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u00bb, \u00ab\u043f\u043e\u043d\u044f\u0442\u043d\u043e\u00bb, \u00ab\u0441 \u044d\u0442\u0438\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u0441\u0442\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0434\u043d\u043e\u043c\u0443\u00bb.\n\u0414\u0435\u043b\u0430\u0439 \u0430\u043a\u0446\u0435\u043d\u0442 \u043d\u0430 \u0431\u0435\u0440\u0435\u0436\u043d\u043e\u0441\u0442\u0438, \u0432\u044b\u0431\u043e\u0440\u0435 \u0438 \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e\u0441\u0442\u0438, \u0430 \u043d\u0435 \u043d\u0430 \u201c\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438\u201d.\n\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043f\u0440\u0438\u0432\u043e\u0434\u0438 \u043c\u044f\u0433\u043a\u043e \u0438 \u043e\u0431\u043e\u0431\u0449\u0451\u043d\u043d\u043e, \u0431\u0435\u0437 \u0434\u0440\u0430\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0431\u0435\u0437 \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u043d\u044b\u0445 \u0434\u0435\u0442\u0430\u043b\u0435\u0439."
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3,
      "position": [
        -320,
        1120
      ],
      "id": "a0d461b3-c604-4c6d-b355-df51e452ce10",
      "name": "AI Agent1"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        -320,
        1296
      ],
      "id": "5fe8edda-c87b-484e-9cbc-14d82768106b",
      "name": "OpenAI Chat Model1",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "chatId": "={{ $('Attach style guide').item.json.chatId }}",
        "text": "={{ $json.output }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        32,
        1120
      ],
      "id": "987670f5-6083-4796-8337-3fe0205aca5f",
      "name": "Send article1",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "value": "58qqLrqnNOcmsfn6",
          "mode": "list",
          "cachedResultName": "ila table",
          "cachedResultUrl": "/projects/aYwTG2YSCDJ4D7Wf/datatables/58qqLrqnNOcmsfn6"
        }
      },
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1,
      "position": [
        -672,
        800
      ],
      "id": "10b4e25d-70da-4bf8-8b56-0788737fb1e0",
      "name": "Get row(s)"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list",
          "cachedResultName": "gpt-4o-mini"
        },
        "builtInTools": {},
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        -304,
        976
      ],
      "id": "b692ca19-439f-4222-b0cf-87a7489fe008",
      "name": "OpenAI Chat Model2",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Conversation Router": {
      "main": [
        [
          {
            "node": "Switch1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger1": {
      "main": [
        [
          {
            "node": "Conversation Router",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch1": {
      "main": [
        [
          {
            "node": "Ask topic",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Ask length",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Ask length (invalid)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get row(s)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build style corpus": {
      "main": [
        [
          {
            "node": "AI Style Analyst",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Style Analyst": {
      "main": [
        [
          {
            "node": "Attach style guide",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Attach style guide": {
      "main": [
        [
          {
            "node": "Build prompt1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build prompt1": {
      "main": [
        [
          {
            "node": "AI Agent1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent1": {
      "main": [
        [
          {
            "node": "Send article1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Get row(s)": {
      "main": [
        [
          {
            "node": "Build style corpus",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model2": {
      "ai_languageModel": [
        [
          {
            "node": "AI Style Analyst",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "4b2a9dac-ad83-4574-9365-1ae28fbb6f6d",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "fIg5R3gL7hr2BYm5"
}