{
  "name": "Follow up on open HubSpot deals when companies revisit your website with Webmetic, OpenAI and Teams",
  "nodes": [
    {
      "id": "826da12e-fcae-5715-89b9-82524c24265b",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -560,
        0
      ],
      "parameters": {
        "content": "## Know when an open deal comes back\n\nWhen a company with an open deal comes back to your website, its account manager should know. Every hour, this workflow finds the companies that visited your website more than once in the last 7 days, checks HubSpot for an open deal and gives the deal owner a follow-up task with a suggestion from OpenAI. Built with HubSpot and Teams, it works with any CRM and chat tool.\n\n### Who's it for\nAccount managers and sales teams who want to follow up the moment interest returns.\n\n### How it works\n1. **Get returning visits** returns the companies with at least two visits in the last 7 days, once per day with new visits.\n2. **Find company in HubSpot** looks the company up by its website domain. Companies without an open deal are skipped.\n3. **Find open deal** picks the company's most recently updated open deal.\n4. OpenAI suggests the follow-up from the deal and the pages they read.\n5. The deal owner gets a HubSpot task with the suggestion, Teams gets an alert.\n\n### Setup\n1. Copy the **Visitor Intelligence** API key from [Webmetic API keys](https://app.webmetic.de/?menu=api_details).\n2. Fill in **Settings**: domain, your company, what you sell and language.\n3. Connect OpenAI, HubSpot (private app token, also for the two HTTP steps) and Teams. About 10 minutes.\n\n### Requirements\n- A Webmetic account. This workflow uses no credits.\n- The Webmetic node, verified by n8n, on n8n Cloud or self-hosted.\n- OpenAI, a CRM with deals and a chat tool.\n\n### Customize\nChange the time window in **Get returning visits**, or swap Teams for Slack or e-mail.\n\n[More Webmetic workflows](https://webmetic.de/n8n)",
        "height": 940,
        "width": 500
      }
    },
    {
      "id": "e91a95f2-5e7a-5f60-8153-5be6168b753b",
      "name": "Section: returning companies",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -20,
        100
      ],
      "parameters": {
        "content": "## 1. Companies coming back\nTwo or more visits in 7 days, once per day",
        "height": 340,
        "width": 840,
        "color": 7
      }
    },
    {
      "id": "c56e906c-a21e-5e68-a90e-54528ade83de",
      "name": "Section: open deal",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        860,
        100
      ],
      "parameters": {
        "content": "## 2. Open deal in HubSpot?\nOnly companies with an open deal go on",
        "height": 340,
        "width": 620,
        "color": 7
      }
    },
    {
      "id": "24ecb6f3-22dc-5fbd-a42d-8cd1814d2278",
      "name": "Section: follow-up",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1500,
        100
      ],
      "parameters": {
        "content": "## 3. Follow-up for the deal owner\nAI suggestion, task in the deal, Teams alert",
        "height": 560,
        "width": 820,
        "color": 7
      }
    },
    {
      "id": "c51a2379-5f5a-5b40-9be0-c4ee5c9ae69e",
      "name": "Every hour",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.3,
      "position": [
        0,
        240
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 1
            }
          ]
        }
      }
    },
    {
      "id": "bb0d68c5-fcac-53fe-8754-2f55aa80c7ce",
      "name": "Settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        240
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "52c59728-57a9-5032-960b-c2cc6986a0f3",
              "name": "domain",
              "value": "example.com",
              "type": "string"
            },
            {
              "id": "ea2b41c6-cb94-5768-bd2f-38583200421a",
              "name": "yourCompany",
              "value": "Acme GmbH",
              "type": "string"
            },
            {
              "id": "8f0b2e79-6609-5969-ad18-540c0600f815",
              "name": "whatYouSell",
              "value": "One sentence about what you sell and for whom",
              "type": "string"
            },
            {
              "id": "d9d459c4-03a6-5227-abde-19ac98f2ebb9",
              "name": "language",
              "value": "English",
              "type": "string"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "8cdbc0cf-d553-5f73-aee4-cb10d95f9392",
      "name": "Get returning visits",
      "type": "n8n-nodes-webmetic.webmetic",
      "typeVersion": 2,
      "position": [
        440,
        240
      ],
      "parameters": {
        "resource": "returningVisits",
        "operation": "get",
        "domain": "={{ $json.domain }}",
        "additionalFields": {
          "from_date": "-7 days",
          "to_date": "now"
        }
      }
    },
    {
      "id": "cf432e23-361c-5188-aa34-c729749b3816",
      "name": "Once per company per day",
      "type": "n8n-nodes-base.removeDuplicates",
      "typeVersion": 2,
      "position": [
        660,
        240
      ],
      "parameters": {
        "operation": "removeItemsSeenInPreviousExecutions",
        "dedupeValue": "={{ $json.company_id }}-{{ $json.sessions.map(s => s.timestamp).sort().at(-1).slice(0, 10) }}",
        "options": {}
      }
    },
    {
      "id": "390edee6-0326-5485-a8b7-0b05475ad70a",
      "name": "Find company in HubSpot",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        920,
        240
      ],
      "parameters": {
        "method": "POST",
        "url": "https://api.hubapi.com/crm/v3/objects/companies/search",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "hubspotAppToken",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"filterGroups\": [{ \"filters\": [{ \"propertyName\": \"domain\", \"operator\": \"EQ\", \"value\": \"{{ $('Get returning visits').item.json.company_url }}\" }] }],\n  \"properties\": [\"name\", \"hs_num_open_deals\"],\n  \"limit\": 1\n}",
        "options": {}
      }
    },
    {
      "id": "250a79da-24c7-5504-ba06-e77761c982d0",
      "name": "Open deal in HubSpot?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        1120,
        240
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "8052bc1f-4ef3-52b2-94b3-1648f5c0a981",
              "leftValue": "={{ Number($json.results[0]?.properties?.hs_num_open_deals || 0) }}",
              "rightValue": 0,
              "operator": {
                "type": "number",
                "operation": "gt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "d7bc6565-8520-5365-a814-21ff95057601",
      "name": "Find open deal",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        1320,
        240
      ],
      "parameters": {
        "method": "POST",
        "url": "https://api.hubapi.com/crm/v3/objects/deals/search",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "hubspotAppToken",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"filterGroups\": [{ \"filters\": [\n    { \"propertyName\": \"associations.company\", \"operator\": \"EQ\", \"value\": \"{{ $json.results[0].id }}\" },\n    { \"propertyName\": \"hs_is_closed\", \"operator\": \"EQ\", \"value\": \"false\" }\n  ] }],\n  \"properties\": [\"dealname\", \"dealstage\", \"amount\", \"hubspot_owner_id\"],\n  \"sorts\": [{ \"propertyName\": \"hs_lastmodifieddate\", \"direction\": \"DESCENDING\" }],\n  \"limit\": 1\n}",
        "options": {}
      }
    },
    {
      "id": "25af8107-c3b0-5226-89d1-2e9e85176967",
      "name": "Suggest next step",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        1580,
        240
      ],
      "parameters": {
        "promptType": "define",
        "text": "=You are an experienced B2B account manager. A company with an open deal is back on our website. Suggest the best follow-up for the deal owner.\n\nOUR COMPANY\n- Name: {{ $('Settings').item.json.yourCompany }}\n- What we sell: {{ $('Settings').item.json.whatYouSell }}\n\nTHE DEAL\n- Deal: {{ $json.results[0].properties.dealname }}\n- Stage: {{ $json.results[0].properties.dealstage }}\n- Amount: {{ $json.results[0].properties.amount || 'unknown' }}\n\nTHE COMPANY\n- Company: {{ $('Get returning visits').item.json.company_name }}\n- Visits in the last 7 days: {{ $('Get returning visits').item.json.sessions_total }}\n- Pages read: {{ ($('Get returning visits').item.json.sessions || []).flatMap(s => s.user_data || []).map(p => p.document_title + ' (' + Math.round(p.time_spent || 0) + 's)').join(' -> ') || 'unknown' }}\n\nWRITE\n1. What their reading suggests (2 sentences)\n2. The follow-up: channel, timing and the first sentence to say or write\n3. One piece of content worth sending\n\nRULES: Write in {{ $('Settings').item.json.language }}. Maximum 150 words. Never say that you saw their website visit. Output simple HTML using only h3, p, ul and li.",
        "options": {}
      }
    },
    {
      "id": "6e91e207-c315-58b5-9e21-c8d023e99c49",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        1600,
        460
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5-mini"
        },
        "options": {}
      }
    },
    {
      "id": "fc82e72f-3982-58cf-956f-e23b270a64b1",
      "name": "Create follow-up task",
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 2.2,
      "position": [
        1920,
        240
      ],
      "parameters": {
        "authentication": "appToken",
        "resource": "engagement",
        "type": "task",
        "dueDate": "={{ $now.toISO() }}",
        "metadata": {
          "subject": "=Follow up: {{ $('Get returning visits').item.json.company_name }} is back on your website",
          "body": "={{ $json.output }}",
          "status": "NOT_STARTED"
        },
        "additionalFields": {
          "associations": {
            "dealIds": "={{ $('Find open deal').item.json.results[0].id }}",
            "companyIds": "={{ $('Find company in HubSpot').item.json.results[0].id }}",
            "ownerId": "={{ Number($('Find open deal').item.json.results[0].properties.hubspot_owner_id) }}"
          }
        }
      }
    },
    {
      "id": "32c5daed-91df-5d81-bd39-127a867145c1",
      "name": "Notify account manager in Teams",
      "type": "n8n-nodes-base.microsoftTeams",
      "typeVersion": 2,
      "position": [
        2140,
        240
      ],
      "parameters": {
        "resource": "channelMessage",
        "operation": "create",
        "teamId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "contentType": "html",
        "message": "=<b>Open deal back on the website:</b> {{ $('Find open deal').item.json.results[0].properties.dealname }} ({{ $('Get returning visits').item.json.company_name }})<br>{{ $('Get returning visits').item.json.sessions_total }} visits in the last 7 days.<br>The deal owner has a follow-up task with a suggestion in HubSpot.",
        "options": {
          "includeLinkToWorkflow": false
        }
      }
    }
  ],
  "connections": {
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Suggest next step",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Every hour": {
      "main": [
        [
          {
            "node": "Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Settings": {
      "main": [
        [
          {
            "node": "Get returning visits",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get returning visits": {
      "main": [
        [
          {
            "node": "Once per company per day",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Once per company per day": {
      "main": [
        [
          {
            "node": "Find company in HubSpot",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find company in HubSpot": {
      "main": [
        [
          {
            "node": "Open deal in HubSpot?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Open deal in HubSpot?": {
      "main": [
        [
          {
            "node": "Find open deal",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find open deal": {
      "main": [
        [
          {
            "node": "Suggest next step",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Suggest next step": {
      "main": [
        [
          {
            "node": "Create follow-up task",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create follow-up task": {
      "main": [
        [
          {
            "node": "Notify account manager in Teams",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false
  }
}
