8
n8n 中文网amn8n.com

使用Rapiwa API自动在WhatsApp上发送WooCommerce发票

中级

这是一个CRM领域的自动化工作流,包含 15 个节点。主要使用 If, Code, Wait, HttpRequest, GoogleSheets 等节点。 使用Rapiwa API通过WhatsApp自动发送WooCommerce发票

前置要求
  • 可能需要目标 API 的认证凭证
  • Google Sheets API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "ze5g8DGP9lpajRcO",
  "meta": {
    "instanceId": "cb9a1e5321767b6316634728341237e564b2587ab15b74ca0a89eb02a53484d6"
  },
  "name": "使用 Rapiwa API 自动在 WhatsApp 上发送 WooCommerce 发票",
  "tags": [],
  "nodes": [
    {
      "id": "5f97a4ae-506f-4eeb-b65b-7387d6db9d37",
      "name": "条件判断",
      "type": "n8n-nodes-base.if",
      "position": [
        1600,
        784
      ],
      "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": "54f3f8ff-50f7-455d-8cbc-ba13df739240",
      "name": "等待",
      "type": "n8n-nodes-base.wait",
      "position": [
        2096,
        864
      ],
      "webhookId": "6c474e54-eb3c-4fcd-b455-948322cd0121",
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "61f4a6bc-43fd-44f9-a1bf-09ad7fb8cc78",
      "name": "遍历项目",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        624,
        768
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "bff871ca-9ae6-4988-ada1-6d5f5ea9f959",
      "name": "清理 Webhooks 响应数据",
      "type": "n8n-nodes-base.code",
      "position": [
        192,
        768
      ],
      "parameters": {
        "jsCode": "return $input.all().map(item => {\n  const body = item.json;\n\n  const customer = {\n    first_name: body.billing.first_name,\n    last_name: body.billing.last_name,\n    name: body.billing.first_name + ' ' + body.billing.last_name,\n    email: body.billing.email,\n    phone: body.billing.phone,\n    address: {\n      address_1: body.billing.address_1,\n      address_2: body.billing.address_2,\n      city: body.billing.city,\n      state: body.billing.state,\n      postcode: body.billing.postcode,\n      country: body.billing.country\n    }\n  };\n\n  const products = body.line_items.map(product => ({\n    name: product.name,\n    product_id: product.product_id,\n    variation_id: product.variation_id,\n    quantity: product.quantity,\n    total: `${body.currency} ${product.total}`, // for currency here\n    price: product.price,\n    currency: body.currency,\n    image: product.image?.src || null,\n    size: product.meta_data?.find(meta => meta.key === \"size\")?.value || null\n  }));\n\n  return {\n    json: {\n      data: {\n        customer,\n        products,\n        invoice_link: body.payment_url\n      }\n    }\n  };\n});\n"
      },
      "typeVersion": 2
    },
    {
      "id": "bde660f4-cf63-4d5e-bff2-65f8c77f3342",
      "name": "清理 WhatsApp 号码",
      "type": "n8n-nodes-base.code",
      "position": [
        1024,
        784
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\n\nconst updatedItems = items.map((item) => {\n  const waNo = item?.json?.[\"number\"];\n  const waNoStr = typeof waNo === 'string'\n    ? waNo\n    : (waNo !== undefined && waNo !== null ? String(waNo) : \"\");\n\n  const cleanedNumber = waNoStr.replace(/\\D/g, \"\"); // Remove non-digit characters\n\n  item.json[\"number\"] = cleanedNumber;\n\n  return item;\n});\n\nreturn updatedItems;\n"
      },
      "typeVersion": 2
    },
    {
      "id": "bbda923c-2c75-4f33-9b78-d0b895f91ac7",
      "name": "使用 Rapiwa 检查有效的 WhatsApp 号码",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1264,
        784
      ],
      "parameters": {
        "url": "=https://app.rapiwa.com/api/verify-whatsapp",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "number",
              "value": "={{ $json.data.customer.phone }}"
            }
          ]
        },
        "genericAuthType": "httpBearerAuth"
      },
      "credentials": {
        "httpBearerAuth": {
          "id": "jnaHCyYia9OAFozh",
          "name": "Rapiwa Bearer YOUR_TOKEN_HERE"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "688ab63d-8a18-4596-8354-9faaec7ac854",
      "name": "使用 Rapiwa 发送消息",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1856,
        672
      ],
      "parameters": {
        "url": "=https://app.rapiwa.com/api/send-message",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "number",
              "value": "={{ $json.data.number }}"
            },
            {
              "name": "message_type",
              "value": "text"
            },
            {
              "name": "message",
              "value": "=Hey *{{ $('Clean WhatsApp Number').item.json.data.customer.name }}*,\n\nThank you for your recent order from *SpaGreen Creative*!\nWe truly appreciate your support.\n\n🛍️ *Order Summary:*\n• *Product:* {{ $('Clean WhatsApp Number').item.json.data.products[0].name }}\n• *Size:* {{ $('Clean WhatsApp Number').item.json.data.products[0].size }}\n• *Quantity:* {{ $('Clean WhatsApp Number').item.json.data.products[0].quantity }}\n• *Product ID:* {{ $('Clean WhatsApp Number').item.json.data.products[0].product_id }}\n• *Price per item:* {{ $('Clean WhatsApp Number').item.json.data.products[0].price }}\n• *Total Price:* {{ $('Clean WhatsApp Number').item.json.data.products[0].total }} \n\n📦 *Shipping Address:* {{ $('Clean WhatsApp Number').item.json.data.customer.address.address_1 }}\n\n🖼️ *Product Preview:* {{ $('Clean WhatsApp Number').item.json.data.products[0].image }}\n\n🧾 *Invoice:* {{ $('Clean WhatsApp Number').item.json.data.invoice_link }}\n\nIf you have any questions or need help, feel free to reach out.\n\n– Team *SpaGreen Creative*\n"
            }
          ]
        },
        "genericAuthType": "httpBearerAuth"
      },
      "credentials": {
        "httpBearerAuth": {
          "id": "jnaHCyYia9OAFozh",
          "name": "Rapiwa Bearer YOUR_TOKEN_HERE"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "77e7e43e-79ca-48bd-a85d-7be61344a3bd",
      "name": "在已验证和已发送表格中追加行",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2080,
        672
      ],
      "parameters": {
        "columns": {
          "value": {
            "name": "={{ $('Clean WhatsApp Number').item.json.data.customer.name }}",
            "size": "={{ $('Clean WhatsApp Number').item.json.data.products[0].size }}",
            "email": "={{ $('Clean WhatsApp Number').item.json.data.customer.email }}",
            "number": "={{ $json.to }}",
            "status": "sent",
            "address1": "={{ $('Clean WhatsApp Number').item.json.data.customer.address.address_1 }}",
            "quantity": "={{ $('Clean WhatsApp Number').item.json.data.products[0].quantity }}",
            "validity": "verified",
            "productId": "={{ $('Clean WhatsApp Number').item.json.data.products[0].product_id }}",
            "totalPrice": "={{ $('Clean WhatsApp Number').item.json.data.products[0].total }}",
            "invoiceLink": "={{ $('Clean WhatsApp Number').item.json.data.invoice_link }}",
            "productImage": "={{ $('Clean WhatsApp Number').item.json.data.products[0].image }}",
            "productTitle": "={{ $('Clean WhatsApp Number').item.json.data.products[0].name }}"
          },
          "schema": [
            {
              "id": "name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "number",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "address1",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "address1",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "productTitle",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "productTitle",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "productId",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "productId",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "size",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "size",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "quantity",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "quantity",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "totalPrice",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "totalPrice",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "productImage",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "productImage",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "invoiceLink",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "invoiceLink",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "status",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "validity",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "validity",
              "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/1NVYsvOg3mzsAGlzJiL7-2mtkN-5gsmqd3fG8hboE3vk/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1NVYsvOg3mzsAGlzJiL7-2mtkN-5gsmqd3fG8hboE3vk",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1NVYsvOg3mzsAGlzJiL7-2mtkN-5gsmqd3fG8hboE3vk/edit?usp=drivesdk",
          "cachedResultName": "WooCommerce - Send WhatsApp invoice link"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "gFH3Wjq6yYqSEAei",
          "name": "Google Sheets"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "ffac664e-9c0c-48e8-aa24-2256cfbbaca2",
      "name": "WooCommerce 触发器",
      "type": "n8n-nodes-base.wooCommerceTrigger",
      "position": [
        -64,
        768
      ],
      "webhookId": "3aa9eb89-094d-49ba-904a-5c2d43015db8",
      "parameters": {
        "event": "order.updated"
      },
      "credentials": {
        "wooCommerceApi": {
          "id": "BZ5Lp9IB4Phney4R",
          "name": "WooCommerce (get customer)"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "9ed7e611-af93-4329-a39c-992cbdc51b33",
      "name": "在未验证和未发送表格中追加行",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1872,
        864
      ],
      "parameters": {
        "columns": {
          "value": {
            "name": "={{ $('Clean WhatsApp Number').item.json.data.customer.name }}",
            "size": "={{ $('Clean WhatsApp Number').item.json.data.products[0].size }}",
            "email": "={{ $('Clean WhatsApp Number').item.json.data.customer.email }}",
            "number": "={{ $json.data.number }}",
            "status": "not sent",
            "address1": "={{ $('Clean WhatsApp Number').item.json.data.customer.address.address_1 }}",
            "quantity": "={{ $('Clean WhatsApp Number').item.json.data.products[0].quantity }}",
            "validity": "unverified",
            "productId": "={{ $('Clean WhatsApp Number').item.json.data.products[0].product_id }}",
            "totalPrice": "={{ $('Clean WhatsApp Number').item.json.data.products[0].total }}",
            "invoiceLink": "={{ $('Clean WhatsApp Number').item.json.data.invoice_link }}",
            "productImage": "={{ $('Clean WhatsApp Number').item.json.data.products[0].image }}",
            "productTitle": "={{ $('Clean WhatsApp Number').item.json.data.products[0].name }}"
          },
          "schema": [
            {
              "id": "name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "number",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "address1",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "address1",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "productTitle",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "productTitle",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "productId",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "productId",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "size",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "size",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "quantity",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "quantity",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "totalPrice",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "totalPrice",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "productImage",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "productImage",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "invoiceLink",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "invoiceLink",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "status",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "validity",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "validity",
              "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/1NVYsvOg3mzsAGlzJiL7-2mtkN-5gsmqd3fG8hboE3vk/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1NVYsvOg3mzsAGlzJiL7-2mtkN-5gsmqd3fG8hboE3vk",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1NVYsvOg3mzsAGlzJiL7-2mtkN-5gsmqd3fG8hboE3vk/edit?usp=drivesdk",
          "cachedResultName": "WooCommerce - Send WhatsApp invoice link"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "gFH3Wjq6yYqSEAei",
          "name": "Google Sheets"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "7f93c1a4-5703-4edd-976f-fecf168023e4",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1392,
        480
      ],
      "parameters": {
        "width": 1216,
        "height": 1072,
        "content": "# 使用 Rapiwa API 自动在 WhatsApp 上发送 WooCommerce 发票"
      },
      "typeVersion": 1
    },
    {
      "id": "ffb8f162-d281-4700-a655-9c67cd3db51d",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1504,
        176
      ],
      "parameters": {
        "width": 848,
        "height": 912,
        "content": "## 条件判断"
      },
      "typeVersion": 1
    },
    {
      "id": "da93b6ea-eabe-49f2-82e1-74bfc22921cc",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        832,
        416
      ],
      "parameters": {
        "width": 656,
        "height": 672,
        "content": "## 1. 清理 WhatsApp 号码"
      },
      "typeVersion": 1
    },
    {
      "id": "3b65cf78-cfc1-417b-8a45-3719a25efbf0",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -160,
        480
      ],
      "parameters": {
        "width": 624,
        "height": 608,
        "content": "## 1. WooCommerce 触发器"
      },
      "typeVersion": 1
    },
    {
      "id": "8e38d72a-772a-4203-8d71-4953684bcc8e",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -160,
        1104
      ],
      "parameters": {
        "color": 7,
        "width": 2512,
        "height": 448,
        "content": "## 使用方法 — 逐步设置"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "bbe634d2-4b6c-45a8-b76d-78e29d6e7ebd",
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Send Message Using Rapiwa",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Append Rows in Sheet Unverified & Not sent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Clean WhatsApp Number",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WooCommerce Trigger": {
      "main": [
        [
          {
            "node": "Clean Webhooks Response Data",
            "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": "Append Rows in Sheet Verified & Sent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Clean Webhooks Response Data": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append Rows in Sheet Verified & Sent": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check valid whatsapp number Using Rapiwa": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append Rows in Sheet Unverified & Not sent": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 客户关系管理

需要付费吗?

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

工作流信息
难度等级
中级
节点数量15
分类1
节点类型8
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

外部链接
在 n8n.io 查看

分享此工作流