{
  "name": "P \u2014 \u041f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f: \u0434\u0432\u0438\u0436\u043e\u043a (\u0427\u0435\u043b\u043b\u0435\u043d\u0434\u0436 200 \u0434\u043d\u0435\u0439)",
  "nodes": [
    {
      "parameters": {
        "inputSource": "passthrough"
      },
      "id": "p-trigger",
      "name": "\u0417\u0430\u043f\u0443\u0441\u043a \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.1,
      "position": [
        -1400,
        0
      ]
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $env.GOOGLE_SHEETS_ID }}"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "pipeline"
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "day_number",
              "lookupValue": "={{ $('\u0417\u0430\u043f\u0443\u0441\u043a \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438').first().json.day }}"
            }
          ]
        },
        "options": {}
      },
      "id": "p-row",
      "name": "\u0421\u0442\u0440\u043e\u043a\u0430 \u0434\u043d\u044f",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        -1180,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "leftValue": "={{ $json.status }}",
              "rightValue": "awaiting_approval",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            },
            {
              "leftValue": "={{ $json.status }}",
              "rightValue": "scheduled",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "or"
        },
        "options": {}
      },
      "id": "p-guard",
      "name": "\u041c\u043e\u0436\u043d\u043e \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -960,
        0
      ]
    },
    {
      "parameters": {
        "chatId": "={{ $('\u0417\u0430\u043f\u0443\u0441\u043a \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438').first().json.chat_id || $env.TELEGRAM_CHAT_ID }}",
        "text": "=\u26a0\ufe0f \u0414\u0435\u043d\u044c {{ $('\u0417\u0430\u043f\u0443\u0441\u043a \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438').first().json.day }}: \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f \u043d\u0435 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u0430 \u2014 \u0441\u0442\u0430\u0442\u0443\u0441 \u00ab{{ $json.status }}\u00bb (\u0437\u0430\u0449\u0438\u0442\u0430 \u043e\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430).",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "id": "p-already",
      "name": "\u0423\u0436\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043e",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        -740,
        160
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000
    },
    {
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $env.GOOGLE_SHEETS_ID }}"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "pipeline"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "day_number": "={{ $('\u0417\u0430\u043f\u0443\u0441\u043a \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438').first().json.day }}",
            "status": "publishing"
          },
          "matchingColumns": [
            "day_number"
          ],
          "schema": []
        },
        "options": {}
      },
      "id": "p-set-publishing",
      "name": "\u0421\u0442\u0430\u0442\u0443\u0441: publishing",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        -740,
        -120
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://backend.blotato.com/v2/media",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "blotato-api-key",
              "value": "={{ $env.BLOTATO_API_KEY }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ url: $('\u0421\u0442\u0440\u043e\u043a\u0430 \u0434\u043d\u044f').first().json.final_url }) }}",
        "options": {}
      },
      "id": "p-media",
      "name": "Blotato: \u043c\u0435\u0434\u0438\u0430",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -520,
        -120
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://backend.blotato.com/v2/posts",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "blotato-api-key",
              "value": "={{ $env.BLOTATO_API_KEY }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ post: { accountId: $env.BLOTATO_ID_LINKEDIN, target: { targetType: 'linkedin' }, content: { platform: 'linkedin', text: $('\u0421\u0442\u0440\u043e\u043a\u0430 \u0434\u043d\u044f').first().json.caption_linkedin, mediaUrls: [ $('Blotato: \u043c\u0435\u0434\u0438\u0430').first().json.url ] } } }) }}",
        "options": {}
      },
      "id": "p-linkedin",
      "name": "\u041f\u043e\u0441\u0442: LinkedIn",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -300,
        -120
      ],
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://backend.blotato.com/v2/posts",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "blotato-api-key",
              "value": "={{ $env.BLOTATO_API_KEY }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ post: { accountId: $env.BLOTATO_ID_INSTAGRAM_1, target: { targetType: 'instagram' }, content: { platform: 'instagram', text: $('\u0421\u0442\u0440\u043e\u043a\u0430 \u0434\u043d\u044f').first().json.caption_instagram, mediaUrls: [ $('Blotato: \u043c\u0435\u0434\u0438\u0430').first().json.url ] } } }) }}",
        "options": {}
      },
      "id": "p-ig1",
      "name": "\u041f\u043e\u0441\u0442: Instagram 1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -80,
        -120
      ],
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://backend.blotato.com/v2/posts",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "blotato-api-key",
              "value": "={{ $env.BLOTATO_API_KEY }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ post: { accountId: $env.BLOTATO_ID_INSTAGRAM_2, target: { targetType: 'instagram' }, content: { platform: 'instagram', text: ($('\u0421\u0442\u0440\u043e\u043a\u0430 \u0434\u043d\u044f').first().json.caption_instagram_2 || $('\u0421\u0442\u0440\u043e\u043a\u0430 \u0434\u043d\u044f').first().json.caption_instagram), mediaUrls: [ $('Blotato: \u043c\u0435\u0434\u0438\u0430').first().json.url ] } } }) }}",
        "options": {}
      },
      "id": "p-ig2",
      "name": "\u041f\u043e\u0441\u0442: Instagram 2",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        140,
        -120
      ],
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://backend.blotato.com/v2/posts",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "blotato-api-key",
              "value": "={{ $env.BLOTATO_API_KEY }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ post: { accountId: $env.BLOTATO_ID_YOUTUBE, target: { targetType: 'youtube', title: $('\u0421\u0442\u0440\u043e\u043a\u0430 \u0434\u043d\u044f').first().json.title_youtube, privacyStatus: 'public', shouldNotifySubscribers: 'false' }, content: { platform: 'youtube', text: $('\u0421\u0442\u0440\u043e\u043a\u0430 \u0434\u043d\u044f').first().json.caption_youtube, mediaUrls: [ $('Blotato: \u043c\u0435\u0434\u0438\u0430').first().json.url ] } } }) }}",
        "options": {}
      },
      "id": "p-youtube",
      "name": "\u041f\u043e\u0441\u0442: YouTube",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        360,
        -120
      ],
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://backend.blotato.com/v2/posts",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "blotato-api-key",
              "value": "={{ $env.BLOTATO_API_KEY }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ post: { accountId: $env.BLOTATO_ID_FACEBOOK, target: { targetType: 'facebook', pageId: $env.BLOTATO_FACEBOOK_PAGE_ID }, content: { platform: 'facebook', text: $('\u0421\u0442\u0440\u043e\u043a\u0430 \u0434\u043d\u044f').first().json.caption_instagram, mediaUrls: [ $('Blotato: \u043c\u0435\u0434\u0438\u0430').first().json.url ] } } }) }}",
        "options": {}
      },
      "id": "p-facebook",
      "name": "\u041f\u043e\u0441\u0442: Facebook",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        360,
        40
      ],
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://backend.blotato.com/v2/posts",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "blotato-api-key",
              "value": "={{ $env.BLOTATO_API_KEY }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ post: { accountId: $env.BLOTATO_ID_TIKTOK, target: { targetType: 'tiktok', privacyLevel: 'PUBLIC_TO_EVERYONE', disabledComments: false, disabledDuet: false, disabledStitch: false, isBrandedContent: false, isYourBrand: false, isAiGenerated: true }, content: { platform: 'tiktok', text: $('\u0421\u0442\u0440\u043e\u043a\u0430 \u0434\u043d\u044f').first().json.caption_instagram, mediaUrls: [ $('Blotato: \u043c\u0435\u0434\u0438\u0430').first().json.url ] } } }) }}",
        "options": {}
      },
      "id": "p-tiktok",
      "name": "\u041f\u043e\u0441\u0442: TikTok",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        360,
        200
      ],
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "jsCode": "const names = [\n  ['LinkedIn', '\u041f\u043e\u0441\u0442: LinkedIn'],\n  ['IG1', '\u041f\u043e\u0441\u0442: Instagram 1'],\n  ['IG2', '\u041f\u043e\u0441\u0442: Instagram 2'],\n  ['YouTube', '\u041f\u043e\u0441\u0442: YouTube'],\n  ['Facebook', '\u041f\u043e\u0441\u0442: Facebook'],\n  ['TikTok', '\u041f\u043e\u0441\u0442: TikTok'],\n];\nconst results = {};\nlet okCount = 0;\nconst failed = [];\n\nfor (const [label, node] of names) {\n  let j = {};\n  try { j = $(node).first().json || {}; } catch (e) { j = { error: '\u0443\u0437\u0435\u043b \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b\u0441\u044f' }; }\n  if (j.error) {\n    const errText = typeof j.error === 'string' ? j.error : (j.error.message || JSON.stringify(j.error));\n    failed.push(label + ': ' + String(errText).slice(0, 200));\n    results[label] = { ok: false, error: errText };\n  } else {\n    okCount++;\n    results[label] = { ok: true, response: j };\n  }\n}\n\nconst day = $('\u0417\u0430\u043f\u0443\u0441\u043a \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438').first().json.day;\nconst total = Number($env.CHALLENGE_TOTAL_DAYS || 200);\nconst status = failed.length === 0 ? 'done' : (okCount === 0 ? 'error' : 'done_partial');\nconst lines = names.map(([label]) => results[label].ok ? label + ' \u2705' : label + ' \u274c').join(' / ');\nconst summary = (failed.length === 0 ? '\u2705' : '\u26a0\ufe0f') + ` \u0414\u0435\u043d\u044c ${day}/${total} \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d: ` + lines + (failed.length ? '\\n\\n\u041e\u0448\u0438\u0431\u043a\u0438:\\n' + failed.join('\\n') : '');\n\nreturn [{ json: {\n  day,\n  status,\n  post_urls: JSON.stringify(results),\n  error_log: failed.join(' | '),\n  summary\n} }];"
      },
      "id": "p-collect",
      "name": "\u0421\u043e\u0431\u0440\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        580,
        -120
      ]
    },
    {
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $env.GOOGLE_SHEETS_ID }}"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "pipeline"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "day_number": "={{ $json.day }}",
            "post_urls": "={{ $json.post_urls }}",
            "status": "={{ $json.status }}",
            "error_log": "={{ $json.error_log }}"
          },
          "matchingColumns": [
            "day_number"
          ],
          "schema": []
        },
        "options": {}
      },
      "id": "p-save",
      "name": "\u0421\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        800,
        -120
      ]
    },
    {
      "parameters": {
        "chatId": "={{ $('\u0417\u0430\u043f\u0443\u0441\u043a \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438').first().json.chat_id || $env.TELEGRAM_CHAT_ID }}",
        "text": "={{ $('\u0421\u043e\u0431\u0440\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b').first().json.summary }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "id": "p-summary",
      "name": "\u0418\u0442\u043e\u0433 \u0432 Telegram",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1020,
        -120
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000
    }
  ],
  "connections": {
    "\u0417\u0430\u043f\u0443\u0441\u043a \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438": {
      "main": [
        [
          {
            "node": "\u0421\u0442\u0440\u043e\u043a\u0430 \u0434\u043d\u044f",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u0421\u0442\u0440\u043e\u043a\u0430 \u0434\u043d\u044f": {
      "main": [
        [
          {
            "node": "\u041c\u043e\u0436\u043d\u043e \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u041c\u043e\u0436\u043d\u043e \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c?": {
      "main": [
        [
          {
            "node": "\u0421\u0442\u0430\u0442\u0443\u0441: publishing",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "\u0423\u0436\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043e",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u0421\u0442\u0430\u0442\u0443\u0441: publishing": {
      "main": [
        [
          {
            "node": "Blotato: \u043c\u0435\u0434\u0438\u0430",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Blotato: \u043c\u0435\u0434\u0438\u0430": {
      "main": [
        [
          {
            "node": "\u041f\u043e\u0441\u0442: LinkedIn",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u041f\u043e\u0441\u0442: LinkedIn": {
      "main": [
        [
          {
            "node": "\u041f\u043e\u0441\u0442: Instagram 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u041f\u043e\u0441\u0442: Instagram 1": {
      "main": [
        [
          {
            "node": "\u041f\u043e\u0441\u0442: Instagram 2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u041f\u043e\u0441\u0442: Instagram 2": {
      "main": [
        [
          {
            "node": "\u041f\u043e\u0441\u0442: YouTube",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u041f\u043e\u0441\u0442: YouTube": {
      "main": [
        [
          {
            "node": "\u041f\u043e\u0441\u0442: Facebook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u041f\u043e\u0441\u0442: Facebook": {
      "main": [
        [
          {
            "node": "\u041f\u043e\u0441\u0442: TikTok",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u041f\u043e\u0441\u0442: TikTok": {
      "main": [
        [
          {
            "node": "\u0421\u043e\u0431\u0440\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u0421\u043e\u0431\u0440\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b": {
      "main": [
        [
          {
            "node": "\u0421\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u0421\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442": {
      "main": [
        [
          {
            "node": "\u0418\u0442\u043e\u0433 \u0432 Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}