{
  "nodes": [
    {
      "id": "47ffdee8-a732-4ff4-abcb-9e16afe68808",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -720,
        96
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 9
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "2be3ab96-67b1-4337-8ea6-54363086a9b6",
      "name": "Workflow Configuration",
      "type": "n8n-nodes-base.set",
      "position": [
        -448,
        80
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "dealStageFilter",
              "type": "string",
              "value": "negotiation,proposal"
            },
            {
              "id": "id-2",
              "name": "emailLookbackDays",
              "type": "number",
              "value": 7
            },
            {
              "id": "id-3",
              "name": "riskScoreThreshold",
              "type": "number",
              "value": 70
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "28df8168-37cd-4a7a-a9d8-6be16e0572ad",
      "name": "Get CRM Deals",
      "type": "n8n-nodes-base.hubspot",
      "position": [
        -128,
        0
      ],
      "parameters": {
        "filters": {},
        "resource": "deal",
        "operation": "getAll",
        "returnAll": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "3f46b5c0-c042-4692-9030-d84ce962b793",
      "name": "Get Recent Emails",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -112,
        160
      ],
      "parameters": {
        "filters": {
          "receivedAfter": "={{ $now.minus({ days: $('Workflow Configuration').first().json.emailLookbackDays }).toISO() }}"
        },
        "operation": "getAll"
      },
      "typeVersion": 2.2
    },
    {
      "id": "fdae90e9-9160-4406-bc90-5430468e8629",
      "name": "Combine Deal Context",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        224,
        96
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "34df3c97-c784-44b1-8823-1244d3192472",
      "name": "AI Deal Intelligence Analyzer",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        496,
        96
      ],
      "parameters": {
        "text": "=Analyze the following CRM deal data and recent email communications: {{ $json }}",
        "options": {
          "systemMessage": "You are an AI sales operations analyst specializing in deal intelligence and risk assessment.\n\nYour task is to:\n1. Extract key objections mentioned in emails or call notes\n2. Identify clear next steps and action items\n3. Detect risk signals such as:\n   - Delayed responses or ghosting\n   - Budget concerns or pricing objections\n   - Competitor mentions\n   - Stakeholder changes or lack of engagement\n   - Timeline pushbacks\n4. Calculate a risk score from 0-100 (0=no risk, 100=deal likely to be lost)\n5. Provide a brief risk summary\n\nReturn your analysis in the structured JSON format defined by the output parser."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3
    },
    {
      "id": "730d3bfb-292b-4139-919f-8b847931775a",
      "name": "Deal Intelligence Schema",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        592,
        320
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"objections\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"string\"\n      }\n    },\n    \"nextSteps\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"string\"\n      }\n    },\n    \"riskSignals\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"string\"\n      }\n    },\n    \"riskScore\": {\n      \"type\": \"number\"\n    },\n    \"riskSummary\": {\n      \"type\": \"string\"\n    },\n    \"dealId\": {\n      \"type\": \"string\"\n    }\n  }\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "93eec037-307f-427f-870e-3f3282b221a0",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        464,
        320
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "bb93d87c-4dc7-4f85-993b-e5060cb851ae",
      "name": "Prepare CRM Update",
      "type": "n8n-nodes-base.set",
      "position": [
        896,
        96
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "dealId",
              "type": "string",
              "value": "={{ $json.dealId }}"
            },
            {
              "id": "id-2",
              "name": "objections",
              "type": "string",
              "value": "={{ $json.objections.join('; ') }}"
            },
            {
              "id": "id-3",
              "name": "nextSteps",
              "type": "string",
              "value": "={{ $json.nextSteps.join('; ') }}"
            },
            {
              "id": "id-4",
              "name": "riskScore",
              "type": "number",
              "value": "={{ $json.riskScore }}"
            },
            {
              "id": "id-5",
              "name": "riskSummary",
              "type": "string",
              "value": "={{ $json.riskSummary }}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "ef2feb84-cc9b-4bc4-922c-07466c8f4b7a",
      "name": "Update CRM Deal",
      "type": "n8n-nodes-base.hubspot",
      "position": [
        1072,
        96
      ],
      "parameters": {
        "dealId": {
          "mode": "id",
          "value": "={{ $json.dealId }}"
        },
        "resource": "deal",
        "operation": "update",
        "updateFields": {
          "customPropertiesUi": {
            "customPropertiesValues": [
              {
                "value": "={{ $json.objections }}",
                "property": "objections"
              },
              {
                "value": "={{ $json.next_steps }}",
                "property": "next_steps"
              },
              {
                "value": "={{ $json.risk_score }}",
                "property": "risk_score"
              },
              {
                "value": "={{ $json.risk_summary }}",
                "property": "risk_summary"
              }
            ]
          }
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "aa519aa8-e5c2-41ca-8a2c-ab79e2f9f547",
      "name": "Check Deal Risk",
      "type": "n8n-nodes-base.if",
      "position": [
        1360,
        96
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "id-1",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ $('Prepare CRM Update').item.json.riskScore }}",
              "rightValue": "={{ $('Workflow Configuration').first().json.riskScoreThreshold }}"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "a7c86138-2700-426e-b033-fc4ae716a9e7",
      "name": "Alert Sales Manager",
      "type": "n8n-nodes-base.slack",
      "position": [
        1584,
        80
      ],
      "parameters": {
        "text": "=\ud83d\udea8 *High-Risk Deal Alert*\n\n*Deal ID:* {{ $json.dealId }}\n*Risk Score:* {{ $json.riskScore }}/100\n*Risk Summary:* {{ $json.riskSummary }}\n\n*Key Objections:*\n{{ $json.objections }}\n\n*Next Steps:*\n{{ $json.nextSteps }}\n\nPlease review this deal immediately.",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "<__PLACEHOLDER_VALUE__Slack channel ID for sales manager alerts__>"
        },
        "otherOptions": {}
      },
      "typeVersion": 2.4
    },
    {
      "id": "3dd4d2ac-d4ec-41c3-b781-5274f91c86e8",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -752,
        -48
      ],
      "parameters": {
        "color": 7,
        "width": 192,
        "height": 320,
        "content": "## Trigger\nRuns daily to start deal monitoring workflow."
      },
      "typeVersion": 1
    },
    {
      "id": "7a70759d-3b17-4f6b-b405-8ab8e06a4807",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -528,
        -80
      ],
      "parameters": {
        "color": 7,
        "width": 272,
        "height": 384,
        "content": "## Configuration\nDefines deal filters, email lookback window, and risk threshold."
      },
      "typeVersion": 1
    },
    {
      "id": "ce921a55-6a3b-4d3e-8323-c18650372fc2",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        144,
        -128
      ],
      "parameters": {
        "color": 7,
        "height": 464,
        "content": "## Context Merge\nCombines deal data and emails into a single dataset for analysis."
      },
      "typeVersion": 1
    },
    {
      "id": "a15c8bf2-7438-498f-87dc-b26c636b0241",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        416,
        -32
      ],
      "parameters": {
        "color": 7,
        "width": 384,
        "height": 320,
        "content": "## AI Analysis\nAI detects objections, next steps, and calculates deal risk score."
      },
      "typeVersion": 1
    },
    {
      "id": "4fd7b96f-98aa-4b4f-b02b-f16cf3e6d865",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        848,
        -32
      ],
      "parameters": {
        "color": 7,
        "width": 352,
        "height": 320,
        "content": "## Data Preparation and update \nFormats AI output for updating CRM fields  and Writes risk insights, objections, and next steps back to CRM."
      },
      "typeVersion": 1
    },
    {
      "id": "8eabfa89-9b6b-46a2-ab1b-80d2a0d17c12",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1296,
        -48
      ],
      "parameters": {
        "color": 7,
        "width": 432,
        "height": 320,
        "content": "## Risk Check and Alerting\nCompares deal risk score against defined threshold and Sends Slack alert for high-risk deals needing attention."
      },
      "typeVersion": 1
    },
    {
      "id": "7a25e630-a30c-49e6-997e-498d15dc590c",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1360,
        -256
      ],
      "parameters": {
        "width": 416,
        "height": 624,
        "content": "## How it works\nThis workflow monitors your CRM deals and flags risky ones automatically.\n\nIt runs on a schedule and pulls active deals from your CRM along with recent email conversations. The data is combined and analyzed using AI to understand deal progress, objections, and engagement.\n\nThe AI identifies key issues, suggests next steps, and assigns a risk score based on signals like delays, lack of response, or pricing concerns.\n\nThe results are saved back into the CRM as structured fields so your team has clear visibility.\n\nIf a deal crosses a defined risk threshold, the workflow sends a Slack alert to notify the sales manager for immediate action.\n\n## Setup steps\n1. Connect HubSpot credentials (for deals)\n2. Connect Gmail (to fetch recent emails)\n3. Connect OpenAI (for analysis)\n4. Connect Slack (for alerts)\n5. Set risk threshold and filters in config node\n6. Test with sample deals\n7. Activate the workflow"
      },
      "typeVersion": 1
    },
    {
      "id": "0012628c-9d13-4cb3-a90a-2fae48f9686b",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -208,
        -144
      ],
      "parameters": {
        "color": 7,
        "width": 304,
        "height": 464,
        "content": "## Data Collection\nFetches CRM deals and recent email activity for context."
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Get CRM Deals": {
      "main": [
        [
          {
            "node": "Combine Deal Context",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Deal Risk": {
      "main": [
        [
          {
            "node": "Alert Sales Manager",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update CRM Deal": {
      "main": [
        [
          {
            "node": "Check Deal Risk",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Workflow Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Recent Emails": {
      "main": [
        [
          {
            "node": "Combine Deal Context",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Deal Intelligence Analyzer",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Prepare CRM Update": {
      "main": [
        [
          {
            "node": "Update CRM Deal",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Combine Deal Context": {
      "main": [
        [
          {
            "node": "AI Deal Intelligence Analyzer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Configuration": {
      "main": [
        [
          {
            "node": "Get CRM Deals",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get Recent Emails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Deal Intelligence Schema": {
      "ai_outputParser": [
        [
          {
            "node": "AI Deal Intelligence Analyzer",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "AI Deal Intelligence Analyzer": {
      "main": [
        [
          {
            "node": "Prepare CRM Update",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}