自动化订单确认,使用Abacate Pay:首购优惠券奖励,通过邮件和Slack
中级
这是一个CRM、Multimodal AI领域的自动化工作流,包含 13 个节点。主要使用 If、Set、Code、Slack、Webhook 等节点。 自动化订单确认,使用Abacate Pay:首购优惠券奖励,通过邮件和Slack
前置要求
- •Slack Bot Token 或 Webhook URL
- •HTTP Webhook 端点(n8n 会自动生成)
- •可能需要目标 API 的认证凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"meta": {
"instanceId": "e860732ed76ff1de8212e780b2d62bd140dee0b71e6ccf7172d54e965acae43d",
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "e4a1ed73-6ae6-4358-81dd-3400180d08ab",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"position": [
-500,
20
],
"webhookId": "1b27997e-c86e-4f3d-ac12-61a79400bb1d",
"parameters": {
"path": "1b27997e-c86e-4f3d-ac12-61a79400bb1d",
"options": {},
"httpMethod": "POST"
},
"typeVersion": 2
},
{
"id": "d1717d9f-ba23-49ad-b06e-ecb14542aaec",
"name": "配置",
"type": "n8n-nodes-base.set",
"position": [
-260,
20
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "fa8a4b24-2171-454d-b0c1-5e7716cd9af6",
"name": "token",
"type": "string",
"value": "teste123"
},
{
"id": "17eb20d8-cd9a-4da4-99dd-853dea0247ea",
"name": "companyName",
"type": "string",
"value": "N8N"
},
{
"id": "7270f9b3-0ca3-4f5a-b236-0f103cec440c",
"name": "companySite",
"type": "string",
"value": "www.n8n.io"
},
{
"id": "f4f8a62c-f214-4872-ac2b-32db8a210296",
"name": "companyEmail",
"type": "string",
"value": "your.email@n8n.com"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "981c713b-53f8-4fe4-b091-bcd7a7a6a341",
"name": "检查令牌",
"type": "n8n-nodes-base.if",
"position": [
-40,
20
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "dbd4bf73-c04d-40b0-8ce1-c00bf578e516",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $('Webhook').item.json.query.webhookSecret }}",
"rightValue": "={{ $json.token }}"
},
{
"id": "c2319a7f-1317-4a48-ba19-4bc44c97a8c1",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "8c252d44-ce6f-4a23-9224-f51ecb0c3462",
"name": "响应错误",
"type": "n8n-nodes-base.respondToWebhook",
"position": [
200,
20
],
"parameters": {
"options": {
"responseCode": 400
},
"respondWith": "json",
"responseBody": "{\n \"error\": \"token invalid\"\n}"
},
"typeVersion": 1.1
},
{
"id": "c757835b-dc8d-484b-b321-c823e19a719c",
"name": "制作邮件正文",
"type": "n8n-nodes-base.code",
"position": [
1220,
-280
],
"parameters": {
"jsCode": "// Get data from previous nodes\nconst webhookData = $('Webhook').item.json.body.data;\nconst configs = $('Configs').item.json;\n\n// Check if the 'CreateCustomCoupon' node ran and has data\n// The .exists property is a safe way to check this\n// const couponNodeExists = $('CreateCustomCoupon');\nlet couponData = null;\nif ($('CheckFirstOrder').item.json.first) {\n console.log(\"teste\")\n couponData = $('CreateCustomCoupon').last().json.data;\n}\n\n// ---- PART 1: BUILD THE HTML FOR THE EMAIL ----\n\nlet couponHtmlSection = '';\nif (couponData) {\n couponHtmlSection = `\n <div class=\"coupon-section\">\n <h2>A Welcome Gift For You!</h2>\n <p>As a thank you for your first purchase, we've created a special <strong>10% discount coupon</strong> for your next order. Use the code below:</p>\n <div class=\"coupon-code\">${couponData.id}</div>\n </div>\n `;\n}\n\nconst emailHtml = `\n<!DOCTYPE html>\n<html>\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n<title>Your Order Confirmation</title>\n<style>\n body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; margin: 0; padding: 0; background-color: #f4f4f7; }\n .container { max-width: 600px; margin: 20px auto; background-color: #ffffff; border: 1px solid #e2e8f0; border-radius: 8px; overflow: hidden; box-shadow: 0 4px 15px rgba(0,0,0,0.05); }\n .header { background-color: #4a5568; color: #ffffff; padding: 40px; text-align: center; }\n .header h1 { margin: 0; font-size: 28px; }\n .content { padding: 30px 40px; color: #4a5568; line-height: 1.6; }\n .content h2 { color: #2d3748; }\n .order-summary { width: 100%; border-collapse: collapse; margin-top: 20px; }\n .order-summary th, .order-summary td { border-bottom: 1px solid #e2e8f0; padding: 12px; text-align: left; }\n .order-summary th { background-color: #f7fafc; }\n .total { font-size: 18px; font-weight: bold; color: #2d3748; text-align: right; margin-top: 20px; }\n .coupon-section { background-color: #f7fafc; border: 2px dashed #2a9d8f; border-radius: 8px; padding: 20px; margin-top: 30px; text-align: center; }\n .coupon-code { background-color: #ffffff; border: 1px solid #e2e8f0; padding: 10px 20px; font-size: 20px; font-weight: bold; color: #2a9d8f; letter-spacing: 2px; display: inline-block; margin-top: 10px; }\n .footer { background-color: #edf2f7; color: #718096; text-align: center; padding: 20px; font-size: 12px; }\n .footer a { color: #4a5568; text-decoration: none; }\n</style>\n</head>\n<body>\n <div class=\"container\">\n <div class=\"header\">\n <h1>Thank You For Your Order!</h1>\n </div>\n <div class=\"content\">\n <p>Hello <strong>${webhookData.billing.customer.metadata.name}</strong>,</p>\n <p>Your order has been successfully processed. We appreciate your business and are already preparing your items.</p>\n\n <h2>Order Summary #${webhookData.billing.id}</h2>\n <table class=\"order-summary\">\n <thead>\n <tr>\n <th>Product ID</th>\n <th>Quantity</th>\n <th>Price</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>${webhookData.billing.products[0].externalId}</td>\n <td>${webhookData.billing.products[0].quantity}</td>\n <td>R$ ${webhookData.billing.paidAmount / 100}</td>\n </tr>\n </tbody>\n </table>\n <p class=\"total\">\n TOTAL: $${webhookData.billing.paidAmount / 100}\n </p>\n\n ${couponHtmlSection}\n\n <p>If you have any questions, please reply to this email or visit our support center. We're here to help!</p>\n <p>Sincerely,<br>The ${configs.companyName} Team</p>\n </div>\n <div class=\"footer\">\n <p>© ${new Date().getFullYear()} ${configs.companyName}. All rights reserved.</p>\n <p><a href=\"https://${configs.companySite}\">Visit our website</a> | <a href=\"mailto:${configs.companyEmail}\">Contact Us</a></p>\n </div>\n </div>\n</body>\n</html>\n`;\n\nlet slackBlocks = [\n\t{\n\t\t\"type\": \"header\",\n\t\t\"text\": { \"type\": \"plain_text\", \"text\": \"🎉 New Sale Received!\", \"emoji\": true }\n\t},\n\t{\n\t\t\"type\": \"section\",\n\t\t\"fields\": [\n\t\t\t{ \"type\": \"mrkdwn\", \"text\": `*Customer:*\\n${webhookData.billing.customer.metadata.name}` },\n\t\t\t{ \"type\": \"mrkdwn\", \"text\": `*Email:*\\n${webhookData.billing.customer.metadata.email}` },\n\t\t\t{ \"type\": \"mrkdwn\", \"text\": `*Order ID:*\\n\\`${webhookData.billing.id}\\`` },\n\t\t\t{ \"type\": \"mrkdwn\", \"text\": `*Amount Paid:*\\n*$${webhookData.billing.paidAmount / 100}*` }\n\t\t]\n\t},\n\t{ \"type\": \"divider\" }\n];\n\nif (couponData) {\n slackBlocks.push({\n\t\t\"type\": \"section\",\n\t\t\"text\": {\n\t\t\t\"type\": \"mrkdwn\",\n\t\t\t\"text\": `🎁 *First-Time Buyer Bonus!*\\nA 10% discount coupon was generated for their next purchase: \\`${couponData.id}\\``\n\t\t}\n\t});\n}\n\nslackBlocks.push(\n {\n\t\t\"type\": \"context\",\n\t\t\"elements\": [\n\t\t\t{ \"type\": \"mrkdwn\", \"text\": `Payment via *${webhookData.payment.method}* | ✅ Confirmation email sent.` }\n\t\t]\n\t},\n\t{\n\t\t\"type\": \"actions\",\n\t\t\"elements\": [\n\t\t\t{\n\t\t\t\t\"type\": \"button\",\n\t\t\t\t\"text\": { \"type\": \"plain_text\", \"text\": \"View Execution\", \"emoji\": true },\n\t\t\t\t\"url\": `${$('Webhook').last().json.webhookUrl}`,\n\t\t\t\t\"action_id\": \"view_execution_button\"\n\t\t\t}\n\t\t]\n\t}\n);\n\nreturn {\n json: {\n emailHtml: emailHtml,\n slackBlocks:{blocks: slackBlocks}\n }\n};"
},
"typeVersion": 2
},
{
"id": "000c0f09-b6a3-4a0a-bc4e-3c91dd22c5c2",
"name": "发送邮件",
"type": "n8n-nodes-base.emailSend",
"position": [
1440,
-360
],
"webhookId": "8c1766d5-bb30-4f14-9078-3193e6aac6b5",
"parameters": {
"html": "={{ $json.emailHtml }}",
"options": {},
"subject": "Thank You For Your Order!",
"toEmail": "={{ $('Webhook').item.json.body.data.billing.customer.metadata.email }}",
"fromEmail": "={{$('Configs').item.json.companyEmail}}"
},
"credentials": {
"smtp": {
"id": "qncoQX3vHrJbtnK7",
"name": "SMTP account"
}
},
"retryOnFail": true,
"typeVersion": 2.1
},
{
"id": "8d647e46-7e42-4ea8-aa81-eb6a380b0f52",
"name": "Slack",
"type": "n8n-nodes-base.slack",
"position": [
1440,
-200
],
"webhookId": "3abc93d5-ae38-4a60-b51c-836f660f5d73",
"parameters": {
"user": {
"__rl": true,
"mode": "username",
"value": "@mth.pedrosa"
},
"select": "user",
"blocksUi": "={{ JSON.stringify($json.slackBlocks) }}",
"messageType": "block",
"otherOptions": {}
},
"credentials": {
"slackApi": {
"id": "BHr2MFFEhDsD4Uzv",
"name": "Slack account 3"
}
},
"typeVersion": 2.3
},
{
"id": "ea067f2a-b47e-4411-92d3-0986c101c3de",
"name": "创建自定义优惠券",
"type": "n8n-nodes-base.httpRequest",
"position": [
1000,
-420
],
"parameters": {
"url": "https://api.abacatepay.com/v1/coupon/create",
"method": "POST",
"options": {},
"jsonBody": "={\n \"code\": \"{{ $('Webhook').item.json.body.data.billing.customer.metadata.name.replaceAll(\" \",\"\").toUpperCase() }}_10\",\n \"notes\": \"Coupon sale {{$('Webhook').item.json.body.data.billing.id}}\",\n \"maxRedeems\": 1,\n \"discountKind\": \"PERCENTAGE\",\n \"discount\": 10,\n \"metadata\": {}\n}",
"sendBody": true,
"sendHeaders": true,
"specifyBody": "json",
"headerParameters": {
"parameters": [
{
"name": "Authorization",
"value": "Bearer {{your_token}}"
}
]
}
},
"typeVersion": 4.2
},
{
"id": "f0faf198-1ed4-4284-bbb6-85dae800999d",
"name": "获取订单",
"type": "n8n-nodes-base.httpRequest",
"position": [
240,
-300
],
"parameters": {
"url": "https://api.abacatepay.com/v1/billing/list",
"options": {},
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Authorization",
"value": "Bearer {{your_token}}"
}
]
}
},
"typeVersion": 4.2
},
{
"id": "4741f8ed-8bef-4d73-9dd6-e60e6ec66aa9",
"name": "检查首次订单",
"type": "n8n-nodes-base.code",
"position": [
520,
-300
],
"parameters": {
"jsCode": "const orders = $('GetOrders').last().json\nconst currentOrder = $('Webhook').last().json.body.data\nlet first = false\n\nif(!orders.error){\n let firstOrder = orders.data.filter(order => order.customer?.id === currentOrder.billing.customer.id && order.id !== currentOrder.billing.id)\n\n console.log('first',firstOrder)\n if (firstOrder.length === 0){\n console.log(\"oi\")\n first = true\n }\n}\n\nreturn {first}"
},
"typeVersion": 2
},
{
"id": "019e46e1-dc65-404d-806e-8d75593be29a",
"name": "如果",
"type": "n8n-nodes-base.if",
"position": [
800,
-300
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "04f28052-4896-4b98-985e-f11adfec2f86",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
},
"leftValue": "={{ $json.first }}",
"rightValue": "true"
}
]
}
},
"typeVersion": 2.2
},
{
"id": "a00461f1-8ece-4f9a-af49-c349d4478e37",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-480,
-660
],
"parameters": {
"width": 560,
"height": 640,
"content": "## Abacate Pay 发送邮件和 Slack:自动化确认与首单客户优惠券"
},
"typeVersion": 1
},
{
"id": "8d7c877d-60ef-43f1-a707-e4616cb5e3ec",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
100,
-660
],
"parameters": {
"color": 4,
"width": 160,
"height": 220,
"content": "## AbacatePay"
},
"typeVersion": 1
}
],
"pinData": {
"Webhook": [
{
"body": {
"data": {
"billing": {
"id": "bill_0HfT4RcsWHfpL45EsCFD5GhF",
"kind": [
"PIX"
],
"amount": 1000,
"status": "ACTIVE",
"customer": {
"id": "cust_LK4T2Es0G0Ru3jZ2pfpPw202",
"metadata": {
"name": "Matheus Pedrosa",
"email": "mth.pedrosa@outlook.com",
"taxId": "37448456806",
"cellphone": "(18) 98820-1588"
}
},
"products": [
{
"id": "prod_jt2nC36C3JxSXcNSYAwaRe2m",
"quantity": 1,
"externalId": "1"
}
],
"frequency": "MULTIPLE_PAYMENTS",
"paidAmount": 1000,
"couponsUsed": []
},
"payment": {
"fee": 80,
"amount": 1000,
"method": "PIX"
}
},
"event": "billing.paid",
"devMode": true
},
"query": {
"webhookSecret": "teste123"
},
"params": {},
"headers": {
"host": "0a4e2be16c08.ngrok-free.app",
"accept": "*/*",
"svix-id": "msg_31FY8V4CRAfe8VNCtVtFDvtaosp",
"user-agent": "Svix-Webhooks/1.70.0 (sender-9YMgn; +https://www.svix.com/http-sender/)",
"content-type": "application/json",
"content-length": "517",
"svix-signature": "v1,Vigvp7HcLdvRR3eC3TDZd+cFOUBsKLxDOn8Kq4wm0iY=",
"svix-timestamp": "1755121128",
"accept-encoding": "gzip",
"x-forwarded-for": "63.33.109.123",
"x-forwarded-host": "0a4e2be16c08.ngrok-free.app",
"x-forwarded-proto": "https"
},
"webhookUrl": "http://localhost:5678/webhook/1b27997e-c86e-4f3d-ac12-61a79400bb1d",
"executionMode": "production"
}
]
},
"connections": {
"If": {
"main": [
[
{
"node": "CreateCustomCoupon",
"type": "main",
"index": 0
}
],
[
{
"node": "MakeBodyEmail",
"type": "main",
"index": 0
}
]
]
},
"Configs": {
"main": [
[
{
"node": "CheckToken",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "Configs",
"type": "main",
"index": 0
}
]
]
},
"GetOrders": {
"main": [
[
{
"node": "CheckFirstOrder",
"type": "main",
"index": 0
}
]
]
},
"CheckToken": {
"main": [
[
{
"node": "GetOrders",
"type": "main",
"index": 0
}
],
[
{
"node": "RespondError",
"type": "main",
"index": 0
}
]
]
},
"Send Email": {
"main": [
[]
]
},
"MakeBodyEmail": {
"main": [
[
{
"node": "Slack",
"type": "main",
"index": 0
},
{
"node": "Send Email",
"type": "main",
"index": 0
}
]
]
},
"CheckFirstOrder": {
"main": [
[
{
"node": "If",
"type": "main",
"index": 0
}
]
]
},
"CreateCustomCoupon": {
"main": [
[
{
"node": "MakeBodyEmail",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
这是一个中级难度的工作流,适用于CRM、Multimodal AI等场景。适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
基于Claap通话使用GPT-4o和Google Slides自动生成销售演示文稿
基于Claap通话使用GPT-4o和Google Slides自动生成销售演示文稿
If
Set
Code
+7
20 节点Robin Bonduelle
CRM
从Notion自动执行客户培育邮件和评价收集
通过Telegram使用Google日历和Notion CRM自动化会议安排
If
Set
Code
+8
19 节点Shelly-Ann Davy
Support Chatbot
基于Bright Data、OpenAI和Redis的高级多源AI研究
使用Bright Data、OpenAI和Redis进行高级多源AI研究
If
Set
Code
+15
43 节点Daniel Shashko
Market Research
简单订单确认和客户通知工作流,用于新电商订单
使用邮件通知和 Webhooks 自动化电商订单处理
If
Set
Webhook
+3
17 节点PhilanthropEAK Automation
CRM
使用 n8n API 和 Bootstrap 为 Webhooks 生成自文档化 API 门户
使用 n8n API 和 Bootstrap 为 Webhooks 生成自文档化 API 门户
N8n
Set
Code
+7
17 节点Matheus Pedrosa
Document Extraction
Qwen3-VL-8B-Thinking旅行规划器
基于Skyscanner、Booking.com和Gmail的AI优化旅行行程生成器
Set
Code
Gmail
+7
18 节点Cheng Siong Chin
Personal Productivity
工作流信息
难度等级
中级
节点数量13
分类2
节点类型9
作者
Matheus Pedrosa
@julinhoI am a software engineer specializing in automations, with extensive experience on the N8N platform. With solid skills in JavaScript, Go, .NET, and C#, I am equipped to develop efficient and scalable solutions.
外部链接
在 n8n.io 上查看 →
分享此工作流