TG机器人-抽奖模块-v4-数据库-销售完整版
高级
这是一个Building Blocks、Marketing领域的自动化工作流,包含 44 个节点。主要使用 If、Set、Sort、Switch、Postgres 等节点。 Telegram频道订阅者抽奖活动("抽奖"模块)
前置要求
- •PostgreSQL 数据库连接信息
- •Telegram Bot Token
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"id": "Vkw2rLJx7PuE9ev2",
"meta": {
"instanceId": "888b5b52ac2aa3f8f1bab6800cae8fce6f3d7947e840e64245b5198449908655",
"templateCredsSetupCompleted": true
},
"name": "TG-Bot-Module-Giveaway-v4-db-sell-full",
"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": "a88a431f-4277-4ed0-91eb-17560a31b832",
"name": "便签14",
"type": "n8n-nodes-base.stickyNote",
"position": [
700,
560
],
"parameters": {
"content": ""
},
"typeVersion": 1
},
{
"id": "0824d027-e77d-40a8-a8ce-0cbe035e1328",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
1160,
560
],
"parameters": {
"content": ""
},
"typeVersion": 1
},
{
"id": "6b98af66-355c-417f-b0da-524c29fdd448",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-500,
1340
],
"parameters": {
"content": ""
},
"typeVersion": 1
},
{
"id": "e08ddd2f-02b7-4b66-b701-7e9af06907e4",
"name": "便签 2",
"type": "n8n-nodes-base.stickyNote",
"position": [
1840,
1560
],
"parameters": {
"content": ""
},
"typeVersion": 1
},
{
"id": "09741b6c-9357-4008-ad12-9f00ccec4338",
"name": "初始化",
"type": "n8n-nodes-base.set",
"position": [
-40,
980
],
"parameters": {},
"typeVersion": 3.4
},
{
"id": "fffb74ce-86dc-4287-bbb6-a8f2ddafe091",
"name": "欢迎消息 推荐",
"type": "n8n-nodes-base.telegram",
"position": [
740,
580
],
"webhookId": "e51c1bc4-21d1-4658-aedc-69a5f0861bcb",
"parameters": {},
"typeVersion": 1.2
},
{
"id": "187122c5-8089-4745-8f3e-7cae49fea60f",
"name": "欢迎消息 管理员",
"type": "n8n-nodes-base.telegram",
"position": [
740,
780
],
"webhookId": "41c10201-f9e3-4aeb-a350-4d6fd4327141",
"parameters": {},
"typeVersion": 1.2
},
{
"id": "7a4135f6-fb98-43ca-b85a-a95f19a84de9",
"name": "启动时更新机器人状态",
"type": "n8n-nodes-base.postgres",
"position": [
940,
780
],
"parameters": {},
"typeVersion": 2.5
},
{
"id": "2483ca3f-7158-455c-9250-65121bb16387",
"name": "添加参与者到抽奖活动",
"type": "n8n-nodes-base.postgres",
"position": [
1220,
580
],
"parameters": {},
"typeVersion": 2.5
},
{
"id": "cf7bc2c4-4d6c-42aa-a53a-8f3cf9b60079",
"name": "获取机器人状态",
"type": "n8n-nodes-base.postgres",
"position": [
740,
980
],
"parameters": {},
"typeVersion": 2.5
},
{
"id": "9bbf4db8-33e3-4cc1-9e6c-59f4552cd62e",
"name": "开始?",
"type": "n8n-nodes-base.if",
"position": [
160,
980
],
"parameters": {},
"typeVersion": 2.2
},
{
"id": "7b56225d-eab4-42d8-bb75-11afda52f1d2",
"name": "按钮?",
"type": "n8n-nodes-base.if",
"position": [
340,
980
],
"parameters": {},
"typeVersion": 1
},
{
"id": "a5b60598-b688-467c-822b-6dc28a1ba4f2",
"name": "推荐?",
"type": "n8n-nodes-base.if",
"position": [
560,
780
],
"parameters": {},
"typeVersion": 2.2
},
{
"id": "ad57cb94-9804-4296-82b4-4b683c02295e",
"name": "定义流程",
"type": "n8n-nodes-base.switch",
"position": [
940,
980
],
"parameters": {},
"typeVersion": 3.2,
"alwaysOutputData": false
},
{
"id": "7dd5490c-633b-4727-8205-6b2945ec8ddc",
"name": "命令",
"type": "n8n-nodes-base.switch",
"position": [
1220,
980
],
"parameters": {},
"retryOnFail": false,
"typeVersion": 3.2
},
{
"id": "60748e12-5dc3-4d5f-aa1f-f4c3a904eac9",
"name": "频道列表",
"type": "n8n-nodes-base.telegram",
"position": [
1440,
980
],
"webhookId": "cba12533-45ae-4b13-9034-2313c0ec029b",
"parameters": {},
"typeVersion": 1.2
},
{
"id": "9ddfacd6-c3e3-4c01-91a5-8752b3bd8b31",
"name": "添加频道",
"type": "n8n-nodes-base.postgres",
"onError": "continueErrorOutput",
"position": [
1220,
1160
],
"parameters": {},
"retryOnFail": false,
"typeVersion": 2.5
},
{
"id": "bb74bc42-ef8b-4012-b7df-4bd12044652f",
"name": "按钮",
"type": "n8n-nodes-base.switch",
"position": [
940,
1820
],
"parameters": {},
"typeVersion": 3.2
},
{
"id": "d7dff496-0cb0-4621-bb6e-08655f52829d",
"name": "创建抽奖活动",
"type": "n8n-nodes-base.telegram",
"position": [
1440,
1820
],
"webhookId": "a3fe0320-2e7a-47af-9cc4-f12ba82f2d34",
"parameters": {},
"typeVersion": 1.2
},
{
"id": "4d86846a-9ace-47c7-8147-9520e7ecdb8f",
"name": "请求新频道",
"type": "n8n-nodes-base.telegram",
"position": [
1440,
1160
],
"webhookId": "fbefe5e0-761d-4e91-95b0-05553f50c931",
"parameters": {},
"typeVersion": 1.2
},
{
"id": "6bd742a7-3d4f-4fd3-96f1-11919be7ea00",
"name": "频道存在",
"type": "n8n-nodes-base.telegram",
"position": [
1440,
1360
],
"webhookId": "3c050a66-4cc9-41a7-a9d1-44adce6b5c4b",
"parameters": {},
"typeVersion": 1.2
},
{
"id": "38eacfc8-96d8-4ad9-8e3f-acd9b830467b",
"name": "定义抽奖步骤",
"type": "n8n-nodes-base.switch",
"position": [
1220,
1580
],
"parameters": {},
"typeVersion": 3.2,
"alwaysOutputData": false
},
{
"id": "181f2e2e-e8c6-4b38-91c9-9a81238ef12a",
"name": "获取参与者",
"type": "n8n-nodes-base.postgres",
"position": [
1660,
1580
],
"parameters": {},
"typeVersion": 2.5
},
{
"id": "8355aa35-1d3a-4a88-8b54-4639e1f095be",
"name": "随机参与者",
"type": "n8n-nodes-base.sort",
"position": [
1880,
1580
],
"parameters": {},
"executeOnce": false,
"typeVersion": 1
},
{
"id": "3af0984f-f383-4fe1-bad1-4841b792c499",
"name": "获取频道",
"type": "n8n-nodes-base.postgres",
"position": [
2080,
1580
],
"parameters": {},
"typeVersion": 2.5
},
{
"id": "32508ab0-b317-45f5-a683-217d2892b9ac",
"name": "合并状态",
"type": "n8n-nodes-base.aggregate",
"position": [
2500,
1580
],
"parameters": {},
"typeVersion": 1
},
{
"id": "34162676-517d-40c8-af24-280d521a2fc1",
"name": "检查成功?",
"type": "n8n-nodes-base.if",
"position": [
2700,
1580
],
"parameters": {},
"executeOnce": true,
"typeVersion": 2.2,
"alwaysOutputData": false
},
{
"id": "8ee97c98-5286-4850-912f-f4516e37d733",
"name": "检查成功",
"type": "n8n-nodes-base.telegram",
"disabled": true,
"position": [
2920,
1160
],
"webhookId": "56d509ee-5088-4fd1-8f58-2b1e89c77813",
"parameters": {},
"executeOnce": true,
"typeVersion": 1.2
},
{
"id": "bcf02704-7d88-49a1-8c33-024d99131ec5",
"name": "检查失败",
"type": "n8n-nodes-base.telegram",
"disabled": true,
"position": [
2920,
1360
],
"webhookId": "07b0223f-7d55-4eba-a8e4-41da8d23a264",
"parameters": {},
"executeOnce": true,
"typeVersion": 1.2
},
{
"id": "0df05a53-83e5-4a39-9d68-a4d4cd22414d",
"name": "给获胜者的短信",
"type": "n8n-nodes-base.telegram",
"position": [
2920,
1580
],
"webhookId": "1c4039a1-8cd9-4cdc-9694-f8ec12bb73ce",
"parameters": {},
"executeOnce": true,
"typeVersion": 1.2
},
{
"id": "7a161f59-7603-4074-9e9d-2ff8b99b7b73",
"name": "给管理员的短信",
"type": "n8n-nodes-base.telegram",
"position": [
3100,
1580
],
"webhookId": "93762c64-12e8-4b2d-8a09-67508e4e5f1c",
"parameters": {},
"executeOnce": true,
"typeVersion": 1.2
},
{
"id": "97d03ad2-9adb-4364-9e50-bd1d53529a20",
"name": "删除频道",
"type": "n8n-nodes-base.postgres",
"position": [
3300,
1160
],
"parameters": {},
"typeVersion": 2.5
},
{
"id": "cbdda4cb-879f-472b-8de7-9f374fa690ef",
"name": "删除参与者",
"type": "n8n-nodes-base.postgres",
"position": [
3300,
1360
],
"parameters": {},
"typeVersion": 2.5
},
{
"id": "5b72da60-2a11-44f9-a59a-2f702eeaec38",
"name": "结束消息",
"type": "n8n-nodes-base.telegram",
"position": [
3480,
1580
],
"webhookId": "eebf4215-6e5a-457e-ab3d-de7a1bfb7c71",
"parameters": {},
"typeVersion": 1.2
},
{
"id": "3bc4e559-c026-4096-860e-ae7aa6045647",
"name": "更新机器人状态为抽奖进行中",
"type": "n8n-nodes-base.postgres",
"position": [
1220,
1820
],
"parameters": {},
"typeVersion": 2.5
},
{
"id": "6e137946-d9a6-43e9-bb12-3f9d3f13424b",
"name": "更新机器人状态为抽奖请求频道",
"type": "n8n-nodes-base.postgres",
"position": [
1660,
980
],
"parameters": {},
"typeVersion": 2.5
},
{
"id": "5d00b729-3c03-4ca3-8a58-b9338d736742",
"name": "更新机器人状态和推荐",
"type": "n8n-nodes-base.postgres",
"position": [
940,
580
],
"parameters": {},
"typeVersion": 2.5
},
{
"id": "83c8e09c-9f46-4bf5-9401-744c4e229338",
"name": "启动时更新机器人状态",
"type": "n8n-nodes-base.postgres",
"position": [
3300,
1580
],
"parameters": {},
"typeVersion": 2.5
},
{
"id": "b417847e-480c-485b-b19c-f06c98cb43cd",
"name": "Telegram",
"type": "n8n-nodes-base.telegram",
"position": [
2300,
1580
],
"webhookId": "01817f8a-d271-4b5a-862f-752787802804",
"parameters": {},
"typeVersion": 1.2
},
{
"id": "4b585aea-96f3-4745-a821-736ff0525387",
"name": "便签 4",
"type": "n8n-nodes-base.stickyNote",
"position": [
-960,
680
],
"parameters": {
"content": ""
},
"typeVersion": 1
},
{
"id": "3fdb6f7f-7bfc-4184-b5e9-a93be2ca44c8",
"name": "便签 5",
"type": "n8n-nodes-base.stickyNote",
"position": [
-960,
1000
],
"parameters": {
"content": ""
},
"typeVersion": 1
},
{
"id": "d587af11-5501-4853-8ca7-4a5834a896f9",
"name": "变量 TG",
"type": "n8n-nodes-base.set",
"position": [
-280,
980
],
"parameters": {},
"typeVersion": 3.4
},
{
"id": "26b42428-0d68-4760-a9ec-e62c505a995f",
"name": "Telegram 触发器",
"type": "n8n-nodes-base.telegramTrigger",
"position": [
-500,
980
],
"webhookId": "6e3495bc-462f-4c3c-b310-d67e6da2f55c",
"parameters": {},
"typeVersion": 1.1
},
{
"id": "ddd0b0a5-ce75-4ed4-800b-7e118b7a507d",
"name": "便签6",
"type": "n8n-nodes-base.stickyNote",
"position": [
-960,
1340
],
"parameters": {
"content": ""
},
"typeVersion": 1
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "8d80b4ee-0bb7-428c-b04d-1b66c2541125",
"connections": {
"Start?": {
"main": [
[
{
"node": "Referal?",
"type": "main",
"index": 0
}
],
[
{
"node": "Button?",
"type": "main",
"index": 0
}
]
]
},
"Button?": {
"main": [
[
{
"node": "Buttons",
"type": "main",
"index": 0
}
],
[
{
"node": "Get Bot Status",
"type": "main",
"index": 0
}
]
]
},
"Buttons": {
"main": [
[
{
"node": "Update bot status on GIVEAWAY RUN",
"type": "main",
"index": 0
}
]
]
},
"Commands": {
"main": [
[
{
"node": "List Channels",
"type": "main",
"index": 0
}
]
]
},
"Referal?": {
"main": [
[
{
"node": "Welcome message Referal",
"type": "main",
"index": 0
}
],
[
{
"node": "Welcome message Manager",
"type": "main",
"index": 0
}
]
]
},
"Telegram": {
"main": [
[
{
"node": "Union Statuses",
"type": "main",
"index": 0
}
]
]
},
"Add channel": {
"main": [
[
{
"node": "Request New Channel",
"type": "main",
"index": 0
}
],
[
{
"node": "Channel Exists",
"type": "main",
"index": 0
}
]
]
},
"Define flow": {
"main": [
[
{
"node": "Commands",
"type": "main",
"index": 0
}
],
[
{
"node": "Add channel",
"type": "main",
"index": 0
}
],
[
{
"node": "Define Step Giveaway",
"type": "main",
"index": 0
}
]
]
},
"Get Channels": {
"main": [
[
{
"node": "Telegram",
"type": "main",
"index": 0
}
]
]
},
"Variables TG": {
"main": [
[
{
"node": "Initialization",
"type": "main",
"index": 0
}
]
]
},
"Check Success": {
"main": [
[]
]
},
"List Channels": {
"main": [
[
{
"node": "Update bot status on GIVEAWAY REQUEST CHANNEL",
"type": "main",
"index": 0
}
]
]
},
"Check Success?": {
"main": [
[
{
"node": "Check Success",
"type": "main",
"index": 0
},
{
"node": "SMS for Winner",
"type": "main",
"index": 0
}
],
[
{
"node": "Check Failed",
"type": "main",
"index": 0
}
]
]
},
"Get Bot Status": {
"main": [
[
{
"node": "Define flow",
"type": "main",
"index": 0
}
]
]
},
"Initialization": {
"main": [
[
{
"node": "Start?",
"type": "main",
"index": 0
}
]
]
},
"SMS for Winner": {
"main": [
[
{
"node": "SMS for Manager",
"type": "main",
"index": 0
}
]
]
},
"Union Statuses": {
"main": [
[
{
"node": "Check Success?",
"type": "main",
"index": 0
}
]
]
},
"Delete Channels": {
"main": [
[]
]
},
"SMS for Manager": {
"main": [
[
{
"node": "Delete Channels",
"type": "main",
"index": 0
},
{
"node": "Delete Participants",
"type": "main",
"index": 0
},
{
"node": "Update bot status on START ",
"type": "main",
"index": 0
}
]
]
},
"Get Participants": {
"main": [
[
{
"node": "Random Participants",
"type": "main",
"index": 0
}
]
]
},
"Telegram Trigger": {
"main": [
[
{
"node": "Variables TG",
"type": "main",
"index": 0
}
]
]
},
"Delete Participants": {
"main": [
[]
]
},
"Random Participants": {
"main": [
[
{
"node": "Get Channels",
"type": "main",
"index": 0
}
]
]
},
"Define Step Giveaway": {
"main": [
[
{
"node": "List Channels",
"type": "main",
"index": 0
}
],
[
{
"node": "Get Participants",
"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
}
]
]
},
"Upsert bot status on START": {
"main": [
[]
]
},
"Add participant in Giveaway": {
"main": [
[]
]
},
"Update bot status on START ": {
"main": [
[
{
"node": "End Message",
"type": "main",
"index": 0
}
]
]
},
"Update bot status and referal": {
"main": [
[
{
"node": "Add participant in Giveaway",
"type": "main",
"index": 0
}
]
]
},
"Update bot status on GIVEAWAY RUN": {
"main": [
[
{
"node": "Create Giveaway",
"type": "main",
"index": 0
}
]
]
},
"Update bot status on GIVEAWAY REQUEST CHANNEL": {
"main": [
[]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
这是一个高级难度的工作流,适用于Building Blocks、Marketing等场景。适合高级用户,包含 16+ 个节点的复杂工作流
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
TG-Bot-Module-Quiz-v4-db-sell-full
通过Telegram在Postgres中自动化测试和收集响应("测验"模块)
If
Set
Code
+9
36 节点Andrew
Sales
TG-Bot-模块-检查_订阅-v4-数据库-销售-完整版
使用 Postgres 验证 Telegram 频道订阅并进行访问控制
If
Set
Switch
+7
45 节点Andrew
Building Blocks
TG-机器人模块-跨平台发布-v1-数据库-销售完整版
使用Postgres自动化Telegram频道帖子("跨平台发布"模块)
If
Set
Switch
+5
47 节点Andrew
Sales
TG机器人-复选框模块-v2-数据库-销售完整版
Telegram机器人,用于多选项目并保存到PostgreSQL("复选框"模块)
If
Set
Code
+6
46 节点Andrew
Sales
WA-机器人-模块-问卷-v1-数据库-销售-完整版
在Postgres中收集WhatsApp问卷回复("Anketa"模块)
If
Set
Switch
+4
32 节点Andrew
Sales
WA-机器人模块-测验-v1-数据库销售完整版
使用PostgreSQL自动化WhatsApp测验和结果排名("测验"模块)
If
Set
Sort
+6
39 节点Andrew
Sales