{
  "name": "General Client Onboarding Pipeline",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "client-onboarding-webhook",
        "options": {}
      },
      "id": "1",
      "name": "Onboarding Webhook Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [100, 300]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "stripe-checkout-webhook",
        "options": {}
      },
      "id": "2",
      "name": "Stripe Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [100, 500]
    },
    {
      "parameters": {
        "jsCode": "return {\n  // Operational Switches\n  enableGoogleSheets: true,\n  enableAirtable: true,\n  enableNotion: true,\n  enableGoogleDrive: true,\n  enableSlackComms: true,\n  enableWelcomeEmail: true,\n  enableTelegramAdmin: true,\n  \n  // Credentials & Resource Identifiers\n  googleSheetId: \"your_google_sheet_id_here\",\n  airtableBaseId: \"your_airtable_base_id_here\",\n  airtableTableName: \"Clients\",\n  notionDatabaseId: \"your_notion_database_id_here\",\n  googleDriveMasterFolderId: \"your_master_drive_folder_id_here\",\n  welcomeEmailFrom: \"hello@yourcompany.com\",\n  telegramChatId: \"your_telegram_chat_id_here\"\n};"
      },
      "id": "3",
      "name": "Workflow Settings",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [320, 400]
    },
    {
      "parameters": {
        "jsCode": "const webhookPayload = $node[\"Onboarding Webhook Trigger\"] ? ($node[\"Onboarding Webhook Trigger\"].json.body || {}) : {};\nconst stripePayload = $node[\"Stripe Trigger\"] ? ($node[\"Stripe Trigger\"].json.body || {}) : {};\n\n// Detect trigger source\nconst isStripe = Object.keys(stripePayload).length > 0;\nconst payload = isStripe ? stripePayload : webhookPayload;\nconst config = $node[\"Workflow Settings\"].json;\n\nlet companyName = \"New Client\";\nlet firstName = \"First\";\nlet lastName = \"Last\";\nlet email = \"\";\nlet phone = \"Not Provided\";\nlet website = \"Not Provided\";\nlet billingEmail = \"Same as Contact\";\nlet successMetrics = \"Not Provided\";\nlet manualSteps = \"Not Provided\";\nlet techStack = \"Not Provided\";\nlet apiLiabilityAgreement = \"Not Agreed\";\nlet systemAccessConsent = \"Not Agreed\";\n\nif (isStripe) {\n  const session = payload.data ? payload.data.object : (payload || {});\n  email = session.customer_details ? (session.customer_details.email || \"\") : \"\";\n  const fullName = session.customer_details ? (session.customer_details.name || \"\") : \"\";\n  const nameParts = fullName.trim().split(\" \");\n  firstName = nameParts[0] || \"First\";\n  lastName = nameParts.slice(1).join(\" \") || \"Last\";\n  \n  const metadata = session.metadata || {};\n  companyName = metadata.company_name || \"New Client\";\n  phone = metadata.phone || \"Not Provided\";\n  website = metadata.website || \"Not Provided\";\n  billingEmail = metadata.billing_email || email;\n  successMetrics = metadata.success_metrics || \"Not Provided\";\n  manualSteps = metadata.manual_steps || \"Not Provided\";\n  techStack = metadata.tech_stack || \"Not Provided\";\n  apiLiabilityAgreement = metadata.api_liability_agreement === \"true\" || metadata.api_liability_agreement === true ? \"Agreed\" : \"Not Agreed\";\n  systemAccessConsent = metadata.system_access_consent === \"true\" || metadata.system_access_consent === true ? \"Agreed\" : \"Not Agreed\";\n} else {\n  companyName = payload.company_name || \"New Client\";\n  firstName = payload.first_name || \"First\";\n  lastName = payload.last_name || \"Last\";\n  email = payload.email || \"\";\n  phone = payload.phone || \"Not Provided\";\n  website = payload.website || \"Not Provided\";\n  billingEmail = payload.billing_email || \"Same as Contact\";\n  successMetrics = payload.success_metrics || \"Not Provided\";\n  manualSteps = payload.manual_steps_description || \"Not Provided\";\n  techStack = payload.tech_stack || \"Not Provided\";\n  apiLiabilityAgreement = payload.api_liability_agreement ? \"Agreed\" : \"Not Agreed\";\n  systemAccessConsent = payload.system_access_consent ? \"Agreed\" : \"Not Agreed\";\n}\n\nreturn {\n  companyName: companyName,\n  firstName: firstName,\n  lastName: lastName,\n  email: email,\n  phone: phone,\n  website: website,\n  billingEmail: billingEmail,\n  successMetrics: successMetrics,\n  manualSteps: manualSteps,\n  techStack: techStack,\n  apiLiabilityAgreement: apiLiabilityAgreement,\n  systemAccessConsent: systemAccessConsent,\n  safeSlackName: companyName\n    .toLowerCase()\n    .replace(/[^a-z0-9-_]/g, \"-\")\n    .substring(0, 70),\n  config: config\n};"
      },
      "id": "4",
      "name": "Process Client Details",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [540, 400]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.config.enableGoogleSheets }}",
              "value2": true
            }
          ]
        }
      },
      "id": "5",
      "name": "Sync to Sheets?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [760, 200]
    },
    {
      "parameters": {
        "resource": "spreadsheet",
        "operation": "append",
        "spreadsheetId": "={{ $json.config.googleSheetId }}",
        "values": {
          "mappingMode": "defineEverything",
          "value": {
            "Date": "={{ new Date().toISOString() }}",
            "Company Name": "={{ $json.companyName }}",
            "First Name": "={{ $json.firstName }}",
            "Last Name": "={{ $json.lastName }}",
            "Email": "={{ $json.email }}",
            "Phone": "={{ $json.phone }}",
            "Website": "={{ $json.website }}",
            "Success Metrics": "={{ $json.successMetrics }}",
            "Manual Steps": "={{ $json.manualSteps }}",
            "Tech Stack": "={{ $json.techStack }}",
            "API Liability Waiver": "={{ $json.apiLiabilityAgreement }}",
            "System Access Consent": "={{ $json.systemAccessConsent }}",
            "Drive Folder Link": "={{ $node[\"Google Drive Folder Creation\"].json.webViewLink || \"Pending\" }}",
            "Slack Channel Link": "=#{{ $json.safeSlackName }}"
          }
        }
      },
      "id": "6",
      "name": "Google Sheets Log",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [960, 100]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $node[\"Process Client Details\"].json.config.enableAirtable }}",
              "value2": true
            }
          ]
        }
      },
      "id": "7",
      "name": "Sync to Airtable?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [760, 400]
    },
    {
      "parameters": {
        "operation": "append",
        "base": "={{ $json.config.airtableBaseId }}",
        "table": "={{ $json.config.airtableTableName }}",
        "addAllFields": true,
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "Company Name",
              "fieldValue": "={{ $json.companyName }}"
            },
            {
              "fieldId": "Contact Email",
              "fieldValue": "={{ $json.email }}"
            },
            {
              "fieldId": "Full Name",
              "fieldValue": "={{ $json.firstName }} {{ $json.lastName }}"
            },
            {
              "fieldId": "Success Metrics",
              "fieldValue": "={{ $json.successMetrics }}"
            },
            {
              "fieldId": "API Waiver",
              "fieldValue": "={{ $json.apiLiabilityAgreement }}"
            },
            {
              "fieldId": "System Consent",
              "fieldValue": "={{ $json.systemAccessConsent }}"
            },
            {
              "fieldId": "Drive Folder",
              "fieldValue": "={{ $node[\"Google Drive Folder Creation\"].json.webViewLink || \"\" }}"
            }
          ]
        }
      },
      "id": "8",
      "name": "Airtable Log",
      "type": "n8n-nodes-base.airtable",
      "typeVersion": 2,
      "position": [960, 300]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $node[\"Process Client Details\"].json.config.enableNotion }}",
              "value2": true
            }
          ]
        }
      },
      "id": "9",
      "name": "Sync to Notion?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [760, 600]
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "create",
        "databaseId": "={{ $json.config.notionDatabaseId }}",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Company Name",
              "title": "={{ $json.companyName }}"
            },
            {
              "key": "Email",
              "email": "={{ $json.email }}"
            },
            {
              "key": "Representative",
              "richText": "={{ $json.firstName }} {{ $json.lastName }}"
            },
            {
              "key": "API Liability Waiver",
              "select": "={{ $json.apiLiabilityAgreement }}"
            },
            {
              "key": "System Access Consent",
              "select": "={{ $json.systemAccessConsent }}"
            }
          ]
        }
      },
      "id": "10",
      "name": "Notion Log",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.1,
      "position": [960, 500]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $node[\"Process Client Details\"].json.config.enableGoogleDrive }}",
              "value2": true
            }
          ]
        }
      },
      "id": "11",
      "name": "Create Drive Folder?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [1200, 400]
    },
    {
      "parameters": {
        "resource": "folder",
        "name": "={{ $node[\"Process Client Details\"].json.companyName }} - Project Hub",
        "parents": [
          "={{ $node[\"Process Client Details\"].json.config.googleDriveMasterFolderId }}"
        ],
        "options": {}
      },
      "id": "12",
      "name": "Google Drive Folder Creation",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [1400, 300]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $node[\"Process Client Details\"].json.config.enableSlackComms }}",
              "value2": true
            }
          ]
        }
      },
      "id": "13",
      "name": "Setup Slack?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [1600, 400]
    },
    {
      "parameters": {
        "channel": "={{ $node[\"Process Client Details\"].json.safeSlackName }}",
        "text": "🚀 *New Client Onboarded!*\n\nWelcome *{{ $node[\"Process Client Details\"].json.companyName }}* to their project workspace. System provisioning complete! 🛠️",
        "otherOptions": {
          "isPrivate": true
        }
      },
      "id": "14",
      "name": "Slack Channel Creation",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.1,
      "position": [1800, 300]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $node[\"Process Client Details\"].json.config.enableWelcomeEmail }}",
              "value2": true
            }
          ]
        }
      },
      "id": "15",
      "name": "Send Welcome Email?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [2000, 400]
    },
    {
      "parameters": {
        "fromEmail": "={{ $node[\"Process Client Details\"].json.config.welcomeEmailFrom }}",
        "toEmail": "={{ $node[\"Process Client Details\"].json.email }}",
        "subject": "Welcome Package — Your Project Hub is Ready!",
        "html": "<html><body><h2>Welcome Onboard!</h2><p>We are excited to begin work with you.</p><p><strong>Your Dedicated Google Drive Folder:</strong> <a href=\"{{ $node[\"Google Drive Folder Creation\"].json.webViewLink }}\">Access Project Drive Hub</a></p><p><strong>Your Private Slack Channel:</strong> #{{ $node[\"Process Client Details\"].json.safeSlackName }}</p><p>Best regards,<br>The Operations Team</p></body></html>",
        "options": {}
      },
      "id": "16",
      "name": "SMTP Welcome Email",
      "type": "n8n-nodes-base.email",
      "typeVersion": 1,
      "position": [2200, 300]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $node[\"Process Client Details\"].json.config.enableTelegramAdmin }}",
              "value2": true
            }
          ]
        }
      },
      "id": "17",
      "name": "Telegram Alert?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [2400, 400]
    },
    {
      "parameters": {
        "chatId": "={{ $node[\"Process Client Details\"].json.config.telegramChatId }}",
        "text": "🔥 *[Onboarding Alert]*\n\n💼 *Company:* {{ $node[\"Process Client Details\"].json.companyName }}\n👤 *Contact:* {{ $node[\"Process Client Details\"].json.firstName }} {{ $node[\"Process Client Details\"].json.lastName }} ({{ $node[\"Process Client Details\"].json.email }})\n📈 *Metrics:* {{ $node[\"Process Client Details\"].json.successMetrics }}\n\n⚖️ *Legal Consent Checks:*\n• API Liability Waiver: *{{ $node[\"Process Client Details\"].json.apiLiabilityAgreement }}*\n• System Access: *{{ $node[\"Process Client Details\"].json.systemAccessConsent }}*\n\n📂 *Google Drive:* {{ $node[\"Google Drive Folder Creation\"].json.webViewLink || \"Skipped/Failed\" }}\n💬 *Slack Channel:* #{{ $node[\"Process Client Details\"].json.safeSlackName }}\n📧 *Welcome Email Status:* Sent Successfully",
        "additionalFields": {
          "parse_mode": "Markdown"
        }
      },
      "id": "18",
      "name": "Admin Telegram Alert",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [2600, 300]
    }
  ],
  "connections": {
    "Onboarding Webhook Trigger": {
      "main": [
        [
          {
            "node": "Workflow Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Stripe Trigger": {
      "main": [
        [
          {
            "node": "Workflow Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Settings": {
      "main": [
        [
          {
            "node": "Process Client Details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process Client Details": {
      "main": [
        [
          {
            "node": "Sync to Sheets?",
            "type": "main",
            "index": 0
          },
          {
            "node": "Sync to Airtable?",
            "type": "main",
            "index": 0
          },
          {
            "node": "Sync to Notion?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sync to Sheets?": {
      "main": [
        [
          {
            "node": "Google Sheets Log",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create Drive Folder?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets Log": {
      "main": [
        [
          {
            "node": "Create Drive Folder?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sync to Airtable?": {
      "main": [
        [
          {
            "node": "Airtable Log",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sync to Notion?": {
      "main": [
        [
          {
            "node": "Notion Log",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Drive Folder?": {
      "main": [
        [
          {
            "node": "Google Drive Folder Creation",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Setup Slack?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Drive Folder Creation": {
      "main": [
        [
          {
            "node": "Setup Slack?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Setup Slack?": {
      "main": [
        [
          {
            "node": "Slack Channel Creation",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Welcome Email?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Slack Channel Creation": {
      "main": [
        [
          {
            "node": "Send Welcome Email?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Welcome Email?": {
      "main": [
        [
          {
            "node": "SMTP Welcome Email",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Telegram Alert?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SMTP Welcome Email": {
      "main": [
        [
          {
            "node": "Telegram Alert?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Alert?": {
      "main": [
        [
          {
            "node": "Admin Telegram Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {}
}
