Magento 2 产品与优惠券自动提醒到 Telegram(防重复)
高级
这是一个Social Media领域的自动化工作流,包含 27 个节点。主要使用 If、Code、MySql、Twitter、Telegram 等节点。 Magento 2 产品与优惠券自动提醒到 Telegram(防重复保护)
前置要求
- •MySQL 数据库连接信息
- •Twitter API 凭证
- •Telegram Bot Token
- •可能需要目标 API 的认证凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"meta": {
"instanceId": "475f038f0c1743165ad39f5fa1e828653b3237cbd0f743c0a3f15e90ddc9aa2b",
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "0eacaccd-7ca0-493b-bcf6-60758b3b0f5e",
"name": "计划触发器",
"type": "n8n-nodes-base.scheduleTrigger",
"position": [
-960,
-440
],
"parameters": {
"rule": {
"interval": [
{
"field": "hours"
}
]
}
},
"typeVersion": 1.2
},
{
"id": "b77cb27a-f72f-4e79-af4d-c128375b6aef",
"name": "获取规则信息",
"type": "n8n-nodes-base.httpRequest",
"position": [
240,
-140
],
"parameters": {
"url": "=https://magekwik.com/rest/V1/salesRules/{{ $json.item_id }}",
"options": {},
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth"
},
"typeVersion": 4.2
},
{
"id": "29b72aef-59f5-45f5-b81f-bb383b8817a7",
"name": "优惠券状态",
"type": "n8n-nodes-base.if",
"position": [
420,
-140
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "90c39652-acba-47a2-beff-494cd117b13c",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
},
"leftValue": "={{ $json.is_active }}",
"rightValue": "={{ $json.is_active }}"
}
]
}
},
"typeVersion": 2.2
},
{
"id": "28dce2fb-11e4-4c4a-845c-17d68c857130",
"name": "发布到 Telegram1",
"type": "n8n-nodes-base.telegram",
"position": [
980,
-160
],
"webhookId": "05b88e7c-bf3a-4a29-aa98-f331831ea6c4",
"parameters": {
"text": "={{ $json.coupon }}",
"chatId": "",
"additionalFields": {
"parse_mode": "HTML"
}
},
"typeVersion": 1
},
{
"id": "d1d70202-6b0e-4ce4-9820-c94109c758ad",
"name": "产品提醒到 Telegram",
"type": "n8n-nodes-base.telegram",
"position": [
980,
40
],
"webhookId": "05b88e7c-bf3a-4a29-aa98-f331831ea6c4",
"parameters": {
"media": {
"media": [
{
"media": "={{ $json.image }}",
"additionalFields": {
"caption": "={{ $json.message }}"
}
}
]
},
"chatId": "",
"operation": "sendMediaGroup",
"additionalFields": {}
},
"typeVersion": 1
},
{
"id": "693d5ef4-0776-4401-97ff-bb49378a8c77",
"name": "初始化数据库",
"type": "n8n-nodes-base.mySql",
"position": [
-520,
-440
],
"parameters": {
"query": "CREATE TABLE IF NOT EXISTS posted_items (item_id INT PRIMARY KEY, item_type ENUM('product', 'coupon') NOT NULL, item_value VARCHAR(255), posted BOOLEAN DEFAULT FALSE, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);",
"options": {},
"operation": "executeQuery"
},
"typeVersion": 2.4
},
{
"id": "99ebf843-ecf6-46da-9f5b-fbbc242db19b",
"name": "获取新产品",
"type": "n8n-nodes-base.httpRequest",
"position": [
-360,
120
],
"parameters": {
"url": "={{$vars.STORE}}rest/V1/products?searchCriteria[sortOrders][0][field]=created_at&searchCriteria[sortOrders][0][direction]=DESC",
"options": {},
"authentication": "headerAuth",
"allowUnauthorizedCerts": true
},
"typeVersion": 1
},
{
"id": "f8b54b91-b743-4d3b-9637-2f769b46a48b",
"name": "获取产品信息",
"type": "n8n-nodes-base.httpRequest",
"position": [
240,
120
],
"parameters": {
"url": "=https://your-website.com/rest/default/V1/products/{{ $json.item_value }}",
"options": {},
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth"
},
"typeVersion": 4.2
},
{
"id": "ef85ab97-027b-4fdd-b79c-c38b2795707e",
"name": "将优惠券标记为已发布",
"type": "n8n-nodes-base.mySql",
"position": [
1260,
-140
],
"parameters": {
"query": "UPDATE posted_items set posted = 1 WHERE item_id = {{ $('Get Latest Offer').item.json.items[0].rule_id }} AND item_type = 'coupon';",
"options": {},
"operation": "executeQuery"
},
"typeVersion": 2.4
},
{
"id": "6716f687-198b-4cff-8212-9e6789d597f9",
"name": "将产品标记为已发布",
"type": "n8n-nodes-base.mySql",
"position": [
1260,
100
],
"parameters": {
"query": "UPDATE posted_items set posted = 1 WHERE item_id = {{ $('Product Status').item.json.id }} AND item_type = 'product';",
"options": {},
"operation": "executeQuery"
},
"typeVersion": 2.4
},
{
"id": "347f5828-f6f9-4d0e-9771-e9b3884c9a27",
"name": "获取最新优惠",
"type": "n8n-nodes-base.httpRequest",
"position": [
-360,
-140
],
"parameters": {
"url": "={{$vars.STORE}}/rest/V1/coupons/search?searchCriteria[sortOrders][0][field]=created_at&searchCriteria[sortOrders][0][direction]=DESC&searchCriteria[pageSize]=1",
"options": {},
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth"
},
"typeVersion": 4.2
},
{
"id": "4fcb066a-f4c8-4449-86d8-6f39513994ab",
"name": "产品消息格式",
"type": "n8n-nodes-base.code",
"position": [
680,
120
],
"parameters": {
"jsCode": "const product = $input.first().json\n\nconst message = ` New Product Alert!\\n\\n*${product.name}*\\nPrice: $${product.price}\\n\\nCheck it out now:\\nhttps://magekwik.com/${product.custom_attributes[2].value}`;\n\nreturn [{\n json: {\n message,\n image: product.media_gallery_entries?.[0]?.file\n ? `https://magekwik.com/pub/media/catalog/product${product.media_gallery_entries[0].file}`\n : null,\n }\n}];"
},
"typeVersion": 2
},
{
"id": "44e6392f-80b1-4a2b-8081-c0004ed3e0fa",
"name": "优惠券消息格式",
"type": "n8n-nodes-base.code",
"position": [
680,
-140
],
"parameters": {
"jsCode": "\nconst coupon = `🎁 New Coupon Alert! 🎁\\n\n🎟️ <b>Coupon Code</b>: ${$('Get Latest Offer').first().json.items[0].code}\n🔄 Usage: ${$('Get Rule Info').first().json.times_used || 0}/${$('Get Rule Info').first().json.uses_per_customer || '∞'}\n✅ Status: ${$('Get Rule Info').first().json.is_active ? 'ACTIVE ✅' : 'INACTIVE ❌'}`\n\nreturn [{\n json: {\n coupon\n }\n}];"
},
"typeVersion": 2
},
{
"id": "0bf1f58c-1b8d-43eb-a110-121e94d7e44a",
"name": "新优惠券条目",
"type": "n8n-nodes-base.mySql",
"position": [
-160,
-140
],
"parameters": {
"query": "SET @coupon_id = '{{ $json.items[0].coupon_id }}';\nSET @search_coupon = '{{ $json.items[0].code }}';\n\nINSERT INTO posted_items (\n item_id, \n item_type,\n item_value,\n posted, \n updated_at\n)\nSELECT \n @coupon_id AS item_id,\n 'coupon' AS item_type,\n @search_coupon AS item_value,\n FALSE AS posted,\n CURRENT_TIMESTAMP AS updated_at\nFROM dual\nWHERE NOT EXISTS (\n SELECT 1 \n FROM posted_items \n WHERE item_id = @coupon_id AND item_type = 'coupon'\n);\n\nSELECT * \nFROM posted_items \nWHERE item_id = @coupon_id AND item_type = 'coupon'",
"options": {},
"operation": "executeQuery"
},
"notesInFlow": false,
"typeVersion": 2.4,
"alwaysOutputData": false
},
{
"id": "d060693e-aed5-40cf-9a36-28bf84d96925",
"name": "新产品条目",
"type": "n8n-nodes-base.mySql",
"position": [
-160,
120
],
"parameters": {
"query": "SET @product_id = '{{ $json.items[0].id }}';\nSET @product_sku = '{{ $json.items[0].sku }}';\n\nINSERT INTO posted_items (\n item_id, \n item_type,\n item_value,\n posted, \n updated_at\n)\nSELECT \n @product_id AS item_id,\n 'product' AS item_type,\n @product_sku AS item_value,\n FALSE AS posted,\n CURRENT_TIMESTAMP AS updated_at\nFROM dual\nWHERE NOT EXISTS (\n SELECT 1 \n FROM posted_items \n WHERE item_id = @product_id AND item_type = 'product'\n);\n\nSELECT * \nFROM posted_items \nWHERE item_id = @product_id AND item_type = 'product'",
"options": {},
"operation": "executeQuery"
},
"notesInFlow": false,
"typeVersion": 2.4,
"alwaysOutputData": false
},
{
"id": "ad3f87a5-a37a-4672-984b-5b8a510ea6a4",
"name": "产品状态",
"type": "n8n-nodes-base.if",
"position": [
420,
120
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "loose"
},
"combinator": "and",
"conditions": [
{
"id": "90c39652-acba-47a2-beff-494cd117b13c",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
},
"leftValue": "={{ $json.status }}",
"rightValue": "={{ $json.is_active }}"
}
]
},
"looseTypeValidation": true
},
"typeVersion": 2.2
},
{
"id": "dceda5b3-9126-453b-bd6e-01f5ddbc8a60",
"name": "优惠券到 X",
"type": "n8n-nodes-base.twitter",
"onError": "continueRegularOutput",
"disabled": true,
"position": [
980,
-340
],
"parameters": {
"text": "={{ $json.coupon }}",
"additionalFields": {}
},
"typeVersion": 2,
"alwaysOutputData": true
},
{
"id": "17e427ed-77f5-4d3c-a6cf-8937f955b9c0",
"name": "产品 X 发布",
"type": "n8n-nodes-base.twitter",
"onError": "continueRegularOutput",
"position": [
980,
260
],
"parameters": {
"text": "={{ $json.image }}\n\n{{ $json.message }}",
"additionalFields": {}
},
"typeVersion": 2,
"alwaysOutputData": true
},
{
"id": "70972854-d872-4665-8971-217494646726",
"name": "优惠券重复保护",
"type": "n8n-nodes-base.if",
"position": [
40,
-140
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "loose"
},
"combinator": "and",
"conditions": [
{
"id": "90c39652-acba-47a2-beff-494cd117b13c",
"operator": {
"type": "number",
"operation": "equals"
},
"leftValue": "={{ $json.posted }}",
"rightValue": 1
}
]
},
"looseTypeValidation": true
},
"typeVersion": 2.2
},
{
"id": "c3c88742-1e58-483d-95ee-4fef4fb69104",
"name": "产品重复保护",
"type": "n8n-nodes-base.if",
"position": [
40,
120
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "loose"
},
"combinator": "or",
"conditions": [
{
"id": "90c39652-acba-47a2-beff-494cd117b13c",
"operator": {
"type": "number",
"operation": "equals"
},
"leftValue": "={{ $json.posted }}",
"rightValue": 1
}
]
},
"looseTypeValidation": true
},
"typeVersion": 2.2,
"alwaysOutputData": false
},
{
"id": "458acf57-b472-4d4f-a609-4e9d2737c506",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
900,
-400
],
"parameters": {
"color": 4,
"width": 260,
"height": 820,
"content": ""
},
"typeVersion": 1
},
{
"id": "63f50109-8206-4da5-9429-46e89ef651aa",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
1200,
-220
],
"parameters": {
"color": 3,
"width": 220,
"height": 480,
"content": "## 记录为已发布"
},
"typeVersion": 1
},
{
"id": "769d34f1-5b3a-41ff-8dc6-9a658eccd52f",
"name": "便签2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1040,
-500
],
"parameters": {
"color": 7,
"width": 700,
"height": 240,
"content": "## 自动调度触发器和初始化数据库"
},
"typeVersion": 1
},
{
"id": "d37f209e-5fa7-46be-8e72-5d1c3757be59",
"name": "便签3",
"type": "n8n-nodes-base.stickyNote",
"position": [
620,
-220
],
"parameters": {
"color": 6,
"height": 500,
"content": "## 格式化消息"
},
"typeVersion": 1
},
{
"id": "c9c618af-1ba3-4c82-a629-8cf0b1a84c9f",
"name": "便签4",
"type": "n8n-nodes-base.stickyNote",
"position": [
-440,
-220
],
"parameters": {
"color": 5,
"width": 1040,
"height": 240,
"content": "## Magento 2 - 检查最新优惠券 - 记录到数据库 - 验证"
},
"typeVersion": 1
},
{
"id": "d9399795-e4ff-4590-bd37-3901beb1aee5",
"name": "便签5",
"type": "n8n-nodes-base.stickyNote",
"position": [
-440,
40
],
"parameters": {
"color": 5,
"width": 1040,
"height": 240,
"content": "## Magento 2 - 检查新产品 - 记录到数据库 - 验证"
},
"typeVersion": 1
},
{
"id": "1d1624e4-cdc1-4b50-886d-cefc118259cf",
"name": "便签6",
"type": "n8n-nodes-base.stickyNote",
"position": [
-320,
-500
],
"parameters": {
"width": 660,
"height": 240,
"content": "## Magento 2 (Adobe Commerce):新产品和优惠券的自动化 X 和 Telegram 发布"
},
"typeVersion": 1
}
],
"pinData": {},
"connections": {
"Voucher to X": {
"main": [
[
{
"node": "Set Coupon as Posted",
"type": "main",
"index": 0
}
]
]
},
"Coupon Status": {
"main": [
[
{
"node": "Voucher Message Format",
"type": "main",
"index": 0
}
]
]
},
"Get Rule Info": {
"main": [
[
{
"node": "Coupon Status",
"type": "main",
"index": 0
}
]
]
},
"Product Status": {
"main": [
[
{
"node": "Product Message Format",
"type": "main",
"index": 0
}
]
]
},
"Product X Post": {
"main": [
[
{
"node": "Set Product as Posted",
"type": "main",
"index": 0
}
]
]
},
"Get Latest Offer": {
"main": [
[
{
"node": "New Voucher Entry",
"type": "main",
"index": 0
}
]
]
},
"Get Product Info": {
"main": [
[
{
"node": "Product Status",
"type": "main",
"index": 0
}
]
]
},
"Schedule Trigger": {
"main": [
[
{
"node": "Get Latest Offer",
"type": "main",
"index": 0
},
{
"node": "Init Database",
"type": "main",
"index": 0
},
{
"node": "Fetch New Product",
"type": "main",
"index": 0
}
]
]
},
"Fetch New Product": {
"main": [
[
{
"node": "New Product Entry",
"type": "main",
"index": 0
}
]
]
},
"New Product Entry": {
"main": [
[
{
"node": "Product Duplication Protection",
"type": "main",
"index": 0
}
]
]
},
"New Voucher Entry": {
"main": [
[
{
"node": "Voucher Duplication Protection",
"type": "main",
"index": 0
}
]
]
},
"Post to Telegram1": {
"main": [
[
{
"node": "Set Coupon as Posted",
"type": "main",
"index": 0
}
]
]
},
"Product Message Format": {
"main": [
[
{
"node": "Product Alert to Telegram",
"type": "main",
"index": 0
},
{
"node": "Product X Post",
"type": "main",
"index": 0
}
]
]
},
"Voucher Message Format": {
"main": [
[
{
"node": "Post to Telegram1",
"type": "main",
"index": 0
},
{
"node": "Voucher to X",
"type": "main",
"index": 0
}
]
]
},
"Product Alert to Telegram": {
"main": [
[
{
"node": "Set Product as Posted",
"type": "main",
"index": 0
}
]
]
},
"Product Duplication Protection": {
"main": [
[],
[
{
"node": "Get Product Info",
"type": "main",
"index": 0
}
]
]
},
"Voucher Duplication Protection": {
"main": [
[],
[
{
"node": "Get Rule Info",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
这是一个高级难度的工作流,适用于Social Media等场景。适合高级用户,包含 16+ 个节点的复杂工作流
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
使用Gmail向高价值Magento 2客户发送自动折扣券
使用Gmail向高价值Magento 2客户发送自动折扣券
If
Code
Cron
+3
14 节点Kanaka Kishore Kandregula
Social Media
Telegram自动复制器
基于GPT-4o-mini的Telegram频道内容自动复制与翻译
If
Set
Code
+6
19 节点Shohani
Social Media
通过Gmail审批自动禁用一年未售出的Magento 2产品
通过Gmail审批自动禁用一年未售出的Magento 2产品
If
Code
Gmail
+7
22 节点Kanaka Kishore Kandregula
Document Extraction
通过REST API修复并重新发送Magento 2访客订单邮件
通过REST API修复并重新发送Magento 2访客订单邮件
If
Code
My Sql
+3
10 节点Kanaka Kishore Kandregula
CRM
✨🩷自动化社交媒体内容发布工厂 + 系统提示组合
使用GPT-4o为6个平台生成平台优化的社交媒体内容
If
Set
Code
+20
100 节点Luan Correia
Social Media
Magento 2低库存提醒通过Slack和Gmail(MSI兼容)
Magento 2低库存提醒通过Slack和Gmail(MSI兼容)
If
Code
Gmail
+4
18 节点Kanaka Kishore Kandregula
Miscellaneous
工作流信息
难度等级
高级
节点数量27
分类1
节点类型8
作者
Kanaka Kishore Kandregula
@kmyprojectsExperienced Magento 2 Developer with 10+ years of expertise in building and optimizing eCommerce solutions. Over the past year, I’ve expanded my skills into workflow automation using n8n, streamlining business processes and integrating systems for efficiency. Passionate about solving complex problems, enhancing performance, and leveraging automation to drive smarter workflows.
外部链接
在 n8n.io 上查看 →
分享此工作流