{
  "name": "Verify Telegram channel subscriptions with access control using Postgres",
  "nodes": [
    {
      "id": "a7919674-7ee6-48a2-a016-d3e5fb8d11cb",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -60,
        140
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "e5cfe2c0-221b-46a0-afad-071fb40b1c84",
      "name": "Get Subscription statuses",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2820,
        -1980
      ]
    },
    {
      "id": "f49053b9-9ac3-4b0d-9452-6564dd6583b9",
      "name": "Get Channels",
      "type": "n8n-nodes-base.postgres",
      "position": [
        2600,
        -1980
      ]
    },
    {
      "id": "4635c188-483f-4622-b0fc-61f9bd2fbd50",
      "name": "Union statuses",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        3040,
        -1980
      ]
    },
    {
      "id": "63b098c5-d263-44ce-8e97-25f65a336117",
      "name": "Check",
      "type": "n8n-nodes-base.if",
      "position": [
        3260,
        -1980
      ]
    },
    {
      "id": "01a28e03-3afb-444f-a1ec-4d91f4ae445a",
      "name": "Check failed",
      "type": "n8n-nodes-base.telegram",
      "position": [
        3480,
        -1780
      ]
    },
    {
      "id": "3ef42885-7096-4bca-b46b-e6e6098fd204",
      "name": "Get File",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        3480,
        -2180
      ]
    },
    {
      "id": "85dac9aa-c453-49f8-888a-9d868715ed43",
      "name": "Download File",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        3700,
        -2180
      ]
    },
    {
      "id": "f62b58f5-2c43-48c6-8421-5db9b1270411",
      "name": "Add Channel",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1940,
        -780
      ]
    },
    {
      "id": "5379c208-1b79-48d2-9c4b-448cf97cf911",
      "name": "Variables TG",
      "type": "n8n-nodes-base.set",
      "position": [
        160,
        -180
      ]
    },
    {
      "id": "52d70635-add3-4f08-8754-10be51121fcc",
      "name": "Initialization",
      "type": "n8n-nodes-base.set",
      "position": [
        400,
        -180
      ]
    },
    {
      "id": "e994a732-e39d-4ccf-a16b-917c04d2857d",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -60,
        -180
      ]
    },
    {
      "id": "555e8dbe-19a9-4ff4-9eab-8625f062788c",
      "name": "Get Bot Status",
      "type": "n8n-nodes-base.postgres",
      "position": [
        840,
        -380
      ]
    },
    {
      "id": "f6c60730-4534-46d7-ac21-aa2e6c60a25b",
      "name": "Define flow",
      "type": "n8n-nodes-base.switch",
      "position": [
        1060,
        -420
      ]
    },
    {
      "id": "04d84bd6-9684-4e0c-8d27-07bb193b16c0",
      "name": "Commands",
      "type": "n8n-nodes-base.switch",
      "position": [
        1500,
        -1260
      ]
    },
    {
      "id": "7e061558-50d7-4ecc-be0c-7df9b3afdc70",
      "name": "Channel Exists",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2160,
        -780
      ]
    },
    {
      "id": "8c71e3cc-0646-43b0-a5f7-8f3adb900bd3",
      "name": "Update bot status on CHECK SUBSCRIPTION REQUEST CHANNEL",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1940,
        -1380
      ]
    },
    {
      "id": "b24e4e29-0142-412a-aee8-daa834915130",
      "name": "Request Add Channel",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1720,
        -1380
      ]
    },
    {
      "id": "01859e62-69b7-4ada-a5ff-b6ef7ff72677",
      "name": "Update bot status on CHECK SUBSCRIPTION REQUEST CHANNEL1",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1940,
        -1180
      ]
    },
    {
      "id": "fe963f1a-73b8-4afd-a01d-c283d8ff6c91",
      "name": "Request Delete Channel",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1720,
        -1180
      ]
    },
    {
      "id": "ce4685ca-63fa-4962-bf6c-037f6c15e4e7",
      "name": "Request New Delete Channel",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2160,
        -580
      ]
    },
    {
      "id": "d0aa6264-f929-42ac-a614-00eaf6d651a2",
      "name": "Request New Add Channel",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2160,
        -980
      ]
    },
    {
      "id": "8a10c59e-a8f2-42b4-bc3a-1863e8e125ec",
      "name": "Channel Not Exists",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2160,
        -380
      ]
    },
    {
      "id": "dfed929b-975d-494b-9aa9-73938b6d857a",
      "name": "Delete Channel",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1940,
        -580
      ]
    },
    {
      "id": "bb12a749-78e1-4714-820a-5720e990ccf6",
      "name": "Get Channels ",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1720,
        -1580
      ]
    },
    {
      "id": "e3d23352-7be0-4d1f-80e3-53ee22d2ce9c",
      "name": "Add Divide Channels",
      "type": "n8n-nodes-base.summarize",
      "position": [
        1940,
        -1580
      ]
    },
    {
      "id": "697ea427-4f9e-40ee-b7db-0a331ad7b216",
      "name": "Channels",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2160,
        -1580
      ]
    },
    {
      "id": "9e0607a1-72cb-4424-8632-f978e3faf528",
      "name": "Define Type",
      "type": "n8n-nodes-base.switch",
      "position": [
        620,
        -380
      ]
    },
    {
      "id": "a03415cd-1f3a-453f-a19c-91d547d43330",
      "name": "Update bot status on START",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1060,
        -780
      ]
    },
    {
      "id": "4a9856ca-0ace-4f2c-a7b2-138886f142d5",
      "name": "Buttons",
      "type": "n8n-nodes-base.switch",
      "position": [
        840,
        -780
      ]
    },
    {
      "id": "e98dddbd-5d2f-4ae5-b24c-1ef663cbf244",
      "name": "Success",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1280,
        -780
      ]
    },
    {
      "id": "2af1329e-7e60-445a-9567-f25feccef426",
      "name": "Get Channels  ",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1500,
        -380
      ]
    },
    {
      "id": "5e91b148-a095-4238-8d29-5f81337fdaee",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        1720,
        -380
      ]
    },
    {
      "id": "b6a8d046-d63f-4a94-b6f7-b50c59228662",
      "name": "Welcome message Referal",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1940,
        -1980
      ]
    },
    {
      "id": "03fc7662-d1fa-49b0-8574-a727f7aea2fd",
      "name": "Welcome message Manager",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1940,
        -1780
      ]
    },
    {
      "id": "9de886ca-0e1b-4bcc-94e4-48bacb84b1f7",
      "name": "Upsert bot status on START",
      "type": "n8n-nodes-base.postgres",
      "position": [
        2160,
        -1780
      ]
    },
    {
      "id": "ea3fbe94-f0db-42bf-8418-988252e8137d",
      "name": "Referal?",
      "type": "n8n-nodes-base.if",
      "position": [
        1720,
        -1780
      ]
    },
    {
      "id": "f872e8ee-a4d3-48ff-a8ad-a8c2693de284",
      "name": "Update bot status and referal",
      "type": "n8n-nodes-base.postgres",
      "position": [
        2160,
        -1980
      ]
    },
    {
      "id": "34f90c75-eb5e-4aa8-b8c2-b31234805738",
      "name": "Get Referal",
      "type": "n8n-nodes-base.postgres",
      "position": [
        2380,
        -1980
      ]
    },
    {
      "id": "8b5373a2-7bb6-4d5f-876b-73f255cf5da7",
      "name": "Check success",
      "type": "n8n-nodes-base.telegram",
      "position": [
        3480,
        -1980
      ]
    },
    {
      "id": "d1dbf21a-9ad4-4ef6-93d5-f0afecefc081",
      "name": "Check success + File",
      "type": "n8n-nodes-base.telegram",
      "position": [
        3920,
        -2180
      ]
    },
    {
      "id": "57798b03-2661-4842-a547-b9d42b10b98c",
      "name": "Is Admin?",
      "type": "n8n-nodes-base.if",
      "position": [
        620,
        -180
      ]
    },
    {
      "id": "a0878b73-7fa6-4cac-8410-ea6bdacc9964",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -500,
        -500
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "bbb66815-c58a-40a1-b425-669f94a20c34",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -500,
        -180
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "203853e7-5df1-4305-82d8-9a1a2416ff38",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -500,
        140
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    }
  ],
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Delete Channel",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Channel Not Exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check": {
      "main": [
        [
          {
            "node": "Get File",
            "type": "main",
            "index": 0
          },
          {
            "node": "Check success",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Check failed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Buttons": {
      "main": [
        [
          {
            "node": "Update bot status on START",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Channels": {
      "main": [
        []
      ]
    },
    "Commands": {
      "main": [
        [],
        [
          {
            "node": "Referal?",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Channels ",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Request Add Channel",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Request Delete Channel",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get File": {
      "main": [
        [
          {
            "node": "Download File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Referal?": {
      "main": [
        [
          {
            "node": "Welcome message Referal",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Welcome message Manager",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Admin?": {
      "main": [
        [
          {
            "node": "Define Type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Channel": {
      "main": [
        [
          {
            "node": "Request New Add Channel",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Channel Exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Define Type": {
      "main": [
        [
          {
            "node": "Buttons",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Bot Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Define flow": {
      "main": [
        [
          {
            "node": "Commands",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Add Channel",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Channels  ",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Get Referal": {
      "main": [
        [
          {
            "node": "Get Channels",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Channels": {
      "main": [
        [
          {
            "node": "Get Subscription statuses",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Variables TG": {
      "main": [
        [
          {
            "node": "Initialization",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download File": {
      "main": [
        [
          {
            "node": "Check success + File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Channels ": {
      "main": [
        [
          {
            "node": "Add Divide Channels",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete Channel": {
      "main": [
        [
          {
            "node": "Request New Delete Channel",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Get Bot Status": {
      "main": [
        [
          {
            "node": "Define flow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Channels  ": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Initialization": {
      "main": [
        [
          {
            "node": "Is Admin?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Union statuses": {
      "main": [
        [
          {
            "node": "Check",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Variables TG",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Divide Channels": {
      "main": [
        [
          {
            "node": "Channels",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Request Add Channel": {
      "main": [
        [
          {
            "node": "Update bot status on CHECK SUBSCRIPTION REQUEST CHANNEL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check success + File": {
      "main": [
        []
      ]
    },
    "Request Delete Channel": {
      "main": [
        [
          {
            "node": "Update bot status on CHECK SUBSCRIPTION REQUEST CHANNEL1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Welcome message Manager": {
      "main": [
        [
          {
            "node": "Upsert bot status on START",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Welcome message Referal": {
      "main": [
        [
          {
            "node": "Update bot status and referal",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Subscription statuses": {
      "main": [
        [
          {
            "node": "Union statuses",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update bot status on START": {
      "main": [
        [
          {
            "node": "Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update bot status and referal": {
      "main": [
        [
          {
            "node": "Get Referal",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}