8
n8n 中文网amn8n.com

将来自Evolution API的消息转发到Chatwoot并支持媒体

高级

这是一个Support Chatbot领域的自动化工作流,包含 36 个节点。主要使用 If, Set, Code, Wait, Redis 等节点。 支持媒体传输的WhatsApp到Chatwoot消息转发器

前置要求
  • Redis 服务器连接信息
  • PostgreSQL 数据库连接信息
  • 可能需要目标 API 的认证凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "zmuAW16DkWnYc6pe",
  "meta": {
    "instanceId": "3b1da7be1b0adaa96356a0c9a5351bedc819261e21791dcc60714d00d82a1136",
    "templateCredsSetupCompleted": true
  },
  "name": "将来自 evolution api 的消息转发到 Chatwoot 并支持媒体",
  "tags": [],
  "nodes": [
    {
      "id": "e88b542d-551b-47ad-8f93-e55f8a145d3d",
      "name": "转换为文件",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        2416,
        320
      ],
      "parameters": {
        "options": {
          "fileName": "={{ $('CODE - MESSAGE OBJECT').item.json.arquivos[0].nm_Arquivo }}",
          "mimeType": "={{ $json.mimetype }}"
        },
        "operation": "toBinary",
        "sourceProperty": "base64",
        "binaryPropertyName": "=data"
      },
      "typeVersion": 1.1
    },
    {
      "id": "056d6ec8-3031-4467-b259-99b7e7390c6a",
      "name": "BASE64",
      "type": "n8n-nodes-base.code",
      "position": [
        2160,
        320
      ],
      "parameters": {
        "jsCode": "return $('EVOLUTION - GET FILE').first().json.data;"
      },
      "typeVersion": 2
    },
    {
      "id": "96a82a81-c985-406d-b3cd-11b4e4910523",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -4224,
        32
      ],
      "parameters": {
        "width": 312,
        "height": 340,
        "content": "## 消息类型"
      },
      "typeVersion": 1
    },
    {
      "id": "81569053-82e9-465f-8bbd-6eef0b461cbd",
      "name": "有效消息类型?",
      "type": "n8n-nodes-base.if",
      "position": [
        -4128,
        192
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "c6900a9d-f55e-446c-8805-66a209796135",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.sn_Mensagem_Valida }}",
              "rightValue": "conversation"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "07339125-f5de-4f4d-9f90-39aef7b449c7",
      "name": "当由另一个工作流执行时",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        -5312,
        192
      ],
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "cd_account",
              "type": "number"
            },
            {
              "name": "cd_inbox_chatwoot",
              "type": "number"
            },
            {
              "name": "ds_msg",
              "type": "object"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "f92a7528-bfd9-4c68-9984-3c1a27eb0803",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3472,
        192
      ],
      "parameters": {
        "color": 4,
        "width": 632,
        "height": 324,
        "content": "## 检查 WhatsApp 消息 ID 是否已发送"
      },
      "typeVersion": 1
    },
    {
      "id": "e44fa6ad-3b6b-4001-8fa4-3329ecce5469",
      "name": "REDIS - EVOLUTION 消息 - 获取",
      "type": "n8n-nodes-base.redis",
      "position": [
        -3408,
        336
      ],
      "parameters": {
        "key": "=wa_{{ $('PARAMETERS').item.json.cd_account }}_{{ $('PARAMETERS').item.json.cd_inbox_chatwoot }}_{{ $('PARAMETERS').item.json.cd_mensagem_evolution }}",
        "options": {
          "dotNotation": false
        },
        "operation": "get",
        "propertyName": "cd_mensagem_evolution"
      },
      "credentials": {
        "redis": {
          "id": "A9jcwJaD5DbwaS7D",
          "name": "Redis account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "350812dc-a2ad-43eb-aaf5-d9bfef9ae427",
      "name": "REDIS - EVOLUTION 消息 - 设置",
      "type": "n8n-nodes-base.redis",
      "position": [
        -2976,
        320
      ],
      "parameters": {
        "key": "=wa_{{ $('PARAMETERS').item.json.cd_account }}_{{ $('PARAMETERS').item.json.cd_inbox_chatwoot }}_{{ $('PARAMETERS').item.json.cd_mensagem_evolution }}",
        "value": "={{ $('PARAMETERS').item.json.cd_mensagem_evolution }}",
        "expire": true,
        "keyType": "string",
        "operation": "set"
      },
      "credentials": {
        "redis": {
          "id": "A9jcwJaD5DbwaS7D",
          "name": "Redis account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "4d5d3ccd-e773-4875-9c72-0dd2146a9f02",
      "name": "等待",
      "type": "n8n-nodes-base.wait",
      "position": [
        -5120,
        192
      ],
      "webhookId": "cad2617b-331e-45cc-871d-a08d6eeff2f1",
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "63b81b6b-8e5e-48f2-bc38-36e950d4cf30",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2720,
        32
      ],
      "parameters": {
        "color": 3,
        "width": 1176,
        "height": 644,
        "content": "## 联系人"
      },
      "typeVersion": 1
    },
    {
      "id": "315c7d07-5fb7-4bd9-afe3-782b71372d1a",
      "name": "EVOLUTION - 获取文件",
      "type": "n8n-nodes-evolution-api.evolutionApi",
      "position": [
        1600,
        336
      ],
      "parameters": {
        "resource": "chat-api",
        "messageId": "={{ $('PARAMETERS').item.json.cd_mensagem_evolution }}",
        "operation": "get-media-base64",
        "instanceName": "={{ $('PARAMETERS').item.json.nm_instancia }}"
      },
      "credentials": {
        "evolutionApi": {
          "id": "KO9PVs8kvAt2hWOa",
          "name": "Evolution account 2"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "4c5150f3-3d1e-4f84-9841-589b59ab1416",
      "name": "获取对话",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -1104,
        352
      ],
      "parameters": {
        "sort": {
          "values": [
            {
              "column": "updated_at",
              "direction": "DESC"
            }
          ]
        },
        "limit": 1,
        "table": {
          "__rl": true,
          "mode": "list",
          "value": "conversations",
          "cachedResultName": "conversations"
        },
        "where": {
          "values": [
            {
              "value": "={{ $('PARAMETERS').item.json.cd_inbox_chatwoot }}",
              "column": "inbox_id"
            },
            {
              "value": "={{ $('CONTACT - ID').item.json.cd_contact }}",
              "column": "contact_id"
            },
            {
              "value": "0",
              "column": "status"
            },
            {
              "value": "={{ $('PARAMETERS').item.json.cd_account }}",
              "column": "account_id"
            }
          ]
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "options": {},
        "operation": "select"
      },
      "credentials": {
        "postgres": {
          "id": "WvZ0txGwx6WXRFZD",
          "name": "Postgres VectorDocs 46"
        }
      },
      "typeVersion": 2.6,
      "alwaysOutputData": true
    },
    {
      "id": "56d22f41-107e-4420-a3b6-48c28d5bcfa1",
      "name": "已发送文件?",
      "type": "n8n-nodes-base.if",
      "position": [
        1248,
        352
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "196a7287-0988-401c-914a-036bfbadb7b1",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $('CODE - MESSAGE OBJECT').item.json.arquivos.length }}",
              "rightValue": 0
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "d3d322fa-aa23-40cf-9e65-7a509ac4aacc",
      "name": "检查文件类型",
      "type": "n8n-nodes-base.switch",
      "position": [
        1888,
        336
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "ALLOWED",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "b024dbec-d707-4d56-93c3-80dcc443d0ee",
                    "operator": {
                      "type": "string",
                      "operation": "notEquals"
                    },
                    "leftValue": "={{ $json.data.mimetype }}",
                    "rightValue": "application/x-msdownload"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": ".MSI",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "38feeef2-acbf-4d4c-b390-83f1abecc482",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.data.mimetype }}",
                    "rightValue": "application/x-msdownload"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "0c1e8e1e-a007-4d6c-a3a4-be88d71e8ca8",
      "name": "发送 CHATWOOT 文件",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2656,
        320
      ],
      "parameters": {
        "url": "=https://chatwoot.unimedsulcapixaba.coop.br/api/v1/accounts/{{ $('PARAMETERS').item.json.cd_account }}/conversations/{{ $('CONVERSATION - ID').item.json.cd_conversation }}/messages",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "multipart-form-data",
        "authentication": "predefinedCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "attachments[]",
              "parameterType": "formBinaryData",
              "inputDataFieldName": "data"
            },
            {
              "name": "message_type",
              "value": "={{ ($('CODE - MESSAGE OBJECT').item.json.sn_Proprio_Numero ? \"outgoing\" : \"incoming\") }}"
            },
            {
              "name": "private",
              "value": "={{ ($('CODE - MESSAGE OBJECT').item.json.sn_Proprio_Numero ? \"true\" : \"false\") }}"
            }
          ]
        },
        "nodeCredentialType": "chatwootApi"
      },
      "credentials": {
        "chatwootApi": {
          "id": "WC3cIXGropqdKVdw",
          "name": "ChatWoot account"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "5af4ea4a-9450-4152-b25a-134f9feddcde",
      "name": "参数",
      "type": "n8n-nodes-base.set",
      "position": [
        -4912,
        192
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "62fbd7f8-2927-4823-b302-aab58af6e1e7",
              "name": "cd_account",
              "type": "number",
              "value": "={{ $json.cd_account }}"
            },
            {
              "id": "efa8bda6-4275-4860-92fc-639fd3ab151e",
              "name": "cd_inbox_chatwoot",
              "type": "number",
              "value": "={{ $json.cd_inbox_chatwoot }}"
            },
            {
              "id": "8f7e75a0-fa77-4066-90e4-eb4c0703b7ea",
              "name": "ds_msg",
              "type": "object",
              "value": "={{ $json.ds_msg }}"
            },
            {
              "id": "3ed7584a-86bd-464a-a002-76bd71c200df",
              "name": "cd_mensagem_evolution",
              "type": "string",
              "value": "={{ $json.ds_msg.data.key.id }}"
            },
            {
              "id": "24baeedd-73bc-4477-9b09-be7e0f9feff5",
              "name": "nm_instancia",
              "type": "string",
              "value": "={{ $json.ds_msg.instance }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "1d0a059a-53b0-458f-8518-3b40502cb1dd",
      "name": "代码 - 消息对象",
      "type": "n8n-nodes-base.code",
      "position": [
        -4592,
        192
      ],
      "parameters": {
        "jsCode": "return items.map(item => {\n  const message = $input.first().json.ds_msg.data.message;\n\n  const tp_Mensagem = $input.first().json.ds_msg.data.messageType;\n  \n  let objMensagem = {\n                      nm_Contato : \"\",\n                      nr_Chave_Contato : \"\",\n                      ds_Mensagem : \"\",\n                      sn_Proprio_Numero : false,   \n                      sn_Mensagem_Valida : false,\n                      arquivos : []\n                    }\n  \n  objMensagem.nr_Chave_Contato = $input.first().json.ds_msg.data.key.remoteJid.split('@')[0].split('-')[0]\n  objMensagem.sn_Proprio_Numero =  $input.first().json.ds_msg.data.key.fromMe;\n  \n  objMensagem.ds_Mensagem =  $input.first().json.ds_msg.data.message.conversation ? $input.first().json.ds_msg.data.message.conversation : $input.first().json.ds_msg.data.message?.reactionMessage?.text;\n  \n  objMensagem.sn_Mensagem_Valida = [\"conversation\", \"audioMessage\",\"documentMessage\",\"videoMessage\",\"imageMessage\",\"reactionMessage\",\"documentWithCaptionMessage\",\"stickerMessage\",\"contactMessage\"].includes(tp_Mensagem); \n\n  objMensagem.nm_Contato =  objMensagem.sn_Proprio_Numero ? objMensagem.nr_Chave_Contato : $input.first().json.ds_msg.data.pushName;\n\n\n  switch($input.first().json.ds_msg.data.messageType)\n  {\n      case 'audioMessage':\n      case 'imageMessage':\n      case 'videoMessage':\n      case 'documentMessage':\n      case 'reactionMessage':\n      case 'stickerMessage':\n        if (message[tp_Mensagem] && message[tp_Mensagem].url) \n        {   \n          objMensagem.ds_Mensagem = message[tp_Mensagem].caption;\n          objMensagem.arquivos.push({\n            nm_Arquivo: message[tp_Mensagem].fileName || \"arquivo\",\n            tp_Arquivo: message[tp_Mensagem].mimetype || \"application/octet-stream\",\n            ds_Base64: $input.first().json.ds_msg.data.message.base64\n          });\n        }\n      break;\n\n    case \"contactMessage\":\n      objMensagem.ds_Mensagem = Tratar_VCARD($input.first().json.ds_msg.data.message.contactMessage.vcard);\n      break;    \n\n    case 'documentWithCaptionMessage':\n          objMensagem.ds_Mensagem = $input.first().json.ds_msg.data.message.documentWithCaptionMessage.message.documentMessage.caption;\n      \n          objMensagem.arquivos.push({\n            nm_Arquivo: $input.first().json.ds_msg.data.message.documentWithCaptionMessage.message.documentMessage.fileName|| \"arquivo\",\n            tp_Arquivo: $input.first().json.ds_msg.data.message.documentWithCaptionMessage.message.documentMessage.mimetype || \"application/octet-stream\",\n            ds_Base64: $input.first().json.ds_msg.data.message.base64\n          });\n      break;     \n  }\n\n  //VERIFICA SE A MENSAGEM VEIO JUNTO COM UM RESPOSTA DE UMA MSG DO WHATSAPP\n  if($input.first().json.ds_msg.data.contextInfo?.quotedMessage != null)\n  {\n    const tipo = Object.keys($input.first().json.ds_msg.data.contextInfo?.quotedMessage)[0];\n    var ds_Texto_Citacao = \"\";\n      \n    switch(tipo)\n    {\n      case 'conversation':\n        ds_Texto_Citacao = $input.first().json.ds_msg.data.contextInfo.quotedMessage.conversation;\n        break;\n\n      case 'audioMessage':  \n      case 'stickerMessage':  \n      case 'documentMessage':\n      case 'audioMessage':\n      case 'imageMessage':        \n        //ds_Texto_Citacao = $input.first().json.ds_msg.data.contextInfo.quotedMessage.conversation;\n\n        //PARA FAZER IMAGEM E VÍDEO PRECISA DESCRIPTOGRAR O ARQUIVO USANDO A MEDIA KEY\n        break;\n    }\n  \n    if(ds_Texto_Citacao != \"\")\n    {\n      objMensagem.ds_Mensagem = \"> \"+ ds_Texto_Citacao + \"\\n\\n\" + objMensagem.ds_Mensagem;\n    }\n  }\n\n  return objMensagem;\n});\n\n\n\nfunction Tratar_VCARD(ds_Vcard) {\n  // Substitui os \"\\n\" por quebras de linha reais\n  const vcard = ds_Vcard.replace(/\\\\n/g, '\\n');\n\n  const aLinhas = vcard.split('\\n');\n\n  let nm_Nome = '';\n  let ds_Telefone = '';\n\n  for (const line of aLinhas) {\n    //Nome\n    if (line.startsWith('FN:')) {\n      nm_Nome = line.replace('FN:', '').trim();\n    }\n\n    // WhatsApp Business: telefone + waid\n    if (line.includes('waid=')) {\n        const waidMatch = line.match(/waid=(\\d+):/);\n        const formattedMatch = line.match(/waid=\\d+:(\\+?[0-9\\s\\-]+)/);\n\n        if (waidMatch) {\n           // output.waid = waidMatch[1];\n        }\n      \n        if (formattedMatch) {\n            const phone = formattedMatch[1].replace(/[^\\d+]/g, '');\n            if (phone) {\n                ds_Telefone = phone;\n            }\n        }\n    }\n\n    // WhatsApp normal: apenas TEL sem waid\n    if (line.startsWith('TEL') && !line.includes('waid=')) \n    {\n      const parts = line.split(':');\n      if (parts.length > 1)\n      {\n        const phone = parts[1].replace(/[^\\d+]/g, '');\n        if (phone) \n        {\n          ds_Telefone = phone;\n        }\n      }\n    }  \n  }\n\n  return `📱 Contato compartilhado:\\nNome: ${nm_Nome}\\nTelefone: ${ds_Telefone}`;\n}"
      },
      "typeVersion": 2
    },
    {
      "id": "286c1735-c445-49fd-b98b-24202b3d1e70",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3872,
        32
      ],
      "parameters": {
        "width": 326,
        "height": 340,
        "content": "## 消息类型"
      },
      "typeVersion": 1
    },
    {
      "id": "05354b1c-96c4-43a0-b618-c08c965f1122",
      "name": "电话号码是否有效?",
      "type": "n8n-nodes-base.if",
      "position": [
        -3760,
        176
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "c6900a9d-f55e-446c-8805-66a209796135",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $('CODE - MESSAGE OBJECT').item.json.nr_Chave_Contato.split('@')[0].substring(0,2) }}",
              "rightValue": "55"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "a634bd07-4044-4938-9719-47190558c2cd",
      "name": "消息已发送?",
      "type": "n8n-nodes-base.if",
      "position": [
        -3200,
        336
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "d9d19a36-2f9e-4f2d-a352-cb73deadee0f",
              "operator": {
                "type": "string",
                "operation": "empty",
                "singleValue": true
              },
              "leftValue": "={{ $json.cd_mensagem_evolution }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "ef54ed1b-488d-43c9-86a6-28da492cbac9",
      "name": "加载联系人",
      "type": "@devlikeapro/n8n-nodes-chatwoot.chatWoot",
      "position": [
        -2544,
        224
      ],
      "parameters": {
        "q": "=+{{ $('CODE - MESSAGE OBJECT').item.json.nr_Chave_Contato }}",
        "sort": "-phone_number",
        "resource": "Contacts",
        "operation": "Contact Search",
        "account_id": "={{ $('PARAMETERS').item.json.cd_account }}",
        "requestOptions": {}
      },
      "credentials": {
        "chatwootApi": {
          "id": "WC3cIXGropqdKVdw",
          "name": "ChatWoot account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "65c13eaf-574f-4199-95c2-028567b8ca45",
      "name": "Chatwoot 上是否有联系人?",
      "type": "n8n-nodes-base.if",
      "position": [
        -2208,
        224
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "03883245-e523-453b-8d4e-4e51b1f47b40",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $json.meta.count }}",
              "rightValue": 0
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "33c12ffa-b867-42d9-a838-5a7978e38fc7",
      "name": "创建联系人",
      "type": "@devlikeapro/n8n-nodes-chatwoot.chatWoot",
      "position": [
        -1984,
        480
      ],
      "parameters": {
        "name": "={{ $('CODE - MESSAGE OBJECT').item.json.nm_Contato }}",
        "email": "={{null}}",
        "avatar": "={{null}}",
        "inbox_id": "={{ $('PARAMETERS').item.json.cd_inbox }}",
        "resource": "Contacts",
        "operation": "Contact Create",
        "account_id": "={{ $('PARAMETERS').item.json.cd_account }}",
        "avatar_url": "={{null}}",
        "identifier": "={{null}}",
        "phone_number": "=+{{ $('CODE - MESSAGE OBJECT').item.json.nr_Chave_Contato }}",
        "requestOptions": {},
        "custom_attributes": "={\n    \"nm_spark\":\"{{ $('PESSOA').item.json.nm_spark }}\",\n\t\"nr_cpf\" : \"{{ $('PESSOA').item.json.nr_cpf }}\"\n}"
      },
      "credentials": {
        "chatwootApi": {
          "id": "WC3cIXGropqdKVdw",
          "name": "ChatWoot account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "a881c1dd-9a63-45c3-8a5e-c8c59b9adc93",
      "name": "现有联系人代码",
      "type": "n8n-nodes-base.set",
      "position": [
        -1712,
        208
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "fb15aadc-bfdb-481b-9140-c7a309517dc7",
              "name": "cd_contact",
              "type": "number",
              "value": "={{ $json.payload[0].id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "911b472c-7074-4693-bce7-d1c7285632a5",
      "name": "新联系人代码",
      "type": "n8n-nodes-base.set",
      "position": [
        -1712,
        480
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "fb15aadc-bfdb-481b-9140-c7a309517dc7",
              "name": "cd_contact",
              "type": "number",
              "value": "={{ $json.payload.contact.id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "5d460e6d-5db8-486f-94ec-ab2a9ffe4098",
      "name": "联系人 - ID",
      "type": "n8n-nodes-base.set",
      "position": [
        -1392,
        352
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "e6b929b9-b598-4232-9e18-07b6dd08e832",
              "name": "cd_contact",
              "type": "number",
              "value": "={{ $json.cd_contact }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "ad575c1c-afe3-422c-95c9-c35922402139",
      "name": "便签5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1136,
        32
      ],
      "parameters": {
        "color": 6,
        "width": 1368,
        "height": 644,
        "content": "## 对话"
      },
      "typeVersion": 1
    },
    {
      "id": "cb62aef9-d500-40f6-af75-ad10cd2851a3",
      "name": "现有对话代码",
      "type": "n8n-nodes-base.set",
      "position": [
        -304,
        224
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "e4cc3a18-b861-44f9-8926-66abf0d4b62e",
              "name": "cd_conversation",
              "type": "string",
              "value": "={{ $json.display_id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "988fe0ca-d96b-49e5-a149-c14d5582b54c",
      "name": "新对话代码",
      "type": "n8n-nodes-base.set",
      "position": [
        -304,
        464
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "e4cc3a18-b861-44f9-8926-66abf0d4b62e",
              "name": "cd_conversation",
              "type": "string",
              "value": "={{ $json.id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "09809c62-309e-4eb5-b586-3ff9df2c1431",
      "name": "Chatwoot 上是否有对话?",
      "type": "n8n-nodes-base.if",
      "position": [
        -800,
        352
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "c1e82142-3fcc-485e-82f1-afb85bd36d84",
              "operator": {
                "type": "number",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.id }}",
              "rightValue": 0
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "6cbf4e8a-d505-483b-ac68-f26343a8a108",
      "name": "对话 - ID",
      "type": "n8n-nodes-base.set",
      "position": [
        80,
        352
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "ed522e2d-7470-4211-8698-7e25edc19daf",
              "name": "cd_conversation",
              "type": "number",
              "value": "={{ $json.cd_conversation }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "48330528-d85b-4238-b5bc-f9a9f1ead69c",
      "name": "是否是连接到 EVOLUTION 的号码本身发送的消息?",
      "type": "n8n-nodes-base.if",
      "position": [
        448,
        352
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "8431382d-8c91-44d1-a66f-029dc819d0c3",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $('CODE - MESSAGE OBJECT').item.json.sn_Proprio_Numero }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "1669e5b7-230a-4bcc-9e02-ae5b86af45ea",
      "name": "发送外发消息",
      "type": "@devlikeapro/n8n-nodes-chatwoot.chatWoot",
      "position": [
        816,
        144
      ],
      "parameters": {
        "content": "={{ $('CODE - MESSAGE OBJECT').item.json.ds_Mensagem }}",
        "resource": "Messages",
        "operation": "Create A New Message In A Conversation",
        "account_id": "={{ $('PARAMETERS').item.json.cd_account }}",
        "content_type": "=text",
        "requestOptions": {},
        "conversation_id": "={{ $('CONVERSATION - ID').item.json.cd_conversation }}",
        "template_params": "{}",
        "content_attributes": "={\n}"
      },
      "credentials": {
        "chatwootApi": {
          "id": "WC3cIXGropqdKVdw",
          "name": "ChatWoot account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "482eabea-1392-4f9b-b99d-2995a55300aa",
      "name": "发送接收消息",
      "type": "@devlikeapro/n8n-nodes-chatwoot.chatWoot",
      "position": [
        816,
        592
      ],
      "parameters": {
        "content": "={{ $('CODE - MESSAGE OBJECT').item.json.ds_Mensagem }}",
        "private": false,
        "resource": "Messages",
        "operation": "Create A New Message In A Conversation",
        "account_id": "={{ $('PARAMETERS').item.json.cd_account.toString() }}",
        "content_type": "=text",
        "message_type": "incoming",
        "requestOptions": {},
        "conversation_id": "={{ $('CONVERSATION - ID').item.json.cd_conversation }}",
        "template_params": "{}",
        "content_attributes": "={\n   \"cd_mensagem_evolution\" : \"{{ $('PARAMETERS').item.json.cd_mensagem_evolution }}\"\n}"
      },
      "credentials": {
        "chatwootApi": {
          "id": "WC3cIXGropqdKVdw",
          "name": "ChatWoot account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "e2844032-7641-44f7-b54c-8cac7c1ec73b",
      "name": "发送外发消息扩展名不允许",
      "type": "@devlikeapro/n8n-nodes-chatwoot.chatWoot",
      "position": [
        2256,
        672
      ],
      "parameters": {
        "content": "=🚨 The uploaded file has an unauthorized extension",
        "private": false,
        "resource": "Messages",
        "operation": "Create A New Message In A Conversation",
        "account_id": "={{ $('PARAMETERS').item.json.cd_account }}",
        "content_type": "=text",
        "requestOptions": {},
        "conversation_id": "={{ $('CONVERSATION - ID').item.json.cd_conversation }}",
        "template_params": "{}"
      },
      "credentials": {
        "chatwootApi": {
          "id": "WC3cIXGropqdKVdw",
          "name": "ChatWoot account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "cf0b5b1c-7eba-453a-ba15-94c20e15d32a",
      "name": "创建对话",
      "type": "@devlikeapro/n8n-nodes-chatwoot.chatWoot",
      "position": [
        -512,
        464
      ],
      "parameters": {
        "inbox_id": "={{ $('PARAMETERS').item.json.cd_inbox_chatwoot }}",
        "resource": "Conversations",
        "operation": "New Conversation",
        "source_id": "={{ null }}",
        "account_id": "={{ $('PARAMETERS').item.json.cd_account }}",
        "contact_id": "={{ $('CONTACT - ID').item.json.cd_contact }}",
        "requestOptions": {}
      },
      "credentials": {
        "chatwootApi": {
          "id": "WC3cIXGropqdKVdw",
          "name": "ChatWoot account"
        }
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "9a9128de-5efe-4667-b33b-8ba0658f3f6f",
  "connections": {
    "Wait": {
      "main": [
        [
          {
            "node": "PARAMETERS",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "BASE64": {
      "main": [
        [
          {
            "node": "Convert to File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "PARAMETERS": {
      "main": [
        [
          {
            "node": "CODE - MESSAGE OBJECT",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SENT FILE?": {
      "main": [
        [
          {
            "node": "EVOLUTION - GET FILE",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CONTACT - ID": {
      "main": [
        [
          {
            "node": "Get Conversations",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "LOAD CONTACT": {
      "main": [
        [
          {
            "node": "IS THERE CONTACT ON CHATWOOT?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "MESSAGE SENT?": {
      "main": [
        [
          {
            "node": "REDIS - EVOLUTION MSG - SET",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CREATE CONTACT": {
      "main": [
        [
          {
            "node": "NEW CONTACT CODE",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CHECK FILE TYPE": {
      "main": [
        [
          {
            "node": "BASE64",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "SEND OUTGOING MESSAGE EXTENSION NOT ALLOWED",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to File": {
      "main": [
        [
          {
            "node": "SEND CHATWOOT FILE",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "NEW CONTACT CODE": {
      "main": [
        [
          {
            "node": "CONTACT - ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CONVERSATION - ID": {
      "main": [
        [
          {
            "node": "WAS IT THE NUMBER ITSELF THAT IS CONNECTED TO EVOLUTION THAT SENT THE MESSAGE?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Conversations": {
      "main": [
        [
          {
            "node": "IS THERE CONVERSATION ON CHATWOOT?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SEND CHATWOOT FILE": {
      "main": [
        []
      ]
    },
    "CREATE CONVERSATION": {
      "main": [
        [
          {
            "node": "NEW CONVERSATION CODE",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "EVOLUTION - GET FILE": {
      "main": [
        [
          {
            "node": "CHECK FILE TYPE",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CODE - MESSAGE OBJECT": {
      "main": [
        [
          {
            "node": "TIPO MENSAGEM VÁLIDO?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "EXISTING CONTACT CODE": {
      "main": [
        [
          {
            "node": "CONTACT - ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "NEW CONVERSATION CODE": {
      "main": [
        [
          {
            "node": "CONVERSATION - ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SEND INCOMING MESSAGE": {
      "main": [
        [
          {
            "node": "SENT FILE?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SEND OUTGOING MESSAGE": {
      "main": [
        [
          {
            "node": "SENT FILE?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "TIPO MENSAGEM VÁLIDO?": {
      "main": [
        [
          {
            "node": "IS THE PHONE NUMBER VALID?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "EXISTING CONVERSATION CODE": {
      "main": [
        [
          {
            "node": "CONVERSATION - ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IS THE PHONE NUMBER VALID?": {
      "main": [
        [
          {
            "node": "REDIS - EVOLUTION MSG - GET",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "REDIS - EVOLUTION MSG - GET": {
      "main": [
        [
          {
            "node": "MESSAGE SENT?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "REDIS - EVOLUTION MSG - SET": {
      "main": [
        [
          {
            "node": "LOAD CONTACT",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IS THERE CONTACT ON CHATWOOT?": {
      "main": [
        [
          {
            "node": "EXISTING CONTACT CODE",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "CREATE CONTACT",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IS THERE CONVERSATION ON CHATWOOT?": {
      "main": [
        [
          {
            "node": "EXISTING CONVERSATION CODE",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "CREATE CONVERSATION",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WAS IT THE NUMBER ITSELF THAT IS CONNECTED TO EVOLUTION THAT SENT THE MESSAGE?": {
      "main": [
        [
          {
            "node": "SEND OUTGOING MESSAGE",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "SEND INCOMING MESSAGE",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 客服机器人

需要付费吗?

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

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

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

作者
Thiago Vazzoler Loureiro

Thiago Vazzoler Loureiro

@thiagovazzoler

Building Custom Automations with n8n | Node.js Developer | Integration Specialist | Open Source Contributor If you need help with n8n workflows, API integrations, or custom nodes, feel free to connect on LinkedIn: http://linkedin.com/in/thiago-vazzoler-loureiro-24056227

外部链接
在 n8n.io 查看

分享此工作流