{
  "name": "Nodbot - Instagram to Telegram crosspost with dedupe",
  "nodes": [
    {
      "parameters": {
        "path": "instagram-telegram-crosspost",
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "id": "c8b1d462-840b-4d4b-a52d-116604a74dc3",
      "name": "Webhook or schedule input",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        260
      ]
    },
    {
      "parameters": {
        "jsCode": "const input = $json.body ?? $json;\nconst media = input.media ?? input;\nconst captionRaw = String(media.caption ?? '').trim();\nconst safeCaption = captionRaw\n  .replace(/<[^>]*>/g, '')\n  .replace(/\n{3,}/g, '\n\n')\n  .slice(0, 900);\n\nconst hashtags = [...captionRaw.matchAll(/#[\\p{L}\\p{N}_]+/gu)].map(m => m[0].toLowerCase());\nconst permalink = String(media.permalink ?? '').trim();\nconst mediaUrl = String(media.media_url ?? '').trim();\nconst mediaType = String(media.media_type ?? 'IMAGE').toUpperCase();\n\nif (!media.id || !permalink) {\n  throw new Error('Instagram media id and permalink are required');\n}\n\nconst telegramText = `${safeCaption}\n\nИсточник: ${permalink}`.trim();\n\nreturn [{\n  json: {\n    dedupe_key: `instagram:${media.id}`,\n    media_id: media.id,\n    media_type: mediaType,\n    media_url: mediaUrl,\n    permalink,\n    hashtags,\n    telegram: {\n      chat_id: input.telegram?.chat_id,\n      text: telegramText,\n      send_as_photo: mediaType === 'IMAGE' && Boolean(mediaUrl),\n      parse_mode: 'HTML'\n    }\n  }\n}];"
      },
      "id": "8e698b01-b076-4051-a14a-a33b552a91da",
      "name": "Normalize caption and media",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        280,
        260
      ]
    },
    {
      "parameters": {},
      "id": "0a8ac573-400b-4eca-b4c9-a9d772717243",
      "name": "Check dedupe",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        560,
        260
      ]
    },
    {
      "parameters": {},
      "id": "3f0ac76f-3761-4acb-81bd-f71c2e90a80e",
      "name": "Send Telegram post",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 2,
      "position": [
        840,
        260
      ]
    },
    {
      "parameters": {},
      "id": "6cb5d8ae-a9f3-418f-8e19-410d96d9e09d",
      "name": "Audit result",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2,
      "position": [
        1120,
        260
      ]
    }
  ],
  "connections": {
    "Webhook or schedule input": {
      "main": [
        [
          {
            "node": "Normalize caption and media",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize caption and media": {
      "main": [
        [
          {
            "node": "Check dedupe",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check dedupe": {
      "main": [
        [
          {
            "node": "Send Telegram post",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Telegram post": {
      "main": [
        [
          {
            "node": "Audit result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    "nodbot",
    "production",
    "template"
  ],
  "triggerCount": 1,
  "updatedAt": "2026-05-30T00:00:00.000Z",
  "versionId": "df611c99-c997-4034-84ed-10bd108eea6e",
  "meta": {
    "templateCredsSetupCompleted": false
  }
}