{
  "id": "REMOVED_FOR_PRIVACY",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "15 - LeadFlow Automation",
  "tags": [],
  "nodes": [
    {
      "id": "91039bef-b0cf-4aaa-b5d7-8151f3fe5bf4",
      "name": "\ud83d\udce7 Gmail: New Lead Response",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -80,
        -160
      ],
      "parameters": {
        "filters": {
          "labelIds": [
            "YOUR_GMAIL_LABEL_ID"
          ]
        },
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "def6d1d6-c2cc-4b63-b387-7e38cc8e19b1",
      "name": "\ud83d\udd27 Normalize Gmail Data",
      "type": "n8n-nodes-base.set",
      "position": [
        360,
        -160
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "normalize-gmail",
              "name": "leadEmail",
              "type": "string",
              "value": "={{ $json.From }}"
            },
            {
              "id": "normalize-gmail-subject",
              "name": "subject",
              "type": "string",
              "value": "={{ $json.Subject }}"
            },
            {
              "id": "normalize-gmail-message",
              "name": "message",
              "type": "string",
              "value": "={{ $json.snippet }}"
            },
            {
              "id": "normalize-gmail-source",
              "name": "source",
              "type": "string",
              "value": "Gmail"
            },
            {
              "id": "normalize-gmail-timestamp",
              "name": "receivedAt",
              "type": "string",
              "value": "={{ $json.internalDate }}"
            }
          ]
        }
      },
      "typeVersion": 3.3
    },
    {
      "id": "b1d38a73-0376-433a-82da-a7a04d3d5da7",
      "name": "\ud83d\udccb Parse AI Analysis Results",
      "type": "n8n-nodes-base.code",
      "position": [
        956,
        -160
      ],
      "parameters": {
        "jsCode": "let aiResponse = $json.output;\n\n// Remove triple backticks and possible \"json\" label\naiResponse = aiResponse.replace(/```json|```/g, '').trim();\n\nlet analysis;\n\ntry {\n  analysis = JSON.parse(aiResponse);\n} catch (error) {\n  // Fallback parsing if JSON is malformed\n  analysis = {\n    sentiment: 'Neutral',\n    intent: 'Needs Info',\n    urgency: 'Medium',\n    nextAction: 'Email',\n    summary: 'Could not parse AI response',\n    priority: 'Warm'\n  };\n}\n\n// Get the original lead data from Normalize Gmail node\nconst leadData = $node['\ud83d\udd27 Normalize Gmail Data'].json;\n\n// Combine everything\nconst result = {\n  ...leadData,\n  ...analysis,\n  analysisDate: new Date().toISOString(),\n  needsFollowUp: analysis.nextAction !== 'No Action',\n  isHighPriority: analysis.priority === 'Hot' || analysis.urgency === 'High'\n};\n\nreturn [{ json: result }];"
      },
      "typeVersion": 2
    },
    {
      "id": "b92abdcc-33b5-4785-b1c4-84c210112dcf",
      "name": "\ud83d\udcdd HubSpot: Create Follow-up Task",
      "type": "n8n-nodes-base.hubspot",
      "position": [
        1396,
        -360
      ],
      "parameters": {
        "type": "task",
        "metadata": {
          "body": "={{ $json.message }}",
          "subject": "={{ $json.subject }}",
          "forObjectType": "CONTACT"
        },
        "resource": "engagement",
        "authentication": "appToken",
        "additionalFields": {}
      },
      "credentials": {
        "hubspotAppToken": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "74068c78-2ea1-4447-987a-8d40088483d4",
      "name": "\ud83d\udcac Slack: Notify Sales Team",
      "type": "n8n-nodes-base.slack",
      "position": [
        1396,
        40
      ],
      "parameters": {
        "text": "=Summary: {{ $json.summary }}\nEmail: {{ $json.leadEmail }}\nPriority: {{ $json.priority }}\nUrgency: {{ $json.urgency }}\nDate: {{ $json.analysisDate }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_SLACK_CHANNEL_ID",
          "cachedResultName": "general"
        },
        "otherOptions": {
          "mrkdwn": false
        }
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "ae8454de-6504-4947-8571-87bd4bc0e0b0",
      "name": "\ud83d\udcca Log to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1396,
        -160
      ],
      "parameters": {
        "columns": {
          "value": {
            "Date": "={{ $json.analysisDate }}",
            "Email": "={{ $json.leadEmail }}",
            "Intent ": "={{ $json.intent }}",
            "Message": "={{ $json.message }}",
            "Subject": "={{ $json.subject }}",
            "Summary": "={{ $json.summary }}",
            "Urgency": "={{ $json.urgency }}",
            "Priority": "={{ $json.priority }}",
            "Sentiment": "={{ $json.sentiment }}",
            "nextAction": "={{ $json.nextAction }}"
          },
          "schema": [
            {
              "id": "Email",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Date",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Subject",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Subject",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Message",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Message",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Sentiment",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Sentiment",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Intent ",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Intent ",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Urgency",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Urgency",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "nextAction",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "nextAction",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Summary",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Summary",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Priority",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Priority",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "YOUR_GOOGLE_SHEETS_URL",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_GOOGLE_SHEETS_ID",
          "cachedResultUrl": "YOUR_GOOGLE_SHEETS_URL",
          "cachedResultName": "Follow Up"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4
    },
    {
      "id": "6b10e13b-d8b0-42e2-ad8a-704a7202148f",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        668,
        60
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "ad3e3fb6-2e91-41c8-8082-30fe37202a71",
      "name": "\ud83d\udd00 Check if Data Exists",
      "type": "n8n-nodes-base.if",
      "position": [
        140,
        -160
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "condition-1",
              "operator": {
                "type": "object",
                "operation": "exists",
                "rightType": "any"
              },
              "leftValue": "={{ $node['\ud83d\udce7 Gmail: New Lead Response'].json }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "88cd5104-9389-4664-8e03-3adee0c408a5",
      "name": "\ud83d\udd0d Needs Follow-Up?",
      "type": "n8n-nodes-base.if",
      "position": [
        1176,
        -160
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "b2831020-9725-454b-a3dc-0b6465587288",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.needsFollowUp }}",
              "rightValue": {}
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "ad81e8cb-6e5d-4b3a-8b1e-5a00853ed3c2",
      "name": "\ud83e\udde0 Analyze Lead Response (AI)",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        580,
        -160
      ],
      "parameters": {
        "text": "=Analyze this lead response and provide:\n\n1. Sentiment: (Positive/Neutral/Negative)\n2. Intent: (Interested/Not Interested/Needs Info/Ready to Buy/Objection)\n3. Urgency: (High/Medium/Low)\n4. Next Action: (Call/Email/Demo/Quote/No Action)\n5. Summary: Brief 1-2 sentence summary\n6. Priority: (Hot/Warm/Cold)\n\nLead Email: {{ $json.leadEmail }}\nSubject: {{ $json.subject }}\nMessage: {{ $json.message }}\nRespond in JSON format with keys: sentiment, intent, urgency, nextAction, summary, priority",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 2
    },
    {
      "id": "b970147b-c301-49e4-924d-535e7cf3a01e",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -120,
        -500
      ],
      "parameters": {
        "color": 5,
        "width": 640,
        "height": 680,
        "content": "## Nodes:\n\n**\ud83d\udce7 Gmail: New Lead Response\n\n\ud83d\udd00 Check if Data Exists\n\n\ud83d\udd27 Normalize Gmail Data**\n\n*Captures new lead responses from Gmail with a specific label every minute. Verifies the presence of data and standardizes incoming fields (email, subject, message, timestamp, etc.) for consistent processing across the workflow.*"
      },
      "typeVersion": 1
    },
    {
      "id": "885d848a-de98-48bb-8fc1-dab28cc20570",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        540,
        -500
      ],
      "parameters": {
        "color": 3,
        "width": 580,
        "height": 680,
        "content": "## Nodes:\n\n**\ud83e\udde0 Analyze Lead Response (AI)\n\nOpenAI Chat Model\n\n\ud83d\udccb Parse AI Analysis Results**\n\n*Utilizes OpenAI to analyze the lead's message for sentiment, intent, urgency, next action, and priority. The response is parsed and merged with original email data. Adds calculated flags (needsFollowUp, isHighPriority) to streamline follow-up logic.*"
      },
      "typeVersion": 1
    },
    {
      "id": "90a8e89d-42fe-498e-950e-c9e1a6eb6878",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1140,
        -500
      ],
      "parameters": {
        "width": 160,
        "height": 680,
        "content": "## Node:\n\n**\ud83d\udd0d Needs Follow-Up?**\n\n*Evaluates if the AI-recommended next action requires follow-up. If so, triggers all follow-up actions like CRM task creation, sales notification, and data logging.*"
      },
      "typeVersion": 1
    },
    {
      "id": "fbd6f660-c7e3-4e8e-ad7f-a8ca871b89dc",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1320,
        -760
      ],
      "parameters": {
        "color": 4,
        "width": 300,
        "height": 1000,
        "content": "## Nodes:\n\n**\ud83d\udcdd HubSpot: Create Follow-up Task\n\n\ud83d\udcac Slack: Notify Sales Team\n\n\ud83d\udcca Log to Google Sheets**\n\n*Once a lead needs follow-up, the workflow:\n\nCreates a HubSpot task for sales tracking\n\nSends a Slack alert with lead insights\n\nLogs analysis to Google Sheets for tracking and review*"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "REMOVED_FOR_PRIVACY",
  "connections": {
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "\ud83e\udde0 Analyze Lead Response (AI)",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udd0d Needs Follow-Up?": {
      "main": [
        [
          {
            "node": "\ud83d\udcdd HubSpot: Create Follow-up Task",
            "type": "main",
            "index": 0
          },
          {
            "node": "\ud83d\udcac Slack: Notify Sales Team",
            "type": "main",
            "index": 0
          },
          {
            "node": "\ud83d\udcca Log to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udd00 Check if Data Exists": {
      "main": [
        [
          {
            "node": "\ud83d\udd27 Normalize Gmail Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udd27 Normalize Gmail Data": {
      "main": [
        [
          {
            "node": "\ud83e\udde0 Analyze Lead Response (AI)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udcac Slack: Notify Sales Team": {
      "main": [
        []
      ]
    },
    "\ud83d\udce7 Gmail: New Lead Response": {
      "main": [
        [
          {
            "node": "\ud83d\udd00 Check if Data Exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udccb Parse AI Analysis Results": {
      "main": [
        [
          {
            "node": "\ud83d\udd0d Needs Follow-Up?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83e\udde0 Analyze Lead Response (AI)": {
      "main": [
        [
          {
            "node": "\ud83d\udccb Parse AI Analysis Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udcdd HubSpot: Create Follow-up Task": {
      "main": [
        []
      ]
    }
  }
}