8
n8n 中文网amn8n.com

TG-Bot-模块-检查_订阅-v4-数据库-销售-完整版

高级

这是一个Building Blocks, Marketing领域的自动化工作流,包含 45 个节点。主要使用 If, Set, Switch, Postgres, Telegram 等节点。 使用 Postgres 验证 Telegram 频道订阅并进行访问控制

前置要求
  • PostgreSQL 数据库连接信息
  • Telegram Bot Token
  • Google Drive API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "At3piGg3jQlWocQ0",
  "meta": {
    "instanceId": "888b5b52ac2aa3f8f1bab6800cae8fce6f3d7947e840e64245b5198449908655",
    "templateCredsSetupCompleted": true
  },
  "name": "TG-Bot-模块-检查_订阅-v4-数据库-销售-完整版",
  "tags": [
    {
      "id": "EwFGeL3ePPNgm0R7",
      "name": "telegram",
      "createdAt": "2025-02-10T18:10:47.435Z",
      "updatedAt": "2025-02-10T18:10:47.435Z"
    },
    {
      "id": "XPad0ERjSdqfxG52",
      "name": "module",
      "createdAt": "2025-03-31T08:11:00.151Z",
      "updatedAt": "2025-03-31T08:11:00.151Z"
    },
    {
      "id": "2ocrWSzdKoCOU2AC",
      "name": "sell",
      "createdAt": "2025-04-19T15:39:51.859Z",
      "updatedAt": "2025-04-19T15:39:51.859Z"
    }
  ],
  "nodes": [
    {
      "id": "a7919674-7ee6-48a2-a016-d3e5fb8d11cb",
      "name": "便签 3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -60,
        140
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "e5cfe2c0-221b-46a0-afad-071fb40b1c84",
      "name": "获取订阅状态",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2820,
        -1980
      ],
      "webhookId": "55bb75a5-c9d5-4cec-a3de-d7bcf9205d75",
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "f49053b9-9ac3-4b0d-9452-6564dd6583b9",
      "name": "获取频道",
      "type": "n8n-nodes-base.postgres",
      "position": [
        2600,
        -1980
      ],
      "parameters": {},
      "typeVersion": 2.5
    },
    {
      "id": "4635c188-483f-4622-b0fc-61f9bd2fbd50",
      "name": "合并状态",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        3040,
        -1980
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "63b098c5-d263-44ce-8e97-25f65a336117",
      "name": "检查",
      "type": "n8n-nodes-base.if",
      "position": [
        3260,
        -1980
      ],
      "parameters": {},
      "executeOnce": true,
      "typeVersion": 2.2,
      "alwaysOutputData": false
    },
    {
      "id": "01a28e03-3afb-444f-a1ec-4d91f4ae445a",
      "name": "检查失败",
      "type": "n8n-nodes-base.telegram",
      "position": [
        3480,
        -1780
      ],
      "webhookId": "3b1f1918-46ea-49c3-b741-263ccf7d82ad",
      "parameters": {},
      "executeOnce": true,
      "typeVersion": 1.2
    },
    {
      "id": "3ef42885-7096-4bca-b46b-e6e6098fd204",
      "name": "获取文件",
      "type": "n8n-nodes-base.googleDrive",
      "disabled": true,
      "position": [
        3480,
        -2180
      ],
      "parameters": {},
      "executeOnce": false,
      "typeVersion": 3
    },
    {
      "id": "85dac9aa-c453-49f8-888a-9d868715ed43",
      "name": "下载文件",
      "type": "n8n-nodes-base.googleDrive",
      "disabled": true,
      "position": [
        3700,
        -2180
      ],
      "parameters": {},
      "typeVersion": 3
    },
    {
      "id": "f62b58f5-2c43-48c6-8421-5db9b1270411",
      "name": "添加频道",
      "type": "n8n-nodes-base.postgres",
      "onError": "continueErrorOutput",
      "position": [
        1940,
        -780
      ],
      "parameters": {},
      "typeVersion": 2.5
    },
    {
      "id": "5379c208-1b79-48d2-9c4b-448cf97cf911",
      "name": "变量 TG",
      "type": "n8n-nodes-base.set",
      "position": [
        160,
        -180
      ],
      "parameters": {},
      "typeVersion": 3.4
    },
    {
      "id": "52d70635-add3-4f08-8754-10be51121fcc",
      "name": "初始化",
      "type": "n8n-nodes-base.set",
      "position": [
        400,
        -180
      ],
      "parameters": {},
      "typeVersion": 3.4
    },
    {
      "id": "e994a732-e39d-4ccf-a16b-917c04d2857d",
      "name": "Telegram 触发器",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -60,
        -180
      ],
      "webhookId": "809e5116-a193-4afc-83d3-37c9cbce58cc",
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "555e8dbe-19a9-4ff4-9eab-8625f062788c",
      "name": "获取机器人状态",
      "type": "n8n-nodes-base.postgres",
      "position": [
        840,
        -380
      ],
      "parameters": {},
      "typeVersion": 2.5
    },
    {
      "id": "f6c60730-4534-46d7-ac21-aa2e6c60a25b",
      "name": "定义流程",
      "type": "n8n-nodes-base.switch",
      "position": [
        1060,
        -420
      ],
      "parameters": {},
      "typeVersion": 3.2,
      "alwaysOutputData": false
    },
    {
      "id": "04d84bd6-9684-4e0c-8d27-07bb193b16c0",
      "name": "命令",
      "type": "n8n-nodes-base.switch",
      "position": [
        1500,
        -1260
      ],
      "parameters": {},
      "retryOnFail": false,
      "typeVersion": 3.2
    },
    {
      "id": "7e061558-50d7-4ecc-be0c-7df9b3afdc70",
      "name": "频道存在",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2160,
        -780
      ],
      "webhookId": "76e016a2-1140-4188-8604-228ebf6bdf2e",
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "8c71e3cc-0646-43b0-a5f7-8f3adb900bd3",
      "name": "在检查订阅请求频道时更新机器人状态",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1940,
        -1380
      ],
      "parameters": {},
      "typeVersion": 2.5
    },
    {
      "id": "b24e4e29-0142-412a-aee8-daa834915130",
      "name": "请求添加频道",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1720,
        -1380
      ],
      "webhookId": "0176253b-d769-47ed-a87a-64b8bc12d16f",
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "01859e62-69b7-4ada-a5ff-b6ef7ff72677",
      "name": "在检查订阅请求频道1时更新机器人状态",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1940,
        -1180
      ],
      "parameters": {},
      "typeVersion": 2.5
    },
    {
      "id": "fe963f1a-73b8-4afd-a01d-c283d8ff6c91",
      "name": "请求删除频道",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1720,
        -1180
      ],
      "webhookId": "912db76f-817b-43fd-bb50-47cd96246ff8",
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "ce4685ca-63fa-4962-bf6c-037f6c15e4e7",
      "name": "请求新删除频道",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2160,
        -580
      ],
      "webhookId": "f94be931-c212-40ba-b153-027f035d4d5b",
      "parameters": {},
      "executeOnce": true,
      "typeVersion": 1.2
    },
    {
      "id": "d0aa6264-f929-42ac-a614-00eaf6d651a2",
      "name": "请求新添加频道",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2160,
        -980
      ],
      "webhookId": "20371a10-6111-4adc-b5ac-761350b6a3d7",
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "8a10c59e-a8f2-42b4-bc3a-1863e8e125ec",
      "name": "频道不存在",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2160,
        -380
      ],
      "webhookId": "bfb33130-79bf-4dda-b691-cd045ef3db02",
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "dfed929b-975d-494b-9aa9-73938b6d857a",
      "name": "删除频道",
      "type": "n8n-nodes-base.postgres",
      "onError": "continueErrorOutput",
      "position": [
        1940,
        -580
      ],
      "parameters": {},
      "typeVersion": 2.5
    },
    {
      "id": "bb12a749-78e1-4714-820a-5720e990ccf6",
      "name": "获取频道",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1720,
        -1580
      ],
      "parameters": {},
      "typeVersion": 2.5,
      "alwaysOutputData": true
    },
    {
      "id": "e3d23352-7be0-4d1f-80e3-53ee22d2ce9c",
      "name": "添加分割频道",
      "type": "n8n-nodes-base.summarize",
      "position": [
        1940,
        -1580
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "697ea427-4f9e-40ee-b7db-0a331ad7b216",
      "name": "频道",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2160,
        -1580
      ],
      "webhookId": "ededf0ab-5b67-4992-a817-7f1792bf36ed",
      "parameters": {},
      "executeOnce": true,
      "typeVersion": 1.2
    },
    {
      "id": "9e0607a1-72cb-4424-8632-f978e3faf528",
      "name": "定义类型",
      "type": "n8n-nodes-base.switch",
      "position": [
        620,
        -380
      ],
      "parameters": {},
      "typeVersion": 3.2
    },
    {
      "id": "a03415cd-1f3a-453f-a19c-91d547d43330",
      "name": "在启动时更新机器人状态",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1060,
        -780
      ],
      "parameters": {},
      "typeVersion": 2.5
    },
    {
      "id": "4a9856ca-0ace-4f2c-a7b2-138886f142d5",
      "name": "按钮",
      "type": "n8n-nodes-base.switch",
      "position": [
        840,
        -780
      ],
      "parameters": {},
      "typeVersion": 3.2,
      "alwaysOutputData": false
    },
    {
      "id": "e98dddbd-5d2f-4ae5-b24c-1ef663cbf244",
      "name": "成功",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1280,
        -780
      ],
      "webhookId": "748d3746-a859-4481-add4-f961563c3ef9",
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "2af1329e-7e60-445a-9567-f25feccef426",
      "name": "获取频道",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1500,
        -380
      ],
      "parameters": {},
      "typeVersion": 2.5,
      "alwaysOutputData": true
    },
    {
      "id": "5e91b148-a095-4238-8d29-5f81337fdaee",
      "name": "如果",
      "type": "n8n-nodes-base.if",
      "position": [
        1720,
        -380
      ],
      "parameters": {},
      "typeVersion": 2.2
    },
    {
      "id": "b6a8d046-d63f-4a94-b6f7-b50c59228662",
      "name": "欢迎消息 推荐",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1940,
        -1980
      ],
      "webhookId": "e3232618-af57-499a-8a09-2a67e9d13f9d",
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "03fc7662-d1fa-49b0-8574-a727f7aea2fd",
      "name": "欢迎消息 管理员",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1940,
        -1780
      ],
      "webhookId": "72fdfc11-adee-4111-9754-e0c9a9096433",
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "9de886ca-0e1b-4bcc-94e4-48bacb84b1f7",
      "name": "在启动时更新或插入机器人状态",
      "type": "n8n-nodes-base.postgres",
      "position": [
        2160,
        -1780
      ],
      "parameters": {},
      "typeVersion": 2.5
    },
    {
      "id": "ea3fbe94-f0db-42bf-8418-988252e8137d",
      "name": "推荐?",
      "type": "n8n-nodes-base.if",
      "position": [
        1720,
        -1780
      ],
      "parameters": {},
      "typeVersion": 2.2
    },
    {
      "id": "f872e8ee-a4d3-48ff-a8ad-a8c2693de284",
      "name": "更新机器人状态和推荐",
      "type": "n8n-nodes-base.postgres",
      "position": [
        2160,
        -1980
      ],
      "parameters": {},
      "typeVersion": 2.5
    },
    {
      "id": "34f90c75-eb5e-4aa8-b8c2-b31234805738",
      "name": "获取推荐",
      "type": "n8n-nodes-base.postgres",
      "position": [
        2380,
        -1980
      ],
      "parameters": {},
      "typeVersion": 2.5,
      "alwaysOutputData": true
    },
    {
      "id": "8b5373a2-7bb6-4d5f-876b-73f255cf5da7",
      "name": "检查成功",
      "type": "n8n-nodes-base.telegram",
      "position": [
        3480,
        -1980
      ],
      "webhookId": "8a3ab6e4-e327-43d0-bbcc-af62ee69bfec",
      "parameters": {},
      "executeOnce": true,
      "typeVersion": 1.2
    },
    {
      "id": "d1dbf21a-9ad4-4ef6-93d5-f0afecefc081",
      "name": "检查成功 + 文件",
      "type": "n8n-nodes-base.telegram",
      "disabled": true,
      "position": [
        3920,
        -2180
      ],
      "webhookId": "585738a3-d849-47af-a118-c38d70b14204",
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "57798b03-2661-4842-a547-b9d42b10b98c",
      "name": "是管理员吗?",
      "type": "n8n-nodes-base.if",
      "position": [
        620,
        -180
      ],
      "parameters": {},
      "typeVersion": 2.2
    },
    {
      "id": "a0878b73-7fa6-4cac-8410-ea6bdacc9964",
      "name": "便签 4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -500,
        -500
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "bbb66815-c58a-40a1-b425-669f94a20c34",
      "name": "便签 5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -500,
        -180
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "203853e7-5df1-4305-82d8-9a1a2416ff38",
      "name": "便签6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -500,
        140
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "2142c115-ceca-4a1c-811f-12cca4b35069",
  "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
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

高级 - 构建模块, 营销

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量45
分类2
节点类型10
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者
Andrew

Andrew

@boanse

Analyst-Developer

外部链接
在 n8n.io 查看

分享此工作流