{
  "name": "Pre-Call Nurture Pipeline",
  "nodes": [
    {
      "parameters": {
        "watchFor": "new",
        "folderId": "{{DRIVE_TRANSCRIPTS_FOLDER_ID}}"
      },
      "type": "n8n-nodes-base.googleDriveTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "id": "DriveTrigger",
      "name": "Watch Transcripts Folder"
    },
    {
      "parameters": {
        "download": true,
        "fileId": "={{ $json.id }}"
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 1,
      "position": [
        200,
        0
      ],
      "id": "DownloadTranscript",
      "name": "Download Transcript"
    },
    {
      "parameters": {
        "resource": "binary",
        "binaryPropertyName": "data",
        "options": {}
      },
      "type": "n8n-nodes-base.readBinaryFile",
      "typeVersion": 1,
      "position": [
        400,
        0
      ],
      "id": "ReadTranscript",
      "name": "Read Transcript"
    },
    {
      "parameters": {
        "model": "claude-3-7-sonnet-20250219",
        "input": "={{\n  `I need you to conduct a forensic analysis of my sales conversation to identify segments and pre-call nurture content.\n\n` +\n  `\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n` +\n  `BACKGROUND CONTEXT:\n` +\n  `\u251c\u2500 Business: {{BUSINESS_DESCRIPTION}}\n` +\n  `\u251c\u2500 Current Stats: Show rate {{SHOW_RATE}}%, close rate {{CLOSE_RATE}}%, sales cycle {{SALES_CYCLE}} days\n` +\n  `\u251c\u2500 Volume: {{LEADS_PER_DAY}} leads/day\n` +\n  `\u251c\u2500 Price Point: ${{PRICE}} with {{PAYMENT_TERMS}}\n` +\n  `\u2514\u2500 Sales Process: {{CALL_COUNT}} calls, typical objections: {{OBJECTIONS}}, closed by {{CLOSER}}\n\n` +\n  `MATERIALS PROVIDED:\n` +\n  `\u251c\u2500 This transcript (pasted below)\n` +\n  `\u2514\u2500 Outcome: {{OUTCOME}}\n\n` +\n  `\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n` +\n  $binary.data.toString()\n}}"
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
      "typeVersion": 1,
      "position": [
        600,
        0
      ],
      "id": "ForensicAnalysis",
      "name": "Forensic Analysis"
    },
    {
      "parameters": {
        "functionCode": "const count = (global.get('transcriptCount') || 0) + 1;\nglobal.set('transcriptCount', count);\nreturn [{ json: { count } }];"
      },
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        800,
        0
      ],
      "id": "CountTranscripts",
      "name": "Increment Transcript Counter"
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{ $json.count }}",
              "operation": "equal",
              "value2": 15
            }
          ]
        }
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1000,
        0
      ],
      "id": "CheckThreshold",
      "name": "Reached 15 Transcripts?"
    },
    {
      "parameters": {
        "functionCode": "// fetch last 15 analysis docs and concatenate\nconst drive = this.getNodeParameter('drive', 0);\n// pseudo-code: you'll replace with actual Drive API calls\nreturn [{ json: { masterAnalysis: '<<COMPILED_ANALYSIS_TEXT>>' } }];"
      },
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1200,
        -100
      ],
      "id": "CompileMaster",
      "name": "Compile Master Analysis"
    },
    {
      "parameters": {
        "model": "claude-3-7-sonnet-20250219",
        "input": "={{\n  `Based on the compiled analysis below, please create detailed profiles for 3-5 segments:\n\n` +\n  `<<PASTE MASTER_ANALYSIS>>\n\n` +\n  `For each, provide: Name, Core Traits, Psychological Profile, Language Patterns, Conversion Keys.\n`}}"
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
      "typeVersion": 1,
      "position": [
        1400,
        -100
      ],
      "id": "SegmentAnalysis",
      "name": "Run Segmentation Prompt"
    },
    {
      "parameters": {
        "operation": "create",
        "databaseId": "{{NOTION_DB_ID}}",
        "properties": {
          "Name": {
            "title": [
              {
                "text": {
                  "content": "={{ 'Segments for ' + new Date().toISOString().split('T')[0] }}"
                }
              }
            ]
          },
          "Status": {
            "select": {
              "name": "Needs Review"
            }
          },
          "Segments": {
            "rich_text": [
              {
                "text": {
                  "content": "={{ $json }}"
                }
              }
            ]
          }
        }
      },
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2,
      "position": [
        1600,
        -100
      ],
      "id": "NotionCreate",
      "name": "Publish Segments to Notion"
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "select": "channel",
        "channel": "{{SLACK_CHANNEL_ID}}",
        "text": "Segments ready for review: <!here> Please review the Notion entry."
      },
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2,
      "position": [
        1800,
        -100
      ],
      "id": "SlackNotifyReview",
      "name": "Slack: Ask for Review"
    },
    {
      "parameters": {
        "waitFor": "={{ $node[\"NotionCreate\"].json.properties.Status.select.name === 'Reviewed' }}"
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1,
      "position": [
        2000,
        -100
      ],
      "id": "WaitForReview",
      "name": "Wait for Notion Review"
    },
    {
      "parameters": {
        "loopData": "={{ JSON.parse($node[\"SegmentAnalysis\"].json).segments }}",
        "key": "segment"
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 1,
      "position": [
        2200,
        -100
      ],
      "id": "LoopSegments",
      "name": "Loop Over Segments"
    },
    {
      "parameters": {
        "model": "claude-3-7-sonnet-20250219",
        "input": "={{\n  `Create all pre-call assets for this segment:\n\nSegment Profile:\n` + $item(0).$node.LoopSegments.json.segment +\n  `\n\nAssets: Email sequence, SMS flows, Thank-You page script, Trust PDF/video script.\n`}}"
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
      "typeVersion": 1,
      "position": [
        2400,
        -100
      ],
      "id": "GenerateAssets",
      "name": "Generate Segment Assets"
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "select": "channel",
        "channel": "{{SLACK_CHANNEL_ID}}",
        "text": "All assets generated for segment: `={{ $json.segment.name }}`. Check Drive folder."
      },
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2,
      "position": [
        2600,
        -100
      ],
      "id": "SlackDone",
      "name": "Slack: Assets Ready"
    }
  ],
  "connections": {
    "DriveTrigger": {
      "main": [
        [
          {
            "node": "DownloadTranscript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "DownloadTranscript": {
      "main": [
        [
          {
            "node": "ReadTranscript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ReadTranscript": {
      "main": [
        [
          {
            "node": "ForensicAnalysis",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ForensicAnalysis": {
      "main": [
        [
          {
            "node": "CountTranscripts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CountTranscripts": {
      "main": [
        [
          {
            "node": "CheckThreshold",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CheckThreshold": {
      "main": [
        [
          {
            "node": "CompileMaster",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "CompileMaster": {
      "main": [
        [
          {
            "node": "SegmentAnalysis",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SegmentAnalysis": {
      "main": [
        [
          {
            "node": "NotionCreate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "NotionCreate": {
      "main": [
        [
          {
            "node": "SlackNotifyReview",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SlackNotifyReview": {
      "main": [
        [
          {
            "node": "WaitForReview",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WaitForReview": {
      "main": [
        [
          {
            "node": "LoopSegments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "LoopSegments": {
      "main": [
        [
          {
            "node": "GenerateAssets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GenerateAssets": {
      "main": [
        [
          {
            "node": "SlackDone",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {},
  "versionId": "1.0.0"
}