当Shopify订单取消时发送WhatsApp道歉与重新订购链接
中级
这是一个Support Chatbot领域的自动化工作流,包含 15 个节点。主要使用 If, Code, Wait, HttpRequest, GoogleSheets 等节点。 当Shopify订单取消时发送Rapiwa WhatsApp道歉与重新订购链接
前置要求
- •可能需要目标 API 的认证凭证
- •Google Sheets API 凭证
- •Shopify Admin API 凭证
分类
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"id": "suCMqeeONiHq3vRv",
"meta": {
"instanceId": "cb9a1e5321767b6316634728341237e564b2587ab15b74ca0a89eb02a53484d6",
"templateCredsSetupCompleted": true
},
"name": "当 Shopify 订单取消时发送 WhatsApp 道歉与重新订购链接",
"tags": [],
"nodes": [
{
"id": "a4668c3f-981a-416a-ae3f-fab26ba31520",
"name": "代码",
"type": "n8n-nodes-base.code",
"position": [
-896,
1328
],
"parameters": {
"jsCode": "// Get input data (assuming one item only)\nconst order = items[0].json;\n\n// Extract important data\nconst result = {\n number: order.number,\n orderNumber: order.order_number,\n orderUrl: order.order_status_url,\n confirmationNumber: order.confirmation_number,\n createdAt: order.created_at,\n cancelledAt: order.cancelled_at,\n status: {\n financial: order.financial_status,\n fulfillment: order.fulfillment_status,\n },\n total: {\n price: order.total_price,\n subtotal: order.subtotal_price,\n tax: order.total_tax,\n currency: order.currency,\n },\n customer: {\n email: order.customer?.email || null,\n phone: order.customer?.phone || null,\n name: `${order.customer?.first_name || ''} ${order.customer?.last_name || ''}`.trim(),\n },\n address: {\n billing: {\n name: `${order.billing_address?.first_name || ''} ${order.billing_address?.last_name || ''}`.trim(),\n phone: order.billing_address?.phone || null,\n address1: order.billing_address?.address1 || null,\n address2: order.billing_address?.address2 || null,\n city: order.billing_address?.city || null,\n zip: order.billing_address?.zip || null,\n country: order.billing_address?.country || null,\n },\n shipping: {\n name: `${order.shipping_address?.first_name || ''} ${order.shipping_address?.last_name || ''}`.trim(),\n phone: order.shipping_address?.phone || null,\n address1: order.shipping_address?.address1 || null,\n address2: order.shipping_address?.address2 || null,\n city: order.shipping_address?.city || null,\n zip: order.shipping_address?.zip || null,\n country: order.shipping_address?.country || null,\n }\n },\n product: order.line_items.map(item => ({\n title: item.title,\n price: item.price,\n quantity: item.quantity,\n tax: item.tax_lines?.[0]?.price || 0,\n })),\n fulfillment: order.fulfillments?.[0]\n ? {\n trackingNumber: order.fulfillments[0].tracking_number,\n trackingUrl: order.fulfillments[0].tracking_url,\n status: order.fulfillments[0].status,\n }\n : null,\n refund: order.refunds?.[0]\n ? {\n reason: order.refunds[0].note || 'N/A',\n amount: order.refunds[0].transactions?.[0]?.amount || '0',\n date: order.refunds[0].created_at,\n }\n : null,\n};\n\n// Return simplified data\nreturn [{ json: result }];\n"
},
"typeVersion": 2
},
{
"id": "bc36bee1-c341-4c0b-8e42-213acc276c7c",
"name": "遍历项目",
"type": "n8n-nodes-base.splitInBatches",
"position": [
-1120,
1312
],
"parameters": {
"options": {}
},
"typeVersion": 3
},
{
"id": "2bfcd535-68af-46f8-b752-b6aa85d3a050",
"name": "Shopify触发器",
"type": "n8n-nodes-base.shopifyTrigger",
"position": [
-1312,
1312
],
"webhookId": "13f436bb-8889-4168-b0a1-4b495cb907da",
"parameters": {
"topic": "orders/cancelled",
"authentication": "accessToken"
},
"credentials": {
"shopifyAccessTokenApi": {
"id": "cWoMnmp2EszIQYpj",
"name": "Shopify Access Token account"
}
},
"typeVersion": 1
},
{
"id": "e357b169-9513-4477-be41-174c5e779f7e",
"name": "如果",
"type": "n8n-nodes-base.if",
"position": [
208,
1328
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "3ab8725a-9268-45fd-b91c-0e055fe6fa7c",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
},
"leftValue": "={{ $json.data.exists }}",
"rightValue": "=\"true\""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "941f8ed9-342b-478d-90c4-200ce2319fb0",
"name": "等待",
"type": "n8n-nodes-base.wait",
"position": [
640,
1424
],
"webhookId": "6c474e54-eb3c-4fcd-b455-948322cd0121",
"parameters": {},
"typeVersion": 1.1
},
{
"id": "e49c4939-de04-442f-b476-413050ab4a72",
"name": "清理 WhatsApp 号码",
"type": "n8n-nodes-base.code",
"position": [
-480,
1328
],
"parameters": {
"jsCode": "const items = await $input.all();\n\nconst updatedItems = items.map((item) => {\n let rawNumber = item?.json?.address?.billing?.phone;\n rawNumber = rawNumber ? String(rawNumber) : \"\";\n\n const cleanedNumber = rawNumber.replace(/\\D/g, \"\"); // Remove non-digit characters\n\n // Update the nested phone field\n if (item.json.address?.billing) {\n item.json.address.billing.phone = cleanedNumber;\n }\n\n return item;\n});\n\nreturn updatedItems;\n"
},
"typeVersion": 2
},
{
"id": "28f381c1-b0a3-4298-ae94-ff6bee35743f",
"name": "使用 Rapiwa 检查有效的 WhatsApp 号码",
"type": "n8n-nodes-base.httpRequest",
"position": [
-272,
1328
],
"parameters": {
"url": "=https://app.rapiwa.com/api/verify-whatsapp",
"method": "POST",
"options": {},
"sendBody": true,
"authentication": "genericCredentialType",
"bodyParameters": {
"parameters": [
{
"name": "number",
"value": "={{ $json.address.billing.phone }}"
}
]
},
"genericAuthType": "httpBearerAuth"
},
"credentials": {
"httpBearerAuth": {
"id": "jnaHCyYia9OAFozh",
"name": "Rapiwa Bearer YOUR_TOKEN_HERE"
}
},
"typeVersion": 4.2
},
{
"id": "7bfbe3cf-1dc4-40c8-8396-d98cf2b5afd5",
"name": "使用 Rapiwa 发送消息",
"type": "n8n-nodes-base.httpRequest",
"position": [
416,
1200
],
"parameters": {
"url": "=https://app.rapiwa.com/api/send-message",
"method": "POST",
"options": {},
"sendBody": true,
"authentication": "genericCredentialType",
"bodyParameters": {
"parameters": [
{
"name": "number",
"value": "={{ $('Clean WhatsApp Number').item.json.address.billing.phone }}"
},
{
"name": "message_type",
"value": "text"
},
{
"name": "message",
"value": "=Dear {{ $('Clean WhatsApp Number').item.json.customer.name }},\nWe’re really sorry about the issue with your order. 🙏\nYou can re-order using this link:👉 {{ $('Clean WhatsApp Number').item.json.orderUrl }}\nWe’ve added a small discount for the inconvenience.\nThanks,\nTeam SpaGreen Creative"
}
]
},
"genericAuthType": "httpBearerAuth"
},
"credentials": {
"httpBearerAuth": {
"id": "jnaHCyYia9OAFozh",
"name": "Rapiwa Bearer YOUR_TOKEN_HERE"
}
},
"typeVersion": 4.2
},
{
"id": "513a364e-5d85-4ef6-bb90-7b3685c6faae",
"name": "在已验证和已发送中保存行状态",
"type": "n8n-nodes-base.googleSheets",
"position": [
624,
1200
],
"parameters": {
"columns": {
"value": {
"name": "={{ $('Clean WhatsApp Number').item.json.customer.name }}",
"email": "={{ $('Clean WhatsApp Number').item.json.customer.email }}",
"price": "={{ $('Clean WhatsApp Number').item.json.total.currency }} {{ $('Clean WhatsApp Number').item.json.total.price }}",
"staus": "sent",
"title": "={{ $('Clean WhatsApp Number').item.json.product[0].title }}",
"number": "={{ $json.to }}",
"address1": "={{ $('Clean WhatsApp Number').item.json.address.billing.address1 }}",
"validity": "verified",
"re-order link": "={{ $('Code').item.json.orderUrl }}"
},
"schema": [
{
"id": "name",
"type": "string",
"display": true,
"required": false,
"displayName": "name",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "number",
"type": "string",
"display": true,
"required": false,
"displayName": "number",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "email",
"type": "string",
"display": true,
"required": false,
"displayName": "email",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "address1",
"type": "string",
"display": true,
"required": false,
"displayName": "address1",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "price",
"type": "string",
"display": true,
"required": false,
"displayName": "price",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "title",
"type": "string",
"display": true,
"required": false,
"displayName": "title",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "re-order link",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "re-order link",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "validity",
"type": "string",
"display": true,
"required": false,
"displayName": "validity",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "staus",
"type": "string",
"display": true,
"required": false,
"displayName": "staus",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"options": {},
"operation": "append",
"sheetName": {
"__rl": true,
"mode": "list",
"value": "gid=0",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/12zMJod9s3Ov0RZh-7-ZoqTvJr4yMIqOeAQKTBeZlrRk/edit#gid=0",
"cachedResultName": "Sheet1"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "12zMJod9s3Ov0RZh-7-ZoqTvJr4yMIqOeAQKTBeZlrRk",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/12zMJod9s3Ov0RZh-7-ZoqTvJr4yMIqOeAQKTBeZlrRk/edit?usp=drivesdk",
"cachedResultName": "Automated WhatsApp Apology Flow for Cancelled Shopify Orders with Reorder Link"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "gFH3Wjq6yYqSEAei",
"name": "Google Sheets"
}
},
"typeVersion": 4.6
},
{
"id": "cda876a3-a926-4843-97cb-cd84881a5ec4",
"name": "在已验证和已发送1中保存行状态",
"type": "n8n-nodes-base.googleSheets",
"position": [
416,
1424
],
"parameters": {
"columns": {
"value": {
"name": "={{ $('Clean WhatsApp Number').item.json.customer.name }}",
"email": "={{ $('Clean WhatsApp Number').item.json.customer.email }}",
"price": "={{ $('Clean WhatsApp Number').item.json.total.currency }} {{ $('Clean WhatsApp Number').item.json.total.price }}",
"staus": "not sent",
"title": "={{ $('Clean WhatsApp Number').item.json.product[0].title }}",
"number": "={{ $('Clean WhatsApp Number').item.json.customer.phone }}",
"address1": "={{ $('Clean WhatsApp Number').item.json.address.billing.address1 }}",
"validity": "unverified"
},
"schema": [
{
"id": "name",
"type": "string",
"display": true,
"required": false,
"displayName": "name",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "number",
"type": "string",
"display": true,
"required": false,
"displayName": "number",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "email",
"type": "string",
"display": true,
"required": false,
"displayName": "email",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "address1",
"type": "string",
"display": true,
"required": false,
"displayName": "address1",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "price",
"type": "string",
"display": true,
"required": false,
"displayName": "price",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "title",
"type": "string",
"display": true,
"required": false,
"displayName": "title",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "re-order link",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "re-order link",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "validity",
"type": "string",
"display": true,
"required": false,
"displayName": "validity",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "staus",
"type": "string",
"display": true,
"required": false,
"displayName": "staus",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"options": {},
"operation": "append",
"sheetName": {
"__rl": true,
"mode": "list",
"value": "gid=0",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/12zMJod9s3Ov0RZh-7-ZoqTvJr4yMIqOeAQKTBeZlrRk/edit#gid=0",
"cachedResultName": "Sheet1"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "12zMJod9s3Ov0RZh-7-ZoqTvJr4yMIqOeAQKTBeZlrRk",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/12zMJod9s3Ov0RZh-7-ZoqTvJr4yMIqOeAQKTBeZlrRk/edit?usp=drivesdk",
"cachedResultName": "Automated WhatsApp Apology Flow for Cancelled Shopify Orders with Reorder Link"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "gFH3Wjq6yYqSEAei",
"name": "Google Sheets"
}
},
"typeVersion": 4.6
},
{
"id": "caf2a130-1668-4645-845d-70cefb3b665e",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-2512,
880
],
"parameters": {
"width": 1072,
"height": 1536,
"content": "# 当 Shopify 订单取消时发送 WhatsApp 道歉与重新订购链接"
},
"typeVersion": 1
},
{
"id": "24101dba-3187-4c81-9acd-1a01f519d2a1",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1392,
880
],
"parameters": {
"width": 656,
"height": 752,
"content": "## Shopify Trigger (订单取消)"
},
"typeVersion": 1
},
{
"id": "c1b39ae5-85be-429c-b5be-bf229f32c2bb",
"name": "便签2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-720,
992
],
"parameters": {
"width": 720,
"height": 640,
"content": "## Code (清理 WhatsApp 号码)"
},
"typeVersion": 1
},
{
"id": "b798b32b-ebac-442c-8039-b60cedb7c2cf",
"name": "便签3",
"type": "n8n-nodes-base.stickyNote",
"position": [
16,
624
],
"parameters": {
"width": 912,
"height": 1008,
"content": "## IF"
},
"typeVersion": 1
},
{
"id": "24e664e7-aa76-4af1-a693-cef64f07efc6",
"name": "便签5",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1392,
1680
],
"parameters": {
"color": 7,
"width": 560,
"height": 432,
"content": "## 如何使用此工作流"
},
"typeVersion": 1
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "6c800339-1a75-4f63-9926-a57a0af96a61",
"connections": {
"If": {
"main": [
[
{
"node": "Send Message Using Rapiwa",
"type": "main",
"index": 0
}
],
[
{
"node": "Save State of Rows in Verified & Sent1",
"type": "main",
"index": 0
}
]
]
},
"Code": {
"main": [
[
{
"node": "Clean WhatsApp Number",
"type": "main",
"index": 0
}
]
]
},
"Wait": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Loop Over Items": {
"main": [
[],
[
{
"node": "Code",
"type": "main",
"index": 0
}
]
]
},
"Shopify Trigger": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Clean WhatsApp Number": {
"main": [
[
{
"node": "Check valid whatsapp number Using Rapiwa",
"type": "main",
"index": 0
}
]
]
},
"Send Message Using Rapiwa": {
"main": [
[
{
"node": "Save State of Rows in Verified & Sent",
"type": "main",
"index": 0
}
]
]
},
"Save State of Rows in Verified & Sent": {
"main": [
[
{
"node": "Wait",
"type": "main",
"index": 0
}
]
]
},
"Save State of Rows in Verified & Sent1": {
"main": [
[
{
"node": "Wait",
"type": "main",
"index": 0
}
]
]
},
"Check valid whatsapp number Using Rapiwa": {
"main": [
[
{
"node": "If",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
中级 - 客服机器人
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
通过WhatsApp向客户发送WooCommerce订单状态更新
使用Rapiwa API通过WhatsApp向客户发送WooCommerce订单更新
If
Code
Wait
+5
14 节点Rapiwa
客服机器人
使用Rapiwa API自动在WhatsApp上发送WooCommerce发票
使用Rapiwa API通过WhatsApp自动发送WooCommerce发票
If
Code
Wait
+5
15 节点Rapiwa
客户关系管理
WooCommerce订单完成的WhatsApp评价请求自动化
使用Rapiwa通过WhatsApp为完成的WooCommerce订单自动化评价请求
If
Code
Wait
+5
15 节点Rapiwa
客户培育
自动向 Shopify 客户发送 WhatsApp 折扣码
使用 Rapiwa 自动向 Shopify 客户发送 WhatsApp 折扣码
If
Code
Wait
+5
17 节点Rapiwa
使用 Rapiwa API 通过 WhatsApp 向客户发送 WooCommerce 交叉销售优惠
使用 Rapiwa API 通过 WhatsApp 向客户发送 WooCommerce 交叉销售优惠
If
Code
Wait
+6
23 节点Rapiwa
社交媒体
使用 Rapiwa API 通过 WhatsApp 向客户发送 WooCommerce 折扣券
使用 Rapiwa API 通过 WhatsApp 向客户发送 WooCommerce 折扣券
If
Code
Wait
+6
16 节点Rapiwa
社交媒体