{
  "name": "EnglishWithNews",
  "nodes": [
    {
      "parameters": {
        "topic": "bbc-news-api",
        "groupId": "b9n-kafka",
        "options": {}
      },
      "type": "n8n-nodes-base.kafkaTrigger",
      "typeVersion": 1.3,
      "position": [
        -1984,
        -368
      ],
      "id": "024c62bf-f989-4ce1-8e1e-cbce84069051",
      "name": "Kafka Trigger",
      "credentials": {
        "kafka": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatDeepSeek",
      "typeVersion": 1,
      "position": [
        -1360,
        -192
      ],
      "id": "5a5fff0b-6ec6-4aba-8083-0f23efc0f138",
      "name": "DeepSeek Chat Model",
      "credentials": {
        "deepSeekApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatDeepSeek",
      "typeVersion": 1,
      "position": [
        -608,
        -176
      ],
      "id": "1003fce9-e317-4e8e-9c7e-edaefebae933",
      "name": "DeepSeek Chat Model1",
      "credentials": {
        "deepSeekApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatDeepSeek",
      "typeVersion": 1,
      "position": [
        -64,
        -176
      ],
      "id": "d0a393ec-12c9-42a5-b875-4f740ac2581b",
      "name": "DeepSeek Chat Model2",
      "credentials": {
        "deepSeekApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435\nconst items = $input.all();\n\n// \u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\nconst result = items.map(item => {\n  // \u0411\u0435\u0440\u0435\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043f\u043e\u043b\u044f message (\u044d\u0442\u043e \u0441\u0442\u0440\u043e\u043a\u0430!)\n  const messageString = item.json.message;\n  \n  try {\n    // \u041f\u0430\u0440\u0441\u0438\u043c \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0439 JSON\n    const parsedMessage = JSON.parse(messageString);\n    \n    // \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\n    // \u0411\u0435\u0440\u0435\u043c \u0432\u0441\u0435 \u043f\u043e\u043b\u044f \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f + \u0440\u0430\u0441\u043f\u0430\u0440\u0441\u0435\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044f \u0438\u0437 message\n    return {\n      ...item.json,        // \u0442\u0443\u0442 \u0431\u0443\u0434\u0435\u0442 topic \u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 message\n      ...parsedMessage,    // \u0430 \u0442\u0443\u0442 title, summary, news_link\n      parsed: true         // \u043c\u0435\u0442\u043a\u0430, \u0447\u0442\u043e \u043c\u044b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438\n    };\n  } catch (error) {\n    // \u0415\u0441\u043b\u0438 \u043f\u0430\u0440\u0441\u0438\u043d\u0433 \u043d\u0435 \u0443\u0434\u0430\u043b\u0441\u044f, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043a\u0430\u043a \u0435\u0441\u0442\u044c \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443\n    return {\n      ...item.json,\n      error: `Failed to parse message: ${error.message}`\n    };\n  }\n});\n\n// \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\nreturn result;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1776,
        -368
      ],
      "id": "1c6bc01f-5d33-4835-91d9-fb5aac250ed0",
      "name": "Code in JavaScript - Parse TXT to JSON"
    },
    {
      "parameters": {
        "jsCode": "const item = $input.first().json;\n\nconst title = item.title || '\u0411\u0435\u0437 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430';\nconst summary = item.summary || '\u041d\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f';\nconst newsLink = item.news_link;\n\n// HTML-\u0432\u0435\u0440\u0441\u0438\u044f \u0441\u0441\u044b\u043b\u043a\u0438\nconst linkText = newsLink \n  ? `\\n\\n\ud83d\udd17 <a href=\"${newsLink}\">\u0427\u0438\u0442\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e</a>` \n  : '\\n\\n\u274c \u0421\u0441\u044b\u043b\u043a\u0430 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442';\n\n// \u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043e\u0441\u0442 \u0432 HTML-\u0444\u043e\u0440\u043c\u0430\u0442\u0435\n// **\u0436\u0438\u0440\u043d\u044b\u0439** \u043c\u0435\u043d\u044f\u0435\u043c \u043d\u0430 <b>\u0436\u0438\u0440\u043d\u044b\u0439</b>\nconst post = `<b>${title}</b>\\n\\n${summary}${linkText}\\n\\n@english_lessons_with_news`;\n\nreturn [{\n  json: {\n    formattedPost: post,\n    hasLink: !!newsLink,\n    // \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043a\u0443, \u0447\u0442\u043e \u0444\u043e\u0440\u043c\u0430\u0442 HTML (\u0434\u043b\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0438)\n    format: 'html',\n    ...item\n  },\n  binary: $input.first().binary\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1568,
        -368
      ],
      "id": "2b2fd240-2a9a-482e-8388-9503bf8f32f8",
      "name": "Code in JavaScript - Prepare Telegram post"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=\u0420\u043e\u043b\u044c: \u0422\u044b \u2014 \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440 \u043d\u043e\u0432\u043e\u0441\u0442\u043d\u043e\u0433\u043e Telegram-\u043a\u0430\u043d\u0430\u043b\u0430.\n\n\u0417\u0430\u0434\u0430\u0447\u0430: \u041e\u0444\u043e\u0440\u043c\u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u044c \u043a \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0438 \u0434\u043b\u044f \u043d\u043e\u0432\u043e\u0441\u0442\u043d\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430, \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0439 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e, \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435.\n\n\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435:\n- \u041e\u0444\u043e\u0440\u043c\u043b\u0435\u043d\u043d\u0430\u044f \u043d\u043e\u0432\u043e\u0441\u0442\u044c:{{ $json.formattedPost }}\n\n\u0422\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f:\n- 4 \u0445\u0435\u0448\u0442\u0435\u0433\u0430 \u0432 \u043a\u043e\u043d\u0446\u0435 (\u0441 \u0437\u0430\u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0431\u0443\u043a\u0432\u044b)\n- \u041d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0439 \u0432 \u0442\u0435\u043a\u0441\u0442 \u043d\u043e\u0432\u043e\u0441\u0442\u0438\n\n\u0424\u043e\u0440\u043c\u0430\u0442:\n\u041e\u0444\u043e\u0440\u043c\u043b\u0435\u043d\u043d\u0430\u044f \u043d\u043e\u0432\u043e\u0441\u0442\u044c\n#\u0425\u0435\u0448\u0442\u0435\u04331 #\u0425\u0435\u0448\u0442\u0435\u04332 #\u0425\u0435\u0448\u0442\u0435\u04333 #\u0425\u0435\u0448\u0442\u0435\u04334",
        "messages": {
          "messageValues": [
            {
              "message": "Just prepare text for publication in telegram channel"
            }
          ]
        },
        "batching": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.9,
      "position": [
        -1360,
        -368
      ],
      "id": "0c709945-2e15-4291-888f-dd73426a5bfd",
      "name": "Basic LLM Chain - Add Hashtags"
    },
    {
      "parameters": {
        "url": "={{ $('Code in JavaScript - Parse TXT to JSON').item.json.image_link }}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -1008,
        -368
      ],
      "id": "50de9a44-26b4-4c74-9273-20890dbbaef0",
      "name": "HTTP Request - Download news picture"
    },
    {
      "parameters": {
        "operation": "sendPhoto",
        "chatId": "@english_lessons_with_news",
        "binaryData": true,
        "additionalFields": {
          "caption": "={{ $json.text }}",
          "parse_mode": "HTML"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        -800,
        -368
      ],
      "id": "05e7b67d-b977-426e-8a3e-52dd6fd9c8d5",
      "name": "Send a photo message - Post news with picture",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=\u0420\u043e\u043b\u044c: \u0422\u044b \u2014 \u043a\u0440\u0435\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0438 \u0443\u0432\u043b\u0435\u0447\u0451\u043d\u043d\u044b\u0439 \u043f\u0440\u0435\u043f\u043e\u0434\u0430\u0432\u0430\u0442\u0435\u043b\u044c \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430. \u0422\u0432\u043e\u0438 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u044b \u043e\u0431\u043e\u0436\u0430\u044e\u0442 \u0442\u0435\u0431\u044f \u0437\u0430 \u0442\u043e, \u0447\u0442\u043e \u0442\u044b \u0434\u0435\u043b\u0430\u0435\u0448\u044c \u0441\u043b\u043e\u0436\u043d\u043e\u0435 \u2014 \u043f\u0440\u043e\u0441\u0442\u044b\u043c, \u0430 \u0441\u043a\u0443\u0447\u043d\u043e\u0435 \u2014 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c.\n\n\u0417\u0430\u0434\u0430\u0447\u0430: \u0421\u043e\u0437\u0434\u0430\u0439 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0439 \u0440\u0430\u0437\u0431\u043e\u0440 \u043b\u0435\u043a\u0441\u0438\u043a\u0438 \u0438 \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u044d\u0442\u043e\u0439 \u043d\u043e\u0432\u043e\u0441\u0442\u0438. \u042d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0434\u0451\u0442 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u043d\u043e\u0432\u043e\u0441\u0442\u0438 \u0441 \u0444\u043e\u0442\u043e.\n\n\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435:\n- \u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043d\u043e\u0432\u043e\u0441\u0442\u0438: {{ $('Code in JavaScript - Parse TXT to JSON').item.json.title }}\n- \u041a\u0440\u0430\u0442\u043a\u043e\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435: {{ $('Code in JavaScript - Parse TXT to JSON').item.json.summary }}\n\n\u26a0\ufe0f \u0422\u0415\u0425\u041d\u0418\u0427\u0415\u0421\u041a\u041e\u0415 \u041e\u0413\u0420\u0410\u041d\u0418\u0427\u0415\u041d\u0418\u0415: \u0412\u0435\u0441\u044c \u043f\u043e\u0441\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043d\u0435 \u0434\u043b\u0438\u043d\u043d\u0435\u0435 3800 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432.\n\n\u0422\u0412\u041e\u0419 \u0421\u0422\u0418\u041b\u042c:\n- \u041e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u044f \u0436\u0438\u0432\u044b\u0435, \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438, \u0441 \u043b\u044e\u0431\u043e\u0432\u044c\u044e \u043a \u044f\u0437\u044b\u043a\u0443\n- \u0412\u044b\u0431\u0438\u0440\u0430\u0439 6-7 \u0441\u0430\u043c\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u0441\u043b\u043e\u0432 \u0438 2 \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 (\u043c\u043e\u0436\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435)\n- \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430: \u044f\u0440\u043a\u043e\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 + 1-2 \u0436\u0438\u0432\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\n- \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0439 \u043f\u0440\u043e\u0438\u0437\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0441\u043b\u043e\u0432 \u0432 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u044b\u0445 \u0441\u043a\u043e\u0431\u043a\u0430\u0445\n- \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u0438 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445\n- \u0413\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0439 \u0441\u043b\u043e\u0432\u0430 \u043f\u043e \u0442\u0435\u043c\u0430\u043c, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0443\u043c\u0435\u0441\u0442\u043d\u043e\n- \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0439 \u044d\u043c\u043e\u0434\u0437\u0438 \u0434\u043b\u044f \u043e\u0436\u0438\u0432\u043b\u0435\u043d\u0438\u044f, \u043d\u043e \u043d\u0435 \u043f\u0435\u0440\u0435\u0431\u0430\u0440\u0449\u0438\u0432\u0430\u0439 (\ud83d\udcda \u2728 \ud83d\udca1)\n\n\u0421\u0422\u0420\u0423\u041a\u0422\u0423\u0420\u0410:\n\n1. \u0417\u0410\u0413\u041e\u041b\u041e\u0412\u041e\u041a (\u043f\u0440\u0438\u0432\u043b\u0435\u043a\u0430\u044e\u0449\u0438\u0439 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435):\n   \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: <b>\ud83d\udcda \u0420\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043c \u043b\u0435\u043a\u0441\u0438\u043a\u0443 \u0438\u0437 \u043d\u043e\u0432\u043e\u0441\u0442\u0438 \u043e NASA</b> \u0438\u043b\u0438 <b>\u2728 \u0421\u043b\u043e\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0434\u0435\u043b\u0430\u044e\u0442 \u0442\u0432\u043e\u0439 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0438\u0439 \u043a\u043e\u0441\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c</b>\n\n2. \u0412\u0412\u0415\u0414\u0415\u041d\u0418\u0415 (1-2 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f):\n   \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: \"\u041f\u0440\u0438\u0432\u0435\u0442, \u0434\u0440\u0443\u0437\u044c\u044f! \ud83d\udc4b \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u0430\u0433\u043b\u044f\u043d\u0435\u043c \u00ab\u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u00bb \u044d\u0442\u043e\u0439 \u043a\u043e\u0440\u043e\u0442\u043a\u043e\u0439 \u043d\u043e\u0432\u043e\u0441\u0442\u0438 \u0438 \u043d\u0430\u0439\u0434\u0451\u043c \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0435 \u044f\u0437\u044b\u043a\u043e\u0432\u044b\u0435 \u0441\u043e\u043a\u0440\u043e\u0432\u0438\u0449\u0430.\"\n\n3. \u041e\u0421\u041d\u041e\u0412\u041d\u0410\u042f \u0427\u0410\u0421\u0422\u042c \u2014 \u041b\u0415\u041a\u0421\u0418\u041a\u0410:\n   \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430:\n   - <b>\u0421\u043b\u043e\u0432\u043e</b> [\u043f\u0440\u043e\u0438\u0437\u043d\u043e\u0448\u0435\u043d\u0438\u0435] \u2014 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 (\u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u043e\u043c)\n   - <i>\u041f\u0440\u0438\u043c\u0435\u0440 1</i> (\u043a\u0443\u0440\u0441\u0438\u0432\u043e\u043c)\n   - <i>\u041f\u0440\u0438\u043c\u0435\u0440 2</i> (\u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c)\n   \n   \u041c\u043e\u0436\u043d\u043e \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0436\u0438\u0440\u043d\u044b\u0445 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432:\n   <b>\ud83d\ude80 \u041a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u0433\u043b\u0430\u0433\u043e\u043b\u044b</b>\n   <b>\ud83c\udf15 \u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435</b>\n   <b>\ud83d\udcab \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u0444\u0440\u0430\u0437\u044b</b>\n\n4. \u0413\u0420\u0410\u041c\u041c\u0410\u0422\u0418\u0427\u0415\u0421\u041a\u0418\u0419 \u0420\u0410\u0417\u0414\u0415\u041b:\n   <b>\u2728 \u0413\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0430: \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438</b>\n   \u041f\u0440\u043e\u0441\u0442\u043e\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 (\u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u043e\u043c)\n   <i>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0437 \u043d\u043e\u0432\u043e\u0441\u0442\u0438 \u0438\u043b\u0438 \u0436\u0438\u0437\u043d\u0438</i>\n\n5. \u0417\u0410\u041a\u041b\u042e\u0427\u0415\u041d\u0418\u0415 (\u043f\u043e \u0436\u0435\u043b\u0430\u043d\u0438\u044e):\n   \u041a\u043e\u0440\u043e\u0442\u043a\u043e\u0435 \u043d\u0430\u043f\u0443\u0442\u0441\u0442\u0432\u0438\u0435, \u0432\u043e\u043f\u0440\u043e\u0441 \u043a \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430\u043c\n\n\u0422\u0420\u0415\u0411\u041e\u0412\u0410\u041d\u0418\u042f \u041a \u0424\u041e\u0420\u041c\u0410\u0422\u0418\u0420\u041e\u0412\u0410\u041d\u0418\u042e (Telegram HTML):\n- \u0414\u043b\u044f <b>\u0436\u0438\u0440\u043d\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430</b> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439 \u0442\u0435\u0433 <b>\n- \u0414\u043b\u044f <i>\u043a\u0443\u0440\u0441\u0438\u0432\u0430</i> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439 \u0442\u0435\u0433 <i>\n- \u0420\u0430\u0437\u0434\u0435\u043b\u044f\u0439 \u0441\u043c\u044b\u0441\u043b\u043e\u0432\u044b\u0435 \u0431\u043b\u043e\u043a\u0438 \u043f\u0443\u0441\u0442\u044b\u043c\u0438 \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438\n- \u041e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u044f \u2014 \u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u043e\u043c, \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u2014 \u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c\n- \u041d\u0415 \u0418\u0421\u041f\u041e\u041b\u042c\u0417\u0423\u0419 \u0441\u0438\u043c\u0432\u043e\u043b\u044b ### \u0434\u043b\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432 \u2014 \u043e\u043d\u0438 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0432 Telegram\n- \u041d\u0415 \u0418\u0421\u041f\u041e\u041b\u042c\u0417\u0423\u0419 \u0434\u0432\u043e\u0439\u043d\u044b\u0435 \u0437\u0432\u0451\u0437\u0434\u043e\u0447\u043a\u0438 ** \u2014 \u043e\u043d\u0438 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0432 HTML-\u0440\u0435\u0436\u0438\u043c\u0435\n- \u0412\u0441\u0435 \u0442\u0435\u0433\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0437\u0430\u043a\u0440\u044b\u0442\u044b (<b>\u0442\u0435\u043a\u0441\u0442</b>, \u0430 \u043d\u0435 <b>\u0442\u0435\u043a\u0441\u0442)\n\n\u0412\u0410\u0416\u041d\u041e: \u0412\u0435\u0441\u044c \u043f\u043e\u0441\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432 HTML-\u0444\u043e\u0440\u043c\u0430\u0442\u0435, \u0433\u043e\u0442\u043e\u0432\u043e\u043c \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0432 Telegram \u0441 parse_mode=HTML.",
        "batching": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.9,
      "position": [
        -608,
        -368
      ],
      "id": "96ab10fe-e821-4b6e-bea3-4a5106dc2ab5",
      "name": "Basic LLM Chain - Generate explanations of news grammar"
    },
    {
      "parameters": {
        "chatId": "@english_lessons_with_news",
        "text": "={{ $json.text }}",
        "additionalFields": {
          "appendAttribution": false,
          "parse_mode": "HTML"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        -304,
        -368
      ],
      "id": "a60aafbf-9453-4a6e-857a-7b2360cc6eff",
      "name": "Send a text message - Post grammar explanations",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=\u0420\u043e\u043b\u044c: \u0422\u044b \u2014 \u043f\u0440\u0435\u043f\u043e\u0434\u0430\u0432\u0430\u0442\u0435\u043b\u044c \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430, \u0441\u043e\u0437\u0434\u0430\u0451\u0448\u044c \u0437\u0430\u043a\u0440\u0435\u043f\u043b\u044f\u044e\u0449\u0438\u0435 \u0432\u0438\u043a\u0442\u043e\u0440\u0438\u043d\u044b \u0434\u043b\u044f \u0441\u0432\u043e\u0438\u0445 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432.\n\n\u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 (\u043f\u043e\u0441\u0442 \u0441 \u043b\u0435\u043a\u0441\u0438\u043a\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043b\u0438 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u044b): {{ $('Basic LLM Chain - Generate explanations of news grammar').item.json.text }}\n\n\u0417\u0430\u0434\u0430\u043d\u0438\u0435: \u0421\u043e\u0437\u0434\u0430\u0439 \u0432\u0438\u043a\u0442\u043e\u0440\u0438\u043d\u0443 (\u043e\u043f\u0440\u043e\u0441 \u0441 \u043e\u0434\u043d\u0438\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c \u043e\u0442\u0432\u0435\u0442\u043e\u043c) \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u044d\u0442\u043e\u0433\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430.\n\n\u0422\u0420\u0415\u0411\u041e\u0412\u0410\u041d\u0418\u042f \u041a \u0412\u0418\u041a\u0422\u041e\u0420\u0418\u041d\u0415:\n- \u0412\u043e\u043f\u0440\u043e\u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0441\u043b\u043e\u0432 \u0438\u043b\u0438 \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 \u0438\u0437 \u043f\u043e\u0441\u0442\u0430\n- \u0412\u043e\u043f\u0440\u043e\u0441 \u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c \u044f\u0437\u044b\u043a\u0435\n- 4 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u043e\u0442\u0432\u0435\u0442\u0430\n- \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u2014 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 (\u0438\u043d\u0434\u0435\u043a\u0441 0)\n- \u041a\u043e\u0440\u043e\u0442\u043a\u043e\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u043e\u043c, \u043f\u043e\u0447\u0435\u043c\u0443 \u043e\u0442\u0432\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 (\u0434\u043e 200 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432)\n- \u041e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c \u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c\n\n\u0424\u041e\u0420\u041c\u0410\u0422 \u041e\u0422\u0412\u0415\u0422\u0410 (\u0441\u0442\u0440\u043e\u0433\u043e JSON, \u0431\u0435\u0437 \u043b\u0438\u0448\u043d\u0435\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430):\n{\n  \"quiz\": {\n    \"question\": \"How do you say '\u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043f\u043b\u0430\u043d\u043e\u0432' correctly?\",\n    \"options\": [\n      \"a change to plans\",\n      \"a change of plans\",\n      \"a change for plans\",\n      \"a change in plans\"\n    ],\n    \"explanation\": \"\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e: 'a change to plans'. \u041f\u0440\u0435\u0434\u043b\u043e\u0433 TO \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0427\u0415\u0413\u041e-\u0422\u041e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e.\"\n  }\n}\n\n\u041f\u0420\u0418\u041c\u0415\u0420\u042b \u0423\u0414\u0410\u0427\u041d\u042b\u0425 \u0412\u041e\u041f\u0420\u041e\u0421\u041e\u0412:\n- \u041f\u043e \u043b\u0435\u043a\u0441\u0438\u043a\u0435: \"Which word means 'to make an official announcement'?\"\n- \u041f\u043e \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0435: \"Which sentence correctly uses the infinitive of purpose?\"\n- \u041f\u043e \u043f\u0440\u043e\u0438\u0437\u043d\u043e\u0448\u0435\u043d\u0438\u044e: \"How do you pronounce 'crew'?\"\n- \u041f\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0433\u0430\u043c: \"Which preposition is correct with 'a change'?\"\n\n\u0412\u0410\u0416\u041d\u041e:\n- \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u0434 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c 0\n- \u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043f\u0440\u0430\u0432\u0434\u043e\u043f\u043e\u0434\u043e\u0431\u043d\u044b\u043c\u0438 (\u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432)\n- \u041e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u0442\u044c \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u043e\n- \u041d\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0439 \u043d\u0438\u0447\u0435\u0433\u043e \u043a\u0440\u043e\u043c\u0435 JSON \u0432 \u043e\u0442\u0432\u0435\u0442\u0435\n\n\u041f\u0420\u041e\u0412\u0415\u0420\u042c \u0421\u0415\u0411\u042f \u041f\u0415\u0420\u0415\u0414 \u041e\u0422\u0412\u0415\u0422\u041e\u041c:\n\u2705 \u0412 options \u0440\u043e\u0432\u043d\u043e 4 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\n\u2705 \u041f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 (\u0438\u043d\u0434\u0435\u043a\u0441 0) \u2014 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442\n\u2705 \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u0440\u0438 \u2014 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435, \u043d\u043e \u043f\u0440\u0430\u0432\u0434\u043e\u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435\n\u2705 explanation \u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u043e\u043c, \u0434\u043e 200 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432\n\u2705 \u041d\u0435\u0442 \u043b\u0438\u0448\u043d\u0435\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430, \u0442\u043e\u043b\u044c\u043a\u043e JSON",
        "batching": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.9,
      "position": [
        -64,
        -368
      ],
      "id": "bbc47377-981e-4288-be10-c54cbb8ad30a",
      "name": "Basic LLM Chain - Generate Quiz"
    },
    {
      "parameters": {
        "jsCode": "const item = $input.first().json;\nconst rawText = item.text || item.response || JSON.stringify(item);\n\nconsole.log('\ud83d\udce5 \u0421\u044b\u0440\u043e\u0439 \u043e\u0442\u0432\u0435\u0442 \u043e\u0442 LLM (\u043f\u0435\u0440\u0432\u044b\u0435 200 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432):', rawText.substring(0, 200));\n\ntry {\n  let quizData;\n  \n  // \u0412\u0430\u0440\u0438\u0430\u043d\u0442 1: \u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u0443\u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\n  if (typeof rawText === 'object') {\n    quizData = rawText;\n  }\n  // \u0412\u0430\u0440\u0438\u0430\u043d\u0442 2: \u041f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0430\u0441\u043f\u0430\u0440\u0441\u0438\u0442\u044c \u043a\u0430\u043a \u0435\u0441\u0442\u044c\n  else {\n    try {\n      quizData = JSON.parse(rawText);\n    } catch (e) {\n      // \u0412\u0430\u0440\u0438\u0430\u043d\u0442 3: \u0423\u0431\u0438\u0440\u0430\u0435\u043c Markdown-\u0431\u043b\u043e\u043a\u0438\n      const cleanedText = rawText\n        .replace(/```json\\s*/g, '')\n        .replace(/```\\s*$/g, '')\n        .replace(/`/g, '')\n        .trim();\n      \n      console.log('\ud83e\uddf9 \u041e\u0447\u0438\u0449\u0435\u043d\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442:', cleanedText.substring(0, 200));\n      quizData = JSON.parse(cleanedText);\n    }\n  }\n  \n  // \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0432\u0438\u043a\u0442\u043e\u0440\u0438\u043d\u0443 (\u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432 \u043a\u043e\u0440\u043d\u0435 \u0438\u043b\u0438 \u0432 \u043f\u043e\u043b\u0435 quiz)\n  const quiz = quizData.quiz || quizData;\n  \n  // \u0411\u0430\u0437\u043e\u0432\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b\n  if (!quiz.question || !Array.isArray(quiz.options) || !quiz.explanation) {\n    throw new Error('\u041d\u0435\u043f\u043e\u043b\u043d\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0432\u0438\u043a\u0442\u043e\u0440\u0438\u043d\u044b');\n  }\n  \n  console.log('\u2705 \u041f\u0430\u0440\u0441\u0438\u043d\u0433 \u0443\u0441\u043f\u0435\u0448\u0435\u043d:', {\n    question: quiz.question.substring(0, 50) + '...',\n    options: quiz.options.length,\n    explanation: quiz.explanation.length\n  });\n  \n  // \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0447\u0438\u0441\u0442\u044b\u0439 JSON \u0441 \u0432\u0438\u043a\u0442\u043e\u0440\u0438\u043d\u043e\u0439\n  return [{\n    json: {\n      quiz: quiz,  // \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043a\u0430\u043a \u0435\u0441\u0442\u044c\n      parsed: true,\n      timestamp: new Date().toISOString()\n    }\n  }];\n  \n} catch (error) {\n  console.error('\u274c \u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430:', error.message);\n  \n  // \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443, \u043d\u043e \u043d\u0435 \u043b\u043e\u043c\u0430\u0435\u043c \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d\n  return [{\n    json: {\n      error: error.message,\n      raw: rawText.substring(0, 500),\n      parsed: false\n    }\n  }];\n}"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        256,
        -368
      ],
      "id": "f954bd95-2c7d-44c4-99bc-0ce6309f42a3",
      "name": "Code in JavaScript - Clean LLM answer"
    },
    {
      "parameters": {
        "jsCode": "const input = $input.first().json;\n\n// \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0431\u044b\u043b \u043b\u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u044b\u0439 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\nif (!input.quiz && !input.parsed) {\n  console.error('\u274c \u041d\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u0438\u043a\u0442\u043e\u0440\u0438\u043d\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0437\u0430\u043f\u0430\u0441\u043d\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442');\n  return [/* \u0437\u0430\u043f\u0430\u0441\u043d\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 */];\n}\n\nconst quiz = input.quiz;\n\n// \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 (\u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c, \u0447\u0442\u043e \u043e\u043d \u043f\u043e\u0434 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c 0)\nconst correctAnswerText = quiz.options[0];\n\n// \u041f\u0435\u0440\u0435\u043c\u0435\u0448\u0438\u0432\u0430\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 options (\u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0424\u0438\u0448\u0435\u0440\u0430-\u0419\u0435\u0442\u0441\u0430)\nconst shuffledOptions = [...quiz.options];\nfor (let i = shuffledOptions.length - 1; i > 0; i--) {\n  const j = Math.floor(Math.random() * (i + 1));\n  [shuffledOptions[i], shuffledOptions[j]] = [shuffledOptions[j], shuffledOptions[i]];\n}\n\n// \u041d\u0430\u0445\u043e\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0442\u0432\u0435\u0442\u0430\nconst correctIndex = shuffledOptions.indexOf(correctAnswerText);\n\n// \u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 \u043b\u0438\u043c\u0438\u0442\u043e\u0432 Telegram\nlet question = quiz.question;\nlet options = shuffledOptions.map(opt => {\n  if (opt.length > 100) {\n    console.warn(`\u26a0\ufe0f \u0412\u0430\u0440\u0438\u0430\u043d\u0442 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0434\u043b\u0438\u043d\u043d\u044b\u0439 (${opt.length}), \u043e\u0431\u0440\u0435\u0437\u0430\u0435\u043c`);\n    return opt.substring(0, 97) + '...';\n  }\n  return opt;\n});\nlet explanation = quiz.explanation || '\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u043d \u0432\u044b\u0448\u0435.';\n\n// \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0434\u043b\u0438\u043d\u044b \u0432\u043e\u043f\u0440\u043e\u0441\u0430 (\u043c\u0430\u043a\u0441 300)\nif (question.length > 300) {\n  question = question.substring(0, 297) + '...';\n}\n\n// \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0434\u043b\u0438\u043d\u044b \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u044f (\u043c\u0430\u043a\u0441 200)\nif (explanation.length > 200) {\n  explanation = explanation.substring(0, 197) + '...';\n}\n\n// \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432\nif (options.length < 2) {\n  while (options.length < 2) options.push('Option ' + (options.length + 1));\n} else if (options.length > 10) {\n  options = options.slice(0, 10);\n  // \u041a\u043e\u0440\u0440\u0435\u043a\u0442\u0438\u0440\u0443\u0435\u043c correctIndex, \u0435\u0441\u043b\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u043c\u0438\n  if (correctIndex >= options.length) {\n    // \u0412 \u043a\u0440\u0430\u0439\u043d\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0442\u0430\u0432\u0438\u043c 0, \u043d\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c\n    correctIndex = 0;\n  }\n}\n\nconsole.log('\ud83c\udfb2 \u0412\u0438\u043a\u0442\u043e\u0440\u0438\u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u0448\u0430\u043d\u0430. \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430 \u043f\u043e\u0437\u0438\u0446\u0438\u0438:', correctIndex);\n\nreturn [{\n  json: {\n    chat_id: \"@english_lessons_with_news\",  // \u0437\u0430\u043c\u0435\u043d\u0438 \u043d\u0430 \u0441\u0432\u043e\u0439\n    question: question,\n    options: options,\n    type: \"quiz\",\n    correct_option_id: correctIndex,\n    explanation: explanation,\n    is_anonymous: true\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        464,
        -368
      ],
      "id": "9cca5f6b-f134-4af1-8af6-12c94c418d51",
      "name": "Code in JavaScript - Prepare Quiz for publishing"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.telegram.org/bot/sendPoll",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "chat_id",
              "value": "={{ $json.chat_id }}"
            },
            {
              "name": "question",
              "value": "={{ $json.question }}"
            },
            {
              "name": "options",
              "value": "={{ $json.options }}"
            },
            {
              "name": "type",
              "value": "={{ $json.type }}"
            },
            {
              "name": "correct_option_id",
              "value": "={{ $json.correct_option_id }}"
            },
            {
              "name": "explanation",
              "value": "={{ $json.explanation }}"
            },
            {
              "name": "is_anonymous",
              "value": "={{ $json.is_anonymous }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        672,
        -368
      ],
      "id": "10c47c17-9597-4e2a-8d71-0f4e3ac0cbe7",
      "name": "HTTP Request - Publish Quiz"
    }
  ],
  "connections": {
    "Kafka Trigger": {
      "main": [
        [
          {
            "node": "Code in JavaScript - Parse TXT to JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "DeepSeek Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Basic LLM Chain - Add Hashtags",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "DeepSeek Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Basic LLM Chain - Generate explanations of news grammar",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "DeepSeek Chat Model2": {
      "ai_languageModel": [
        [
          {
            "node": "Basic LLM Chain - Generate Quiz",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript - Parse TXT to JSON": {
      "main": [
        [
          {
            "node": "Code in JavaScript - Prepare Telegram post",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript - Prepare Telegram post": {
      "main": [
        [
          {
            "node": "Basic LLM Chain - Add Hashtags",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Basic LLM Chain - Add Hashtags": {
      "main": [
        [
          {
            "node": "HTTP Request - Download news picture",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request - Download news picture": {
      "main": [
        [
          {
            "node": "Send a photo message - Post news with picture",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a photo message - Post news with picture": {
      "main": [
        [
          {
            "node": "Basic LLM Chain - Generate explanations of news grammar",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Basic LLM Chain - Generate explanations of news grammar": {
      "main": [
        [
          {
            "node": "Send a text message - Post grammar explanations",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a text message - Post grammar explanations": {
      "main": [
        [
          {
            "node": "Basic LLM Chain - Generate Quiz",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Basic LLM Chain - Generate Quiz": {
      "main": [
        [
          {
            "node": "Code in JavaScript - Clean LLM answer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript - Clean LLM answer": {
      "main": [
        [
          {
            "node": "Code in JavaScript - Prepare Quiz for publishing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript - Prepare Quiz for publishing": {
      "main": [
        [
          {
            "node": "HTTP Request - Publish Quiz",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": false
  },
  "versionId": "11071034-02b0-496b-84c5-c288fb5e947b",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "ONc199Lt6ntdiZMj",
  "tags": []
}