8
n8n 中文网amn8n.com

基于Baserow和WasenderAPI的WhatsApp微型CRM

高级

这是一个CRM领域的自动化工作流,包含 29 个节点。主要使用 If, Set, Code, Switch, Baserow 等节点。 基于Baserow和WasenderAPI的WhatsApp微型CRM

前置要求
  • HTTP Webhook 端点(n8n 会自动生成)
  • 可能需要目标 API 的认证凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "834bc6c387a1c56d0622a24b912577f9e6d66c5873f4e6426166054eb488d8fc",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "e276ac8b-4659-431e-a876-590b2532289e",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        280,
        -100
      ],
      "parameters": {
        "width": 540,
        "height": 740,
        "content": "## 基于 Baserow 和 WasenderAPI 的 WhatsApp 微型客户关系管理系统"
      },
      "typeVersion": 1
    },
    {
      "id": "6ffa7908-f596-4654-99f2-9ea6c57bc4a7",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1820,
        60
      ],
      "parameters": {
        "color": 7,
        "width": 820,
        "height": 520,
        "content": "## 1. 管理来电联系人"
      },
      "typeVersion": 1
    },
    {
      "id": "83efa23c-d381-4b91-8eeb-522a544b55db",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2760,
        0
      ],
      "parameters": {
        "color": 7,
        "width": 700,
        "height": 540,
        "content": "## 可选功能:联系人头像"
      },
      "typeVersion": 1
    },
    {
      "id": "6b74df85-924c-471c-9848-e4ea2030f967",
      "name": "webhook测试(测试后删除)",
      "type": "n8n-nodes-base.noOp",
      "position": [
        2060,
        620
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "ea447200-f883-428f-b7ac-1aebe35e0979",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2000,
        800
      ],
      "parameters": {
        "color": 7,
        "width": 1160,
        "height": 520,
        "content": "## 2. 消息类型检测与图片处理"
      },
      "typeVersion": 1
    },
    {
      "id": "ce955b07-9257-4458-8301-e0a2412ccb8a",
      "name": "便签5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1960,
        1640
      ],
      "parameters": {
        "color": 7,
        "width": 820,
        "height": 560,
        "content": "## 3. 此处仅记录文本消息"
      },
      "typeVersion": 1
    },
    {
      "id": "c940dd3a-0984-49dd-848e-38608a0d877c",
      "name": "便签6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1060,
        420
      ],
      "parameters": {
        "color": 6,
        "width": 380,
        "height": 240,
        "content": "## 重要提示"
      },
      "typeVersion": 1
    },
    {
      "id": "ccb8b5b5-dec7-4d69-b3bd-e5e6e8087e64",
      "name": "Baserow:搜索联系人",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1900,
        260
      ],
      "parameters": {
        "url": "https://api.baserow.io/api/database/rows/table/622539/",
        "options": {},
        "sendQuery": true,
        "sendHeaders": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "user_field_names",
              "value": "true"
            },
            {
              "name": "search",
              "value": "={{ $json.readable_phone_number }}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Token <your token>"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "8f2f2f9c-3824-42e7-a4b7-23d4b82f20b7",
      "name": "路由:联系人是否存在?",
      "type": "n8n-nodes-base.switch",
      "position": [
        2120,
        260
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "New_Contact",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "e930a9f3-ad63-4c99-bff4-931ddbfe1bca",
                    "operator": {
                      "type": "number",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.count }}",
                    "rightValue": 0
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Existing_Contact",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "6071cc1e-70ba-4072-bfcb-6c56aa3ecb4e",
                    "operator": {
                      "type": "number",
                      "operation": "gt"
                    },
                    "leftValue": "={{ $json.count }}",
                    "rightValue": 0
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {},
        "looseTypeValidation": true
      },
      "typeVersion": 3.2
    },
    {
      "id": "8efc8abc-e331-4a0e-b14b-b5047fbcf086",
      "name": "创建新联系人",
      "type": "n8n-nodes-base.baserow",
      "position": [
        2460,
        160
      ],
      "parameters": {
        "tableId": 622539,
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": 5064505,
              "fieldValue": "={{ $('Prepare: Standardize Incoming Data').item.json.readable_phone_number }}"
            },
            {
              "fieldId": 5064506,
              "fieldValue": "={{ $('Prepare: Standardize Incoming Data').item.json.body.data.messages.pushName }}"
            },
            {
              "fieldId": 5064507,
              "fieldValue": "New"
            },
            {
              "fieldId": 5064508,
              "fieldValue": "={{ $('Prepare: Standardize Incoming Data').item.json.body.timestamp.toDateTime('ms')}}"
            }
          ]
        },
        "operation": "create",
        "databaseId": 264981
      },
      "credentials": {
        "baserowApi": {
          "id": "HadM27Hzjj2CaqeH",
          "name": "Baserow account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "4f976974-20c2-4a52-8c29-330aad9404d7",
      "name": "更新联系人时间戳",
      "type": "n8n-nodes-base.baserow",
      "position": [
        2460,
        360
      ],
      "parameters": {
        "rowId": "={{ $json.results[0].id }}",
        "tableId": 622539,
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": 5064508,
              "fieldValue": "={{$now.setLocale(nl-NL).toLocal()}}"
            }
          ]
        },
        "operation": "update",
        "databaseId": 264981
      },
      "credentials": {
        "baserowApi": {
          "id": "HadM27Hzjj2CaqeH",
          "name": "Baserow account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "841d7a05-5afd-4d53-80cb-bbb7b5665201",
      "name": "WasenderAPI:获取头像URL",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2840,
        160
      ],
      "parameters": {
        "url": "=https://www.wasenderapi.com/api/contacts/{{ $('Prepare: Standardize Incoming Data').item.json.body.data.messages.key.remoteJid }}/picture",
        "options": {},
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer <your token>"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "9f7c8e1b-94e7-446c-8286-2720c051510d",
      "name": "Baserow:上传头像文件",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3060,
        160
      ],
      "parameters": {
        "url": "https://api.baserow.io/api/user-files/upload-via-url/",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n    \"url\": \"{{ $json.data.imgUrl}}\"\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Token <your token>"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "c834feb4-f935-4606-bf2b-c4fc27b8a2ce",
      "name": "更新联系人头像字段",
      "type": "n8n-nodes-base.baserow",
      "position": [
        3280,
        160
      ],
      "parameters": {
        "rowId": "={{ $('Create New Contact').item.json.id }}",
        "tableId": 622539,
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": 5065051,
              "fieldValue": "={{ $json.name }}"
            }
          ]
        },
        "operation": "update",
        "databaseId": 264981
      },
      "credentials": {
        "baserowApi": {
          "id": "HadM27Hzjj2CaqeH",
          "name": "Baserow account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "bd55cfc2-db60-44a3-ae86-8b5d743d385b",
      "name": "路由:消息类型(图片/文本)",
      "type": "n8n-nodes-base.switch",
      "position": [
        1600,
        980
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Testing",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "abc80fe6-2034-4918-8738-2cc3ce93cd03",
                    "operator": {
                      "type": "boolean",
                      "operation": "true",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.body.data.test }}",
                    "rightValue": "webhook.test"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "has_image",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "b865b469-58bd-4cfa-b359-bb2dbeb11134",
                    "operator": {
                      "type": "boolean",
                      "operation": "true",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.found_image }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "txt_only",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "9a58353d-6ed0-45b4-8553-87d4326c5bb9",
                    "operator": {
                      "type": "boolean",
                      "operation": "false",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.found_image }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {},
        "looseTypeValidation": true
      },
      "typeVersion": 3.2
    },
    {
      "id": "96602e32-242e-435d-9d41-4bec08ad2f8d",
      "name": "提取:图片消息数据",
      "type": "n8n-nodes-base.set",
      "position": [
        2040,
        980
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "08f9b688-dc42-4724-b9e3-5969215f69f2",
              "name": "message_object",
              "type": "object",
              "value": "={{ $json.body.data.messages.message }}"
            },
            {
              "id": "ca2ab33b-ab78-4615-9052-f7dfafe9d20d",
              "name": "message_id",
              "type": "string",
              "value": "={{ $json.body.data.messages.key.id }}"
            },
            {
              "id": "cd93ec84-ccb1-4944-bee9-ef360bb7df8d",
              "name": "remoteJid (wasenderapi)",
              "type": "string",
              "value": "={{ $json.body.data.messages.key.remoteJid }}"
            },
            {
              "id": "a25f071c-70a6-45aa-b0fe-0c3256d41039",
              "name": "fromMe (for filtering purposes)",
              "type": "boolean",
              "value": "={{ $json.body.data.messages.key.fromMe }}"
            },
            {
              "id": "a09926b2-52ab-44ce-ba6c-29a58c90d99a",
              "name": "readable_phone_number",
              "type": "string",
              "value": "={{ $json.readable_phone_number }}"
            },
            {
              "id": "72993315-16a0-4aab-89d5-38dd354aa6df",
              "name": "found_image",
              "type": "boolean",
              "value": "={{ $json.found_image }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "18b56bc9-a2c5-48b0-a9e2-e6397b1ac522",
      "name": "WasenderAPI:解密外发图片",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2520,
        920
      ],
      "parameters": {
        "url": "https://www.wasenderapi.com/api/decrypt-media",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"data\": {\n    \"messages\": {\n      \"key\": {\n        \"id\": \"{{ $json.message_id }}\"\n      },\n      \"message\": {\n        \"imageMessage\": {\n          \"url\": \"{{ $json.message_object.imageMessage.url }}\",\n          \"mimetype\": \"{{ $json.message_object.imageMessage.mimetype }}\",\n          \"mediaKey\": \"{{ $json.message_object.imageMessage.mediaKey }}\"\n        }\n      }\n    }\n  }\n} ",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer <your token>"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "dcce686f-56c4-4073-917f-1cdbcf2f2668",
      "name": "WasenderAPI:解密接收图片",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2520,
        1100
      ],
      "parameters": {
        "url": "https://www.wasenderapi.com/api/decrypt-media",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"data\": {\n    \"messages\": {\n      \"key\": {\n        \"id\": \"{{ $json.message_id }}\"\n      },\n      \"message\": {\n        \"imageMessage\": {\n          \"url\": \"{{ $json.message_object.imageMessage.url }}\",\n          \"mimetype\": \"{{ $json.message_object.imageMessage.mimetype }}\",\n          \"mediaKey\": \"{{ $json.message_object.imageMessage.mediaKey }}\"\n        }\n      }\n    }\n  }\n} ",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer <your token>"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "bf50d793-04a4-4b5d-bf13-c311b604a2d1",
      "name": "Baserow 上传消息图片",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2720,
        920
      ],
      "parameters": {
        "url": "https://api.baserow.io/api/user-files/upload-via-url/",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n    \"url\": \"{{ $json.publicUrl }}\"\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Token <your token>"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "87b605aa-b7be-4a36-bb9d-e1d35e67afbd",
      "name": "Baserow_上传消息图片",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2720,
        1100
      ],
      "parameters": {
        "url": "https://api.baserow.io/api/user-files/upload-via-url/",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n    \"url\": \"{{ $json.publicUrl }}\"\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Token <your token>"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "65ecd4e0-6b34-4b76-8ab5-9bcb7ff9d23e",
      "name": "记录接收的图片消息",
      "type": "n8n-nodes-base.baserow",
      "position": [
        2940,
        1100
      ],
      "parameters": {
        "tableId": 622533,
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": 5064439,
              "fieldValue": "={{ $('Extract: Image Message Data').item.json.message_id }}"
            },
            {
              "fieldId": 5064440,
              "fieldValue": "={{ $('Extract: Image Message Data').item.json.readable_phone_number }}"
            },
            {
              "fieldId": 5065335,
              "fieldValue": "={{ $json.name }}"
            },
            {
              "fieldId": 5064444,
              "fieldValue": "Unread"
            },
            {
              "fieldId": 5064441,
              "fieldValue": "Inbound"
            },
            {
              "fieldId": 5064443,
              "fieldValue": "={{ $('Extract: Image Message Data').item.json.message_object.messageContextInfo.deviceListMetadata.recipientTimestamp.toDateTime('s')}}"
            }
          ]
        },
        "operation": "create",
        "databaseId": 264981
      },
      "credentials": {
        "baserowApi": {
          "id": "HadM27Hzjj2CaqeH",
          "name": "Baserow account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "421dce70-b96e-4697-8db1-2d3b1914aad5",
      "name": "记录外发的图片消息",
      "type": "n8n-nodes-base.baserow",
      "position": [
        2940,
        920
      ],
      "parameters": {
        "tableId": 622533,
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": 5064439,
              "fieldValue": "={{ $('Extract: Image Message Data').item.json.message_id }}"
            },
            {
              "fieldId": 5064440,
              "fieldValue": "={{ $('Extract: Image Message Data').item.json.readable_phone_number }}"
            },
            {
              "fieldId": 5065335,
              "fieldValue": "={{ $json.name }}"
            },
            {
              "fieldId": 5064444,
              "fieldValue": "Unread"
            },
            {
              "fieldId": 5064441,
              "fieldValue": "Outbound"
            },
            {
              "fieldId": 5064443,
              "fieldValue": "={{ $('Extract: Image Message Data').item.json.message_object.messageContextInfo.deviceListMetadata.recipientTimestamp.toDateTime('s')}}"
            }
          ]
        },
        "operation": "create",
        "databaseId": 264981
      },
      "credentials": {
        "baserowApi": {
          "id": "HadM27Hzjj2CaqeH",
          "name": "Baserow account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "fd725c80-806f-463e-b812-093d86eec91d",
      "name": "提取:文本消息数据",
      "type": "n8n-nodes-base.set",
      "position": [
        2000,
        1860
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "08f9b688-dc42-4724-b9e3-5969215f69f2",
              "name": "message_object",
              "type": "object",
              "value": "={{ $json.body.data.messages.message }}"
            },
            {
              "id": "ca2ab33b-ab78-4615-9052-f7dfafe9d20d",
              "name": "message_id",
              "type": "string",
              "value": "={{ $json.body.data.messages.key.id }}"
            },
            {
              "id": "cd93ec84-ccb1-4944-bee9-ef360bb7df8d",
              "name": "remoteJid (wasenderapi)",
              "type": "string",
              "value": "={{ $json.body.data.messages.key.remoteJid }}"
            },
            {
              "id": "a25f071c-70a6-45aa-b0fe-0c3256d41039",
              "name": "fromMe (for filtering purposes)",
              "type": "boolean",
              "value": "={{ $json.body.data.messages.key.fromMe }}"
            },
            {
              "id": "a09926b2-52ab-44ce-ba6c-29a58c90d99a",
              "name": "readable_phone_number",
              "type": "string",
              "value": "={{ $json.readable_phone_number }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "e05079d7-6e92-4716-bec1-240886628b50",
      "name": "路由:消息来源(外发/接收)",
      "type": "n8n-nodes-base.if",
      "position": [
        2180,
        1860
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "87a619cb-67b0-4f86-abdf-6e06a53da2d4",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json['fromMe (for filtering purposes)'] }}",
              "rightValue": ""
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "b543195a-4ae8-40a3-8401-f0e422bb80dc",
      "name": "记录外发文本消息",
      "type": "n8n-nodes-base.baserow",
      "position": [
        2480,
        1760
      ],
      "parameters": {
        "tableId": 622533,
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": 5064439,
              "fieldValue": "={{ $json.message_id }}"
            },
            {
              "fieldId": 5064440,
              "fieldValue": "={{ $json.readable_phone_number }}"
            },
            {
              "fieldId": 5064444,
              "fieldValue": "Unread"
            },
            {
              "fieldId": 5064441,
              "fieldValue": "Outbound"
            },
            {
              "fieldId": 5064443,
              "fieldValue": "={{ $json.message_object.messageContextInfo.deviceListMetadata.recipientTimestamp.toDateTime('s')}}"
            },
            {
              "fieldId": 5064442,
              "fieldValue": "={{ $json.message_object.conversation || $json.message_object.reactionMessage.text}}"
            }
          ]
        },
        "operation": "create",
        "databaseId": 264981
      },
      "credentials": {
        "baserowApi": {
          "id": "HadM27Hzjj2CaqeH",
          "name": "Baserow account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "da6b95a9-ac1d-4f90-a1ac-ff47b2826eaa",
      "name": "记录接收文本消息",
      "type": "n8n-nodes-base.baserow",
      "position": [
        2460,
        1980
      ],
      "parameters": {
        "tableId": 622533,
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": 5064439,
              "fieldValue": "={{ $json.message_id }}"
            },
            {
              "fieldId": 5064440,
              "fieldValue": "={{ $json.readable_phone_number }}"
            },
            {
              "fieldId": 5064444,
              "fieldValue": "Unread"
            },
            {
              "fieldId": 5064441,
              "fieldValue": "Inbound"
            },
            {
              "fieldId": 5064443,
              "fieldValue": "={{ $json.message_object.messageContextInfo.deviceListMetadata.recipientTimestamp.toDateTime('s')}}"
            },
            {
              "fieldId": 5064442,
              "fieldValue": "={{ $json.message_object.conversation || $json.message_object.reactionMessage.text}}"
            }
          ]
        },
        "operation": "create",
        "databaseId": 264981
      },
      "credentials": {
        "baserowApi": {
          "id": "HadM27Hzjj2CaqeH",
          "name": "Baserow account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "ff623bac-b802-41c0-9053-129b725c0e78",
      "name": "触发器:WhatsApp 消息",
      "type": "n8n-nodes-base.webhook",
      "position": [
        1140,
        720
      ],
      "webhookId": "9218c291-18b1-44a6-9b1c-4df4ff7605f6",
      "parameters": {
        "path": "9218c291-18b1-44a6-9b1c-4df4ff7605f6",
        "options": {},
        "httpMethod": "POST",
        "authentication": "headerAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "id": "sFH79l1dvIvxEu2W",
          "name": "whatsapp_hook"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "70541065-1e4c-4ad0-bdd8-73a319f48699",
      "name": "准备:标准化输入数据",
      "type": "n8n-nodes-base.code",
      "position": [
        1320,
        720
      ],
      "parameters": {
        "language": "python",
        "pythonCode": "import json\n\ndef check_for_image_message(whatsapp_payload_body):\n    \"\"\"\n    Checks if a WhatsApp webhook payload contains an image message\n    and extracts the URL if present. \n\n    Args:\n        whatsapp_payload_body (dict): The 'body' of the WhatsApp webhook payload.\n\n    Returns:\n        tuple: (bool, str or None) A tuple where the first element is True\n                       if an image message is found, otherwise False.\n                       The second element is the URL of the image if found,\n                       otherwise None.\n    \"\"\"\n    try:\n        message_data = whatsapp_payload_body.get('data', {}).get('messages', {}).get('message', {})\n\n        if 'imageMessage' in message_data and message_data['imageMessage']:\n            image_message = message_data['imageMessage']\n            image_url = image_message.get('url')\n            return True, image_url\n        else:\n            return False, None\n    except Exception as e:\n        print(f\"Error in check_for_image_message: {e}\")\n        return False, None\n\n# Function to convert JID to readable phone number\ndef jid_to_readable_number(jid):\n    \"\"\"\n    Converts a WhatsApp JID to a readable phone number format.\n    Example: '8615621124179@s.whatsapp.net' -> '+8615621124179'\n    \"\"\"\n    if jid and '@s.whatsapp.net' in jid:\n        number_part = jid.split('@')[0]\n        return f'+{number_part}'\n    return jid # Returns original JID if format not recognized\n\n\nfor item in items:\n    whatsapp_full_payload = item.json\n\n    # Check if 'body' and 'remoteJid' exist before attempting to convert\n    remote_jid = whatsapp_full_payload.get('body', {}).get('data', {}).get('messages', {}).get('remoteJid')\n    \n    # Add the readable phone number\n    item.json['readable_phone_number'] = jid_to_readable_number(remote_jid)\n\n    # Perform image detection as before\n    found_image, image_url = check_for_image_message(whatsapp_full_payload.get('body', {}))\n    item.json['found_image'] = found_image\n    item.json['image_url'] = image_url\n    \nreturn items"
      },
      "typeVersion": 2
    },
    {
      "id": "0bfec423-676f-4113-8d12-8b8b41c3d67d",
      "name": "路由:消息来源(外发/接收)1",
      "type": "n8n-nodes-base.if",
      "position": [
        2240,
        980
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "87a619cb-67b0-4f86-abdf-6e06a53da2d4",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json['fromMe (for filtering purposes)'] }}",
              "rightValue": ""
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.2
    }
  ],
  "pinData": {},
  "connections": {
    "Create New Contact": {
      "main": [
        [
          {
            "node": "WasenderAPI: Fetch Profile Picture URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route: Contact Exists?": {
      "main": [
        [
          {
            "node": "Create New Contact",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Update Contact Timestamp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Baserow: Search Contact": {
      "main": [
        [
          {
            "node": "Route: Contact Exists?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Trigger: WhatsApp Message": {
      "main": [
        [
          {
            "node": "Prepare: Standardize Incoming Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract: Text Message Data": {
      "main": [
        [
          {
            "node": "Route: Message Origin (Outbound/Inbound)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract: Image Message Data": {
      "main": [
        [
          {
            "node": "Route: Message Origin (Outbound/Inbound)1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Baserow Upload Message Image": {
      "main": [
        [
          {
            "node": "Log Outbound Image Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Baserow_Upload Message Image": {
      "main": [
        [
          {
            "node": "Log Inbound Image Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route: Message Type (Image/Text)": {
      "main": [
        [
          {
            "node": "webhooktest (delete after testing)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract: Image Message Data",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract: Text Message Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare: Standardize Incoming Data": {
      "main": [
        [
          {
            "node": "Route: Message Type (Image/Text)",
            "type": "main",
            "index": 0
          },
          {
            "node": "Baserow: Search Contact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WasenderAPI: Decrypt Image Inbound": {
      "main": [
        [
          {
            "node": "Baserow_Upload Message Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WasenderAPI: Decrypt Image Outbound": {
      "main": [
        [
          {
            "node": "Baserow Upload Message Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Baserow: Upload Profile Picture File": {
      "main": [
        [
          {
            "node": "Update Contact Profile Picture Field",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WasenderAPI: Fetch Profile Picture URL": {
      "main": [
        [
          {
            "node": "Baserow: Upload Profile Picture File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route: Message Origin (Outbound/Inbound)": {
      "main": [
        [
          {
            "node": "Log Outbound Text Message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log Inbound Text Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route: Message Origin (Outbound/Inbound)1": {
      "main": [
        [
          {
            "node": "WasenderAPI: Decrypt Image Outbound",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "WasenderAPI: Decrypt Image Inbound",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 客户关系管理

需要付费吗?

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

工作流信息
难度等级
高级
节点数量29
分类1
节点类型9
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者
Stephan Koning

Stephan Koning

@reklaim

Account Executive by day , Noco builder for fun at night and always a proud dad of Togo the Samoyed.

外部链接
在 n8n.io 查看

分享此工作流