{
  "name": "Activity 5 \u2014 Website Chatbot via Webhook (Investment Advisor)",
  "nodes": [
    {
      "parameters": {
        "path": "investment-enquiry",
        "responseMode": "responseNode",
        "options": {
          "allowedOrigins": "*"
        },
        "httpMethod": "POST"
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        128,
        144
      ],
      "id": "fff43c41-4540-42c9-800e-01ca10ce3ed7",
      "name": "Enquiry Webhook"
    },
    {
      "parameters": {
        "jsCode": "const q = $json.body || $json.query || {};\n\n// The website posts the destination inbox as adminEmail. Fall back to a\n// hard-coded address here if you prefer to fix it in the workflow instead.\nconst ADVISOR_FALLBACK = '';\nconst advisorEmail = (q.adminEmail || ADVISOR_FALLBACK || '').trim();\n\nconst lead = {\n  type: q.type || 'enquiry',\n  name: q.name || '',\n  email: q.email || '',\n  phone: q.phone || '',\n  goal: q.goal || '',\n  message: q.message || '',\n  advisorEmail,\n  submittedAt: new Date().toISOString(),\n};\n\nif (!advisorEmail) {\n  throw new Error('No advisor email supplied. Enter an Admin email in the website setup panel, or set ADVISOR_FALLBACK in this node.');\n}\n\nlead.emailSubject = `New investment enquiry from ${lead.name || 'website visitor'}`;\nlead.emailMessage = [\n  'New investment advisory enquiry received from the website.',\n  '',\n  `Name: ${lead.name}`,\n  `Email: ${lead.email}`,\n  `Phone: ${lead.phone}`,\n  `Investment Goal: ${lead.goal}`,\n  '',\n  'Message:',\n  lead.message,\n  '',\n  `Submitted: ${lead.submittedAt}`,\n].join('\\n');\n\nlead.success = true;\nlead.responseMessage = 'Thank you. Your enquiry has been received.';\nreturn [{ json: lead }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        368,
        144
      ],
      "id": "fb3a491b-c18c-46b1-89e7-493f8d64ae57",
      "name": "Format Enquiry"
    },
    {
      "parameters": {
        "sendTo": "={{ $json.advisorEmail }}",
        "subject": "={{ $json.emailSubject }}",
        "message": "={{ $json.emailMessage }}",
        "options": {}
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.2,
      "position": [
        608,
        144
      ],
      "id": "03a1b469-9dc1-41a5-be1c-1743b8583bba",
      "name": "Email Advisor",
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "return [{\n  json: {\n    success: true,\n    message: 'Thank you. Your enquiry has been received.'\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        848,
        144
      ],
      "id": "5138b97e-27b3-4524-8204-ed991cc3497d",
      "name": "Enquiry Response Body"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json }}",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.5,
      "position": [
        1104,
        144
      ],
      "id": "0903c4fa-b3e6-4808-83c8-18fb4e96f314",
      "name": "Respond to Enquiry"
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "investment-chat",
        "responseMode": "responseNode",
        "options": {
          "allowedOrigins": "*"
        }
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        128,
        640
      ],
      "id": "3120b723-068c-4c04-a1fc-c71f3f65b716",
      "name": "Chat Webhook"
    },
    {
      "parameters": {
        "jsCode": "const body = $json.body || $json;\nreturn [{\n  json: {\n    type: body.type || 'chat',\n    message: body.message || '',\n    name: body.name || '',\n    phone: body.phone || body.tel || '',\n    email: body.email || '',\n    source: body.source || 'investment-advisor-website',\n    sessionId: body.sessionId || body.email || body.phone || body.source || 'investment-advisor-website'\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        368,
        640
      ],
      "id": "0b90c456-b480-4748-a222-ffaa94e5be77",
      "name": "Normalize Chat Message"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ ['Visitor contact details:', 'Name: ' + ($json.name || ''), 'Telephone: ' + ($json.phone || ''), 'Email: ' + ($json.email || ''), '', 'Visitor question:', $json.message || ''].join('\\n') }}",
        "options": {
          "systemMessage": "You are a professional investment advisor assistant for a lead magnet website. Always make sure the visitor has first provided full name, telephone number, and email address so a licensed advisor can get back to them. If any of those details are missing, politely ask for the missing details before answering the investment question. Once contact details are available, answer using concise FAQ-style guidance.\n\nCompliance rules: answer general investment-related questions only. Explain financial planning concepts clearly. Do not promise guaranteed returns. Do not recommend specific stocks, funds, products, or exact buy/sell actions. Do not provide personalised financial advice or regulated financial recommendations. Encourage the visitor to book a consultation and remind them to speak with a licensed advisor before making investment decisions.\n\nFAQ guidance to use in replies:\nQ: What can an investment advisor help with?\nA: Goal setting, risk profiling, portfolio review, diversification, retirement planning, education planning, and long-term wealth planning.\nQ: Is the consultation free?\nA: The initial consultation is free and helps clarify goals, time horizon, risk comfort, and next steps.\nQ: Can you guarantee returns?\nA: No. Investments carry risk and returns are not guaranteed.\nQ: Can you tell me which stock to buy?\nA: No. The chatbot cannot provide stock tips or personalised recommendations. A licensed advisor can review the visitor's situation in a consultation.\nQ: What should I prepare before speaking with an advisor?\nA: Current investment holdings, monthly savings capacity, goals, time horizon, risk comfort, debts, insurance coverage, and major financial commitments.\nQ: How does diversification help?\nA: Diversification spreads exposure across assets or sectors and can reduce concentration risk, but it does not remove investment risk.\nQ: What is long-term investing?\nA: Long-term investing focuses on disciplined planning over multiple years, regular reviews, and alignment with goals rather than short-term market timing."
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        608,
        640
      ],
      "id": "8f25b2df-0f87-4300-9464-68b31e5748a8",
      "name": "Investment Advisor AI"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4.1-mini",
          "mode": "list",
          "cachedResultName": "gpt-4.1-mini"
        },
        "builtInTools": {},
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        480,
        880
      ],
      "id": "a2b8241d-7304-47e7-8e97-83c52f1fb4c1",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $json.sessionId }}"
      },
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.4,
      "position": [
        688,
        880
      ],
      "id": "67156c10-6ff1-47a7-9eb2-fc4dca44f11d",
      "name": "Website Chat Memory"
    },
    {
      "parameters": {
        "jsCode": "const reply = $json.output || $json.text || $json.reply || $json.message || 'Thank you. Our advisor will get back to you shortly.';\nreturn [{ json: { reply } }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        976,
        640
      ],
      "id": "e31d3bb5-d9c3-4b96-adb7-0376aca1cd81",
      "name": "Chat Response Body"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json }}",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.5,
      "position": [
        1216,
        640
      ],
      "id": "fed91bd0-c531-4eba-9831-d981b36fe165",
      "name": "Respond to Chat"
    },
    {
      "parameters": {
        "content": "## Enquiry Form\nGET requests from the website form read query parameters, email the advisor, and return a success JSON response.",
        "height": 360,
        "width": 1260
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "id": "10783a57-87c0-4090-90fa-d50d8916c5ec",
      "name": "Enquiry Note"
    },
    {
      "parameters": {
        "content": "## Chatbot\nPOST requests read the JSON body, apply the investment compliance system prompt, call the AI model, and return { reply }.",
        "height": 536,
        "width": 1360
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        0,
        496
      ],
      "id": "00d64a16-26dc-4f65-bacc-7ebd09c455d4",
      "name": "Chatbot Note"
    }
  ],
  "connections": {
    "Enquiry Webhook": {
      "main": [
        [
          {
            "node": "Format Enquiry",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Enquiry": {
      "main": [
        [
          {
            "node": "Email Advisor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email Advisor": {
      "main": [
        [
          {
            "node": "Enquiry Response Body",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enquiry Response Body": {
      "main": [
        [
          {
            "node": "Respond to Enquiry",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Chat Webhook": {
      "main": [
        [
          {
            "node": "Normalize Chat Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Chat Message": {
      "main": [
        [
          {
            "node": "Investment Advisor AI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Investment Advisor AI": {
      "main": [
        [
          {
            "node": "Chat Response Body",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Investment Advisor AI",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Website Chat Memory": {
      "ai_memory": [
        [
          {
            "node": "Investment Advisor AI",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Chat Response Body": {
      "main": [
        [
          {
            "node": "Respond to Chat",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": false
  },
  "versionId": "9063443a-3be3-471b-9409-0da1f7146d16",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodeGroups": [],
  "id": "w76yfcA3Um3gU1UR",
  "tags": []
}