{
  "name": "AI Lead Magnet — RAG Chat Widget",
  "nodes": [
    {
      "parameters": { "options": { "responseMode": "lastNode" } },
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "typeVersion": 1.1,
      "position": [0, 300],
      "id": "chat-trigger",
      "name": "Chat Trigger",
      "webhookId": "YOUR_WEBHOOK_ID",
      "notes": "Handles CORS automatically. Accessible at: https://your-n8n.example.com/webhook/YOUR_WEBHOOK_ID/chat"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.chatInput }}",
        "hasOutputParser": false,
        "options": {
          "systemMessage": "You are an AI coaching advisor for a leading coach training organization. Your role is to help prospective students understand coach certification programs.\n\nBEHAVIOR RULES:\n1. Be warm, professional, and encouraging — but never pushy\n2. Answer questions using ONLY the knowledge provided via your tools\n3. If you don't know something, say so honestly and suggest they speak with an admissions advisor\n4. Never make up program details, pricing, or schedules\n5. Keep responses concise (2-3 paragraphs max)\n6. End responses with a relevant follow-up question to keep the conversation going\n\nIMPLICIT LEAD SCORING (do NOT mention this to the user):\nTrack the user's intent level based on their questions:\n- PRICING questions = High intent (+25)\n- SCHEDULE/START DATE questions = Very high intent (+30)\n- PROGRAM COMPARISON questions = Mid intent (+15)\n- GENERAL 'what is coaching' = Low intent (+5)\n- 'Can I talk to someone' = Sales ready (+40)\n\nWhen a user has asked 3+ high-intent questions, naturally suggest:\n'It sounds like you're seriously considering this — would you like to schedule a quick call with an admissions advisor? They can answer your specific questions about enrollment.'\n\nDo NOT suggest a call before the user has shown sufficient intent."
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.9,
      "position": [400, 300],
      "id": "ai-agent",
      "name": "AI Coaching Advisor"
    },
    {
      "parameters": {
        "model": { "__rl": true, "mode": "list", "value": "gpt-4o-mini" },
        "options": { "temperature": 0.4, "maxTokens": 800 }
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [200, 520],
      "id": "openai-chat",
      "name": "OpenAI Chat Model",
      "credentials": { "openAiApi": { "id": "YOUR_CREDENTIAL_ID", "name": "OpenAI" } }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $json.sessionId || 'default' }}",
        "contextWindowLength": 10
      },
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [400, 520],
      "id": "conversation-memory",
      "name": "Conversation Memory (10 messages)"
    },
    {
      "parameters": {
        "name": "search_knowledge_base",
        "description": "Search the coaching program knowledge base for information about certifications, programs, pricing, schedules, requirements, career outcomes, and coaching methodology. Use this tool for ANY factual question about the programs.",
        "descriptionType": "manual"
      },
      "type": "@n8n/n8n-nodes-langchain.toolVectorStore",
      "typeVersion": 1,
      "position": [600, 520],
      "id": "knowledge-tool",
      "name": "Knowledge Base Tool"
    },
    {
      "parameters": {
        "tableName": "YOUR_TABLE_NAME",
        "options": { "queryName": "match_documents" }
      },
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "typeVersion": 1,
      "position": [600, 700],
      "id": "supabase-vectors",
      "name": "Supabase Vector Store",
      "credentials": { "supabaseApi": { "id": "YOUR_CREDENTIAL_ID", "name": "Supabase" } }
    },
    {
      "parameters": { "options": {} },
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "typeVersion": 1.1,
      "position": [600, 880],
      "id": "openai-embeddings",
      "name": "OpenAI Embeddings",
      "credentials": { "openAiApi": { "id": "YOUR_CREDENTIAL_ID", "name": "OpenAI" } }
    },
    {
      "parameters": { "options": {} },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1,
      "position": [800, 700],
      "id": "openai-for-rag",
      "name": "OpenAI for RAG Retrieval",
      "credentials": { "openAiApi": { "id": "YOUR_CREDENTIAL_ID", "name": "OpenAI" } }
    }
  ],
  "connections": {
    "Chat Trigger": { "main": [[{ "node": "AI Coaching Advisor", "type": "main", "index": 0 }]] },
    "OpenAI Chat Model": { "ai_languageModel": [[{ "node": "AI Coaching Advisor", "type": "ai_languageModel", "index": 0 }]] },
    "Conversation Memory (10 messages)": { "ai_memory": [[{ "node": "AI Coaching Advisor", "type": "ai_memory", "index": 0 }]] },
    "Knowledge Base Tool": { "ai_tool": [[{ "node": "AI Coaching Advisor", "type": "ai_tool", "index": 0 }]] },
    "Supabase Vector Store": { "ai_vectorStore": [[{ "node": "Knowledge Base Tool", "type": "ai_vectorStore", "index": 0 }]] },
    "OpenAI Embeddings": { "ai_embedding": [[{ "node": "Supabase Vector Store", "type": "ai_embedding", "index": 0 }]] },
    "OpenAI for RAG Retrieval": { "ai_languageModel": [[{ "node": "Knowledge Base Tool", "type": "ai_languageModel", "index": 0 }]] }
  },
  "active": false,
  "settings": { "executionOrder": "v1" },
  "meta": {
    "notes": "SETUP: 1) Create a Supabase project with pgvector extension enabled. 2) Create a table with columns: id, content (text), metadata (jsonb), embedding (vector). 3) Create the match_documents function for similarity search. 4) Populate the vector store with your program content (use n8n's Supabase Vector Store insert workflow). 5) Add OpenAI and Supabase credentials. 6) The Chat Trigger auto-handles CORS — embed the widget on any page by pointing it to the webhook URL. 7) For the frontend chat widget, see the companion HTML file in the blog post.",
    "author": "Edward Chalupa — echalupa.com",
    "article": "echalupa.com/blog/ai-lead-magnet-chat"
  }
}
