{
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "name": "SaaS Onboarding Template",
  "tags": [],
  "nodes": [
    {
      "id": "b9c16e96-31ec-4988-871d-7ea15090853a",
      "name": "Amount conversion",
      "type": "n8n-nodes-base.code",
      "position": [
        0,
        128
      ],
      "parameters": {
        "jsCode": "const amountInPence = $input.first().json.data.object.amount_total;\nconst amount = amountInPence / 100;\nreturn [{ json: { amount: `$${amount}` } }];"
      },
      "typeVersion": 2
    },
    {
      "id": "89327a83-5252-4724-b8a7-a469496e7d09",
      "name": "Get user_details",
      "type": "n8n-nodes-base.set",
      "position": [
        208,
        128
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "ebf02fce-9c7a-43f6-b2a2-399baeee8d5e",
              "name": "amount",
              "type": "string",
              "value": "={{ $json.amount }}"
            },
            {
              "id": "3804fc6a-55c5-44eb-bcbe-ee294270e29a",
              "name": "name",
              "type": "string",
              "value": "={{ $('Stripe Trigger').item.json.data.object.customer_details.name }}"
            },
            {
              "id": "fcb2d5c6-ee73-44aa-8692-1a6648f2e5b7",
              "name": "email",
              "type": "string",
              "value": "={{ $('Stripe Trigger').item.json.data.object.customer_details.email }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "014f589f-5080-4bc8-898b-ef22ddecc237",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        416,
        128
      ],
      "parameters": {
        "text": "=Name: {{ $json.name }}\nAmount paid: {{ $json.amount }}\nSubscription date: {{ $now }}",
        "options": {
          "systemMessage": "=You are a warm, professional onboarding assistant for LeadPulse, an AI-powered lead generation platform.\n\nA new customer has just subscribed. Use the Pinecone tool to retrieve the subscription plan details based on the amount paid, then write a personalised welcome email for this customer.\n\nThe subscription is monthly. Calculate the renewal date by adding 30 days to the current date and mention it in the email.\n\nThe email body should follow this structure:\nOpen with one warm sentence welcoming them to their specific plan.\n\nThen clearly state what they now have access to, highlight 2-3 key features of their plan in a conversational tone, not a bullet list.\n\nInclude a short paragraph with the practical details, their plan is set to renew on the calculated renewal date, payment will be automatically charged to their account, and they can cancel or manage their subscription anytime from their account settings.\n\nEnd with one punchy sentence encouraging them to get started.\n\nThe email body must be wrapped in clean HTML. Use tags like <p>, <strong>, and <br> where appropriate. Do not use inline styles or external CSS.\n\nSubject line format: {first name}, welcome to LeadPulse {plan}!\n\nSign off as: The LeadPulse Team\n\nKeep the tone human, confident and straightforward. No corporate fluff. No generic phrases like \"we are thrilled\" or \"we are excited.\"\n\nYou must return ONLY a valid JSON object with exactly four fields:\n\n{\n  \"tier\": \"\",\n  \"renewal_date\": \"\",\n  \"subject\": \"\",\n  \"body\": \"\"\n}\n\nNo preamble, no explanation, no markdown backticks outside the JSON. Just the raw JSON object."
        },
        "promptType": "define"
      },
      "typeVersion": 3.1
    },
    {
      "id": "816034a3-854b-4910-a453-1b06d69029a0",
      "name": "Pinecone Tool",
      "type": "@n8n/n8n-nodes-langchain.vectorStorePinecone",
      "position": [
        512,
        272
      ],
      "parameters": {
        "mode": "retrieve-as-tool",
        "topK": 3,
        "options": {
          "pineconeNamespace": "YOUR_PINECONE_NAMESPACE"
        },
        "pineconeIndex": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_PINECONE_INDEX",
          "cachedResultName": "YOUR_PINECONE_INDEX"
        },
        "toolDescription": "Call this tool to access the database for leadpulse chunks"
      },
      "credentials": {
        "pineconeApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "537e1183-a2a0-4259-be64-13b4f5cdfae5",
      "name": "Parse AI Output",
      "type": "n8n-nodes-base.code",
      "position": [
        816,
        128
      ],
      "parameters": {
        "jsCode": "const raw = $input.first().json.output;\nconst parsed = JSON.parse(raw);\n\nreturn [{\n  json: {\n    tier: parsed.tier,\n    renewal_date: parsed.renewal_date,\n    subject: parsed.subject,\n    body: parsed.body\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "216c8d50-7ca4-43f2-890f-5733e7bb59b1",
      "name": "Log customer details",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1200,
        128
      ],
      "parameters": {
        "columns": {
          "value": {
            "Name": "={{ $('Get user_details').item.json.name }}",
            "Tier": "={{ $('Parse AI Output').item.json.tier }}",
            "Email": "={{ $('Get user_details').item.json.email }}",
            "Status": "Active",
            "Renewal Date": "={{ $('Parse AI Output').item.json.renewal_date }}",
            "Renewal Status": "Renewal_pending",
            "Subscription Date": "={{ $now }}"
          },
          "schema": [
            {
              "id": "Name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Email",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Tier",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Tier",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Subscription Date",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Subscription Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Renewal Date",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Renewal Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Renewal Status",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Renewal Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_GOOGLE_SHEET_ID",
          "cachedResultName": "YOUR_SHEET_NAME"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "75302c0b-e616-4663-9c1f-f1ed10230387",
      "name": "Send Welcome Email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        992,
        128
      ],
      "parameters": {
        "sendTo": "={{ $('Get user_details').item.json.email }}",
        "message": "={{ $json.body }}",
        "options": {
          "appendAttribution": false
        },
        "subject": "={{ $json.subject }}"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "3b0ef4fc-8d57-4e7b-bc1e-6897eb1d5622",
      "name": "GPT-4o",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        416,
        272
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "gpt-4o"
        },
        "options": {
          "textFormat": {
            "textOptions": {
              "type": "json_object"
            }
          }
        },
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "36b39931-adf1-46d5-ade1-4c57fc4b82d0",
      "name": "OpenAI Embeddings",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        464,
        336
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "56469a95-c10b-4d09-b9a8-ebbb441803ff",
      "name": "Stripe Trigger",
      "type": "n8n-nodes-base.stripeTrigger",
      "position": [
        -176,
        128
      ],
      "parameters": {
        "events": [
          "checkout.session.completed"
        ]
      },
      "credentials": {
        "stripeApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "28fefbbf-2a51-44b9-9eca-9f53d97ec0ac",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -720,
        -160
      ],
      "parameters": {
        "width": 480,
        "height": 832,
        "content": "**Try It Out!**\n\nThis n8n template automates the entire onboarding experience for a SaaS product with multiple subscription tiers. When a customer completes payment via Stripe, the workflow identifies their plan, retrieves tier details from a Pinecone vector store, and uses a GPT-4 AI Agent to generate a personalised HTML welcome email, then logs the customer to Google Sheets for renewal tracking.\n\n**How it works**\n\n- A Stripe Trigger listens for successful payment events.\n- The payment amount is converted and used to identify the subscription tier.\n- Customer details are extracted from the Stripe payload.\n- The AI Agent queries Pinecone to retrieve the correct plan details and generates a personalised welcome email with the renewal date calculated automatically.\n- The email is parsed and sent via Gmail.\n- The customer's details and subscription info are logged to Google Sheets for follow-up tracking.\n\n**How to use**\n\n- Connect your Stripe account and configure it to listen for checkout.session.completed events.\n- Add your Pinecone credentials and ensure your tier chunks are stored in your index.\n- Connect OpenAI for the AI Agent and Embeddings.\n- Set up Gmail with your sender email address.\n- Create a Google Sheet with columns: Name, Email, Amount, Tier, Renewal Date, Status.\n\n**Requirements**\n\n- Stripe account\n- Pinecone account with tier knowledge base\n- OpenAI account\n- Gmail account\n- Google Sheets"
      },
      "typeVersion": 1
    },
    {
      "id": "0a171bc4-e9a3-4c8c-95d1-0861735d8fcd",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -192,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 304,
        "height": 832,
        "content": "**1. Stripe Payment Trigger**"
      },
      "typeVersion": 1
    },
    {
      "id": "79eccdfe-82ee-40b2-a58c-8a09e689488e",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        144,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 208,
        "height": 832,
        "content": "**2. Extract Customer Details**"
      },
      "typeVersion": 1
    },
    {
      "id": "4a0e6770-d018-4fb2-a6b7-54dbf901492f",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        384,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 384,
        "height": 832,
        "content": "**3. AI Email Generation**"
      },
      "typeVersion": 1
    },
    {
      "id": "5d6df43b-c6a2-438c-ab1c-86016e3cd93b",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        784,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 576,
        "height": 832,
        "content": "**4. Send & Log**"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "",
  "connections": {
    "GPT-4o": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Parse AI Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pinecone Tool": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Stripe Trigger": {
      "main": [
        [
          {
            "node": "Amount conversion",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse AI Output": {
      "main": [
        [
          {
            "node": "Send Welcome Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get user_details": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Amount conversion": {
      "main": [
        [
          {
            "node": "Get user_details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Embeddings": {
      "ai_embedding": [
        [
          {
            "node": "Pinecone Tool",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Send Welcome Email": {
      "main": [
        [
          {
            "node": "Log customer details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}