{
  "name": "Smart CSM assignment & AI welcome emails for HubSpot deal wins with Gmail",
  "nodes": [
    {
      "id": "2bdfeaf7-f4db-446d-84bc-68e914138e28",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -112,
        192
      ]
    },
    {
      "id": "46c35571-3823-4cb9-8e07-df85c8fd6a2f",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2368,
        240
      ],
      "parameters": {
        "width": 368,
        "height": 212,
        "content": "## Contact me\n- If you need any modification to this workflow\n- if you need some help with this workflow\n- Or if you need any workflow in n8n, Make, or Langchain / Langgraph\n\nWrite to me: [thomas@poll"
      }
    },
    {
      "id": "3d3a2b5f-c5cd-4fdc-bc1d-55956b6b7809",
      "name": "If Deal Is Won",
      "type": "n8n-nodes-base.if",
      "position": [
        -1824,
        -32
      ]
    },
    {
      "id": "3b7f2eb6-c57f-454e-8bca-dece1d7ac508",
      "name": "Configure Template Variables",
      "type": "n8n-nodes-base.set",
      "position": [
        -2048,
        -32
      ]
    },
    {
      "id": "e26d9e1d-de10-445d-bbc7-aa20753c3bbb",
      "name": "If Role is 'Champion'",
      "type": "n8n-nodes-base.if",
      "position": [
        -480,
        -32
      ]
    },
    {
      "id": "e22c6e48-5899-4f13-b857-65d499e296ca",
      "name": "HubSpot: Get Deal Details",
      "type": "n8n-nodes-base.hubspot",
      "position": [
        -1152,
        -32
      ]
    },
    {
      "id": "8f569481-1ee0-4441-8269-a0630cb116d3",
      "name": "Split Contact IDs",
      "type": "n8n-nodes-base.code",
      "position": [
        -928,
        -32
      ]
    },
    {
      "id": "7ccef67d-88ba-4ee2-88b8-ea0888b57319",
      "name": "HubSpot: Get Contact Details",
      "type": "n8n-nodes-base.hubspot",
      "position": [
        -704,
        -32
      ]
    },
    {
      "id": "8f0f446d-2705-4e0b-a982-76a04c9010ca",
      "name": "AI: Write Welcome Email",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -256,
        -32
      ]
    },
    {
      "id": "c3795f85-b2cf-4baf-86f5-7919234d1cad",
      "name": "AI Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -256,
        192
      ]
    },
    {
      "id": "7262a3e6-dae7-4011-ab90-54897deb9f19",
      "name": "Util: Markdown to HTML",
      "type": "n8n-nodes-base.markdown",
      "position": [
        96,
        -32
      ]
    },
    {
      "id": "366e7c5d-f6df-4896-bd32-ae1fba5b4f49",
      "name": "Gmail: Send Welcome Email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        320,
        -32
      ]
    },
    {
      "id": "1033acf3-11d8-4ea2-89f2-13ceda2e9f8d",
      "name": "HubSpot: Assign Contact Owner",
      "type": "n8n-nodes-base.hubspot",
      "position": [
        544,
        -32
      ]
    },
    {
      "id": "cb68f201-669e-4f65-a065-93e1e1586fd5",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2368,
        -1104
      ],
      "parameters": {
        "width": 768,
        "height": 656,
        "content": "# Automate a CSM assignment and email send from a HubSpot onboarding\n\nThis workflow triggers when a HubSpot deal is marked `Closed Won`, assigns the **least busy CSM based on a Data Table**, and sends"
      }
    },
    {
      "id": "c1c64eb1-7108-4579-8b77-3cadb79fab4d",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2464,
        -352
      ],
      "parameters": {
        "width": 352,
        "height": 480,
        "content": "This node is the **live** trigger for the workflow.\n\n* **Action:** It watches for changes to the \"Is closed won\" property on a HubSpot deal.\n* **Heads Up:** This trigger will fire when the property ch"
      }
    },
    {
      "id": "d1cc6510-b720-4076-910a-b528a72b6f62",
      "name": "Trigger: Deal Is 'Closed Won'",
      "type": "n8n-nodes-base.hubspotTrigger",
      "position": [
        -2272,
        -32
      ]
    },
    {
      "id": "04545ef6-cae4-4c4e-bf96-ea4ac26be3ad",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -304,
        -352
      ],
      "parameters": {
        "width": 336,
        "height": 672,
        "content": "### AI Email Writer\n* Uses AI to write a personalized Welcome Email.\n* Requires OpenAI credentials.\n* You can customize the prompt in the `AI: Write Welcome Email` node."
      }
    },
    {
      "id": "7d1fd6d1-7ded-4760-8158-55f9e9f4d209",
      "name": "Get CSM List",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        -1600,
        -32
      ]
    },
    {
      "id": "f5774385-f71b-4b5c-bf67-54d8f184af06",
      "name": "Find Least Busy CSM",
      "type": "n8n-nodes-base.code",
      "position": [
        -1376,
        -32
      ]
    },
    {
      "id": "46936c4a-7dcf-4cc0-bce9-6f06d230ee92",
      "name": "Increment CSM Deal Count",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        768,
        -32
      ]
    },
    {
      "id": "426da06b-eb9f-4a6d-8b13-a2cffd6dd6ba",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1664,
        -352
      ],
      "parameters": {
        "width": 432,
        "height": 480,
        "content": "### Least-Busy CSM Assignment\n\nThese nodes find the CSM with the lowest `deal_count` from the `csm_assignments` Data Table, assign them the new deal, and then add 1 to their count to keep the table in"
      }
    },
    {
      "id": "e9606b09-3cbc-4f51-a1e9-23ba1a617aa4",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        704,
        -352
      ],
      "parameters": {
        "width": 544,
        "height": 512,
        "content": "This node updates the CSM's deal count.\n\n**After you select your `csm_assignments` table:**\n1.  Go to the \"Fields to Update\" section.\n2.  Click **Add Field**.\n3.  **Field:** Select `deal_count`.\n4.  *"
      }
    }
  ],
  "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
          }
        ]
      ]
    }
  }
}