8
n8n 中文网amn8n.com

HubSpot 交易赢单的智能 CSM 分配与 AI 欢迎邮件(集成 Gmail)

高级

这是一个CRM, Multimodal AI领域的自动化工作流,包含 22 个节点。主要使用 If, Set, Code, Gmail, Hubspot 等节点。 HubSpot 交易赢单的智能 CSM 分配与 AI 欢迎邮件(集成 Gmail)

前置要求
  • Google 账号和 Gmail API 凭证
  • HubSpot API Key
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "nodes": [
    {
      "id": "2bdfeaf7-f4db-446d-84bc-68e914138e28",
      "name": "结构化输出解析器",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -112,
        192
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"subject\": {\n      \"type\": \"string\",\n      \"description\": \"The subject line for the email\"\n    },\n    \"body\": {\n      \"type\": \"string\",\n      \"description\": \"The full, complete body of the email, formatted in Markdown\"\n    }\n  },\n  \"required\": [\"subject\", \"body\"]\n}"
      },
      "typeVersion": 1.2
    },
    {
      "id": "46c35571-3823-4cb9-8e07-df85c8fd6a2f",
      "name": "便签7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2368,
        240
      ],
      "parameters": {
        "color": 6,
        "width": 368,
        "height": 212,
        "content": "## 联系我"
      },
      "typeVersion": 1
    },
    {
      "id": "3d3a2b5f-c5cd-4fdc-bc1d-55956b6b7809",
      "name": "如果交易已赢得",
      "type": "n8n-nodes-base.if",
      "position": [
        -1824,
        -32
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "b70f4699-008f-4924-8e69-af4fa69422a5",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $(\"Trigger: Deal Is 'Closed Won'\").item.json.body[0].propertyValue }}",
              "rightValue": "contact.creation"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "3b7f2eb6-c57f-454e-8bca-dece1d7ac508",
      "name": "配置模板变量",
      "type": "n8n-nodes-base.set",
      "position": [
        -2048,
        -32
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "11a8b9e9-a7ed-454a-9aef-a9137c0e17ea",
              "name": "company_name",
              "type": "string",
              "value": "Your Company Name"
            },
            {
              "id": "f2dcfe2e-3145-4a30-9731-0a8d02c7aa9a",
              "name": "sender_name",
              "type": "string",
              "value": "Your Sender Name"
            },
            {
              "id": "18b5c0bd-4e75-4b98-92fc-5fca90a8b680",
              "name": "sender_email",
              "type": "string",
              "value": "your-email@example.com"
            }
          ]
        }
      },
      "notesInFlow": true,
      "typeVersion": 3.4
    },
    {
      "id": "e26d9e1d-de10-445d-bbc7-aa20753c3bbb",
      "name": "如果角色是'冠军'",
      "type": "n8n-nodes-base.if",
      "position": [
        -480,
        -32
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "90d9c369-80df-4938-adac-af3b452f97ca",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.properties.hs_buying_role.value }}",
              "rightValue": "CHAMPION"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "e22c6e48-5899-4f13-b857-65d499e296ca",
      "name": "HubSpot:获取交易详情",
      "type": "n8n-nodes-base.hubspot",
      "position": [
        -1152,
        -32
      ],
      "parameters": {
        "dealId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $(\"Trigger: Deal Is 'Closed Won'\").item.json.body[0].objectId }}"
        },
        "filters": {},
        "resource": "deal",
        "operation": "get",
        "authentication": "oAuth2"
      },
      "typeVersion": 2.2
    },
    {
      "id": "8f569481-1ee0-4441-8269-a0630cb116d3",
      "name": "拆分联系人ID",
      "type": "n8n-nodes-base.code",
      "position": [
        -928,
        -32
      ],
      "parameters": {
        "jsCode": "// Get the list of contact IDs\nconst vids = $('HubSpot: Get Deal Details').first().json.associations.associatedVids;\n\n// Make sure it's always a list (even if there's only one)\nconst vidsList = [].concat(vids);\n\n// Return each ID as a separate item for the next node to process\nreturn vidsList.map(id => {\n  return {\n    json: {\n      contactId: id\n    }\n  };\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "7ccef67d-88ba-4ee2-88b8-ea0888b57319",
      "name": "HubSpot:获取联系人详情",
      "type": "n8n-nodes-base.hubspot",
      "position": [
        -704,
        -32
      ],
      "parameters": {
        "contactId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.contactId }}"
        },
        "operation": "get",
        "authentication": "oAuth2",
        "additionalFields": {
          "propertiesCollection": {
            "propertiesValues": {
              "properties": [
                "hs_buying_role"
              ],
              "propertyMode": "valueOnly"
            }
          }
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "8f0f446d-2705-4e0b-a982-76a04c9010ca",
      "name": "AI:撰写欢迎邮件",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -256,
        -32
      ],
      "parameters": {
        "text": "=Your task is to write a warm, personalized welcome email to a new customer.\n\n## Content to Include\n- Congratulate them on their purchase.\n- Welcome them to the [Your Company Name] family.\n- Let them know that their new Customer Success Manager will be in touch shortly to schedule a kickoff call.\n- Provide a link to a \"Getting Started\" video: [Link to Your Video]\n- Provide a link to a \"Help Documentation\" page: [Link to Your Help Doc]\n\n## Rules\n- Be professional, enthusiastic, and welcoming.\n- You are writing on behalf of the sender.\n\n## Use the variables below\nSender's name:  {{ $('Configure Template Variables').item.json.sender_name }}\nSender's email: {{ $('Configure Template Variables').item.json.sender_email }}\nSender's company name: {{ $('Configure Template Variables').item.json.company_name }}\nRecipient's first name: {{ $('HubSpot: Get Contact Details').item.json.properties.firstname.value }}\nRecipient's last name: {{ $('HubSpot: Get Contact Details').item.json.properties.lastname.value }}\nRecipient's email: {{ $('HubSpot: Get Contact Details').item.json.properties.email.value }}",
        "options": {
          "systemMessage": "=# Overview\nYou are a professional Customer Success Manager.\n"
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.9
    },
    {
      "id": "c3795f85-b2cf-4baf-86f5-7919234d1cad",
      "name": "AI模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -256,
        192
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "7262a3e6-dae7-4011-ab90-54897deb9f19",
      "name": "工具:Markdown转HTML",
      "type": "n8n-nodes-base.markdown",
      "position": [
        96,
        -32
      ],
      "parameters": {
        "mode": "markdownToHtml",
        "options": {},
        "markdown": "={{ $json.output.body }}"
      },
      "typeVersion": 1
    },
    {
      "id": "366e7c5d-f6df-4896-bd32-ae1fba5b4f49",
      "name": "Gmail:发送欢迎邮件",
      "type": "n8n-nodes-base.gmail",
      "position": [
        320,
        -32
      ],
      "webhookId": "600dd71c-272e-4300-8f5a-7e5bbf7eb9fe",
      "parameters": {
        "sendTo": "={{ $('HubSpot: Get Contact Details').item.json.properties.email.value }}",
        "message": "={{ $json.data }}",
        "options": {},
        "subject": "={{ $json.output.subject }}"
      },
      "typeVersion": 2.1
    },
    {
      "id": "1033acf3-11d8-4ea2-89f2-13ceda2e9f8d",
      "name": "HubSpot:分配联系人负责人",
      "type": "n8n-nodes-base.hubspot",
      "position": [
        544,
        -32
      ],
      "parameters": {
        "email": "={{ $('HubSpot: Get Contact Details').item.json.properties.email.value }}",
        "options": {},
        "authentication": "oAuth2",
        "additionalFields": {
          "contactOwner": "={{ $('Find Least Busy CSM').item.json.csm_id }}"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "cb68f201-669e-4f65-a065-93e1e1586fd5",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2368,
        -1104
      ],
      "parameters": {
        "width": 768,
        "height": 656,
        "content": "# 从HubSpot入职流程自动化CSM分配和邮件发送"
      },
      "typeVersion": 1
    },
    {
      "id": "c1c64eb1-7108-4579-8b77-3cadb79fab4d",
      "name": "便签10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2464,
        -352
      ],
      "parameters": {
        "color": 7,
        "width": 352,
        "height": 480,
        "content": "此节点是工作流的**实时**触发器。"
      },
      "typeVersion": 1
    },
    {
      "id": "d1cc6510-b720-4076-910a-b528a72b6f62",
      "name": "触发器:交易为'已关闭赢得'",
      "type": "n8n-nodes-base.hubspotTrigger",
      "position": [
        -2272,
        -32
      ],
      "webhookId": "b7a996ff-1c3b-417f-be7f-190ec04405b9",
      "parameters": {
        "eventsUi": {
          "eventValues": [
            {
              "name": "deal.propertyChange",
              "property": "=hs_is_closed_won"
            }
          ]
        },
        "additionalFields": {
          "maxConcurrentRequests": 5
        }
      },
      "typeVersion": 1
    },
    {
      "id": "04545ef6-cae4-4c4e-bf96-ea4ac26be3ad",
      "name": "便签9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -304,
        -352
      ],
      "parameters": {
        "color": 7,
        "width": 336,
        "height": 672,
        "content": "### AI邮件撰写器"
      },
      "typeVersion": 1
    },
    {
      "id": "7d1fd6d1-7ded-4760-8158-55f9e9f4d209",
      "name": "获取CSM列表",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        -1600,
        -32
      ],
      "parameters": {
        "operation": "get",
        "returnAll": true,
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": ""
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f5774385-f71b-4b5c-bf67-54d8f184af06",
      "name": "查找最不繁忙的CSM",
      "type": "n8n-nodes-base.code",
      "position": [
        -1376,
        -32
      ],
      "parameters": {
        "jsCode": "// Get the list of CSMs from the previous node\nconst csmList = $input.all();\n\n// Check if the table is empty\nif (csmList.length === 0) {\n  throw new Error(\"CSM assignment table is empty. Please add CSMs to the Data Table.\");\n}\n\n// Sort the list to find the CSM with the lowest deal_count\n// The input item looks like: { json: { csm_id: '123', deal_count: 0 }, row_id: 'abc' }\nconst sortedList = csmList.sort((a, b) => {\n  return a.json.deal_count - b.json.deal_count;\n});\n\n// The least busy CSM is the first one in the sorted list\nconst leastBusyCsm = sortedList[0];\n\n// Return the data needed for the next nodes\nreturn {\n  csm_id: leastBusyCsm.json.csm_id,\n  row_id_to_update: leastBusyCsm.json.id,\n  current_count: leastBusyCsm.json.deal_count\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "46936c4a-7dcf-4cc0-bce9-6f06d230ee92",
      "name": "增加CSM交易计数",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        768,
        -32
      ],
      "parameters": {
        "columns": {
          "value": {},
          "schema": [],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "filters": {
          "conditions": [
            {
              "keyValue": "={{ $('Find Least Busy CSM').item.json.row_id_to_update }}"
            }
          ]
        },
        "options": {},
        "operation": "update",
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": ""
        }
      },
      "typeVersion": 1
    },
    {
      "id": "426da06b-eb9f-4a6d-8b13-a2cffd6dd6ba",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1664,
        -352
      ],
      "parameters": {
        "color": 7,
        "width": 432,
        "height": 480,
        "content": "### 最不繁忙CSM分配"
      },
      "typeVersion": 1
    },
    {
      "id": "e9606b09-3cbc-4f51-a1e9-23ba1a617aa4",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        704,
        -352
      ],
      "parameters": {
        "color": 7,
        "width": 544,
        "height": 512,
        "content": "此节点更新CSM的交易计数。"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "AI Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI: Write Welcome Email",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Get CSM List": {
      "main": [
        [
          {
            "node": "Find Least Busy CSM",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Deal Is Won": {
      "main": [
        [
          {
            "node": "Get CSM List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Contact IDs": {
      "main": [
        [
          {
            "node": "HubSpot: Get Contact Details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find Least Busy CSM": {
      "main": [
        [
          {
            "node": "HubSpot: Get Deal Details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Role is 'Champion'": {
      "main": [
        [
          {
            "node": "AI: Write Welcome Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Util: Markdown to HTML": {
      "main": [
        [
          {
            "node": "Gmail: Send Welcome Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI: Write Welcome Email": {
      "main": [
        [
          {
            "node": "Util: Markdown to HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "AI: Write Welcome Email",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Gmail: Send Welcome Email": {
      "main": [
        [
          {
            "node": "HubSpot: Assign Contact Owner",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HubSpot: Get Deal Details": {
      "main": [
        [
          {
            "node": "Split Contact IDs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Configure Template Variables": {
      "main": [
        [
          {
            "node": "If Deal Is Won",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HubSpot: Get Contact Details": {
      "main": [
        [
          {
            "node": "If Role is 'Champion'",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HubSpot: Assign Contact Owner": {
      "main": [
        [
          {
            "node": "Increment CSM Deal Count",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Trigger: Deal Is 'Closed Won'": {
      "main": [
        [
          {
            "node": "Configure Template Variables",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 客户关系管理, 多模态 AI

需要付费吗?

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

工作流信息
难度等级
高级
节点数量22
分类2
节点类型12
难度说明

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

作者
PollupAI

PollupAI

@zeerobug

We create bespoke AI solutions, automations and agents that help your business as it scales.

外部链接
在 n8n.io 查看

分享此工作流