{
  "id": "XD13YYXBD3REvwUy",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "AI Sales Chatbot: RAG, Lead Capture, Scoring, CRM and DB Sync, and Slack Alerts",
  "tags": [
    {
      "id": "94yO3JL7wpOZjk3A",
      "name": "AI Chatbot",
      "createdAt": "2025-10-22T11:21:35.499Z",
      "updatedAt": "2025-10-22T11:21:35.499Z"
    },
    {
      "id": "G2fbfHeKIPv2Lpo9",
      "name": "RAG",
      "createdAt": "2025-11-05T11:27:13.020Z",
      "updatedAt": "2025-11-05T11:27:13.020Z"
    },
    {
      "id": "W01fUigEbpzoMJlg",
      "name": "Lead Capture",
      "createdAt": "2025-11-05T11:27:38.370Z",
      "updatedAt": "2025-11-05T11:27:38.370Z"
    },
    {
      "id": "fQJMELuV9jzEHujv",
      "name": "Customer Support",
      "createdAt": "2025-11-05T11:27:35.406Z",
      "updatedAt": "2025-11-05T11:27:35.406Z"
    },
    {
      "id": "qZx9OTwt2STp2V9s",
      "name": "Identity Verification",
      "createdAt": "2025-11-05T11:27:46.110Z",
      "updatedAt": "2025-11-05T11:27:46.110Z"
    }
  ],
  "nodes": [
    {
      "id": "de3b285e-4006-421a-b580-f4e05c1e129c",
      "name": "Chat Trigger",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        -1712,
        256
      ],
      "parameters": {
        "options": {
          "responseMode": "responseNodes"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "38e2375a-e033-4309-9694-bef4dd59628b",
      "name": "Vector Store",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "position": [
        -176,
        512
      ],
      "parameters": {
        "mode": "retrieve-as-tool",
        "topK": 30,
        "options": {},
        "tableName": {
          "__rl": true,
          "mode": "list",
          "value": "documents",
          "cachedResultName": "documents"
        },
        "useReranker": true,
        "toolDescription": "Use this tool to search for information about [COMPANY] to answer the user's question/concern/feedback/enquiry."
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "3e75814d-af98-41c0-9f7e-7f8c6a9f70e6",
      "name": "Embeddings",
      "type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
      "position": [
        -256,
        704
      ],
      "parameters": {},
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "a9eda68f-bb97-41bb-b9f5-117190c583ad",
      "name": "Reranker",
      "type": "@n8n/n8n-nodes-langchain.rerankerCohere",
      "position": [
        -96,
        704
      ],
      "parameters": {
        "topN": 4
      },
      "credentials": {
        "cohereApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "1e749878-5772-4b12-ab65-da65ddad4a53",
      "name": "Supabase Upsert - Save User Identity",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        -1200,
        512
      ],
      "parameters": {
        "url": "https://YOUR_PROJECT_REF.supabase.co/rest/v1/chat_users",
        "fields": "session_id,name,email",
        "method": "POST",
        "options": {},
        "jsonBody": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('JSON', ``, 'json') }}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "fieldsToInclude": "selected",
        "toolDescription": "=Makes an HTTP request to Supabase to UPSERT a record. Take the chat message details and extract the session_id, name, and/or email, and UPSERT them in the correct JSON body format for your response. Make sure the name starts with a capital letter.",
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "YOUR_SUPABASE_API_KEY"
            },
            {
              "name": "Authorization",
              "value": "Bearer YOUR_TOKEN_HERE"
            },
            {
              "name": "Prefer",
              "value": "resolution=merge-duplicates,return=representation"
            }
          ]
        },
        "optimizeResponse": true
      },
      "typeVersion": 4.2
    },
    {
      "id": "87e3c640-3f98-4efc-95c0-bb379bcc000e",
      "name": "Check Identity In DB",
      "type": "n8n-nodes-base.supabase",
      "position": [
        -1408,
        256
      ],
      "parameters": {
        "filters": {
          "conditions": [
            {
              "keyName": "session_id",
              "keyValue": "={{ $json.sessionId }}",
              "condition": "eq"
            }
          ]
        },
        "tableId": "chat_users",
        "operation": "getAll"
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "f4ac6301-a6a1-488c-a984-0116f24f5493",
      "name": "Respond to Chat",
      "type": "@n8n/n8n-nodes-langchain.chat",
      "position": [
        -608,
        256
      ],
      "parameters": {
        "message": "={{ $json.output }}",
        "options": {},
        "waitUserReply": false
      },
      "typeVersion": 1
    },
    {
      "id": "schedule-trigger-scoring",
      "name": "Schedule Trigger - Score Leads",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -1680,
        1072
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 10
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "if-has-leads",
      "name": "If Has Leads",
      "type": "n8n-nodes-base.if",
      "position": [
        -1008,
        1072
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "has-items",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $input.all().length }}",
              "rightValue": 0
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "filter-leads-to-score",
      "name": "Filter Leads Ready to Score",
      "type": "n8n-nodes-base.filter",
      "position": [
        -1232,
        1072
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "scored-false",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.scored }}",
              "rightValue": "false"
            },
            {
              "id": "7fdf21d9-f1d2-4ba4-9420-7b28b2490620",
              "operator": {
                "type": "boolean",
                "operation": "false",
                "singleValue": true
              },
              "leftValue": "={{ new Date($json.score_after) < new Date() }}",
              "rightValue": "false"
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "d5680ad8-dec2-42d1-a995-6ac65bc076cb",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -800,
        1264
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "fb8897d0-e7fd-43a6-bcb7-40900d792771",
      "name": "Google Gemini Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -1552,
        512
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "af48ecde-f603-42b6-ac5c-d5538aa1f5d4",
      "name": "Postgres Chat Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "position": [
        -1376,
        512
      ],
      "parameters": {
        "tableName": "chat_memory"
      },
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "gs-get-leads-to-score",
      "name": "Get All Leads",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -1456,
        1072
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 348462050,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1GJdgFLrKpjg3oyUvieW1mIbN7vWnJC2yxaEbwbAllbw/edit#gid=348462050",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1GJdgFLrKpjg3oyUvieW1mIbN7vWnJC2yxaEbwbAllbw",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1GJdgFLrKpjg3oyUvieW1mIbN7vWnJC2yxaEbwbAllbw/edit?usp=drivesdk",
          "cachedResultName": "leads_template"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "gs-mark-as-scored",
      "name": "Mark as Scored",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -384,
        1056
      ],
      "parameters": {
        "columns": {
          "value": {
            "email": "={{ $('Get All Leads').item.json.email }}",
            "scored": "TRUE"
          },
          "schema": [
            {
              "id": "email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "lead_score",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "lead_score",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "lead_status",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "lead_status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "interests",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "interests",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "conversation_summary",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "conversation_summary",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "notes",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "notes",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "last_message_at",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "last_message_at",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "score_after",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "score_after",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "scored",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "scored",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "created_at",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "created_at",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "email"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 348462050,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1GJdgFLrKpjg3oyUvieW1mIbN7vWnJC2yxaEbwbAllbw/edit#gid=348462050",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1GJdgFLrKpjg3oyUvieW1mIbN7vWnJC2yxaEbwbAllbw",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1GJdgFLrKpjg3oyUvieW1mIbN7vWnJC2yxaEbwbAllbw/edit?usp=drivesdk",
          "cachedResultName": "leads_template"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "c332f4d1-d44f-47bf-a028-3765533768ea",
      "name": "Update row in Google Sheets CRM",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        -672,
        512
      ],
      "parameters": {
        "columns": {
          "value": {
            "email": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('email__using_to_match_', ``, 'string') }}",
            "notes": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('notes', ``, 'string') }}",
            "scored": "FALSE",
            "interests": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('interests', ``, 'string') }}",
            "score_after": "={{ $now.plus({minutes: 30}).toISO() }}",
            "last_message_at": "={{ $now.toISO() }}",
            "conversation_summary": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('conversation_summary', ``, 'string') }}"
          },
          "schema": [
            {
              "id": "email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "name",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "lead_score",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "lead_score",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "lead_status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "lead_status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "interests",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "interests",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "conversation_summary",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "conversation_summary",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "notes",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "notes",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "last_message_at",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "last_message_at",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "score_after",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "score_after",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "scored",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "scored",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "created_at",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "created_at",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "number",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "email"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 348462050,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1GJdgFLrKpjg3oyUvieW1mIbN7vWnJC2yxaEbwbAllbw/edit#gid=348462050",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1GJdgFLrKpjg3oyUvieW1mIbN7vWnJC2yxaEbwbAllbw",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1GJdgFLrKpjg3oyUvieW1mIbN7vWnJC2yxaEbwbAllbw/edit?usp=drivesdk",
          "cachedResultName": "leads_template"
        },
        "descriptionType": "manual",
        "toolDescription": "=Update an existing lead's information in the CRM.\n\nUse this tool after any meaningful conversation exchange to record:\n- interests: Topics they asked about (append to existing)\n- conversation_summary: Brief summary of the full conversation so far\n- notes: Any relevant details (budget, timeline, company mentioned, etc.)\n\nMatch by email - the lead must already exist in the sheet.\nWorks for both NEW leads (after Append) and RETURNING users."
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "676d4a0b-d61d-4691-bf57-7777d1497398",
      "name": "Update row in Google Sheets CRM (2)",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        -608,
        1264
      ],
      "parameters": {
        "columns": {
          "value": {
            "email": "={{ $('Get All Leads').item.json.email }}",
            "lead_score": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('lead_score', ``, 'string') }}",
            "lead_status": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('lead_status', ``, 'string') }}"
          },
          "schema": [
            {
              "id": "email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "lead_score",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "lead_score",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "lead_status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "lead_status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "interests",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "interests",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "conversation_summary",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "conversation_summary",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "notes",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "notes",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "last_message_at",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "last_message_at",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "score_after",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "score_after",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "scored",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "scored",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "created_at",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "created_at",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "number",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "email"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 348462050,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1GJdgFLrKpjg3oyUvieW1mIbN7vWnJC2yxaEbwbAllbw/edit#gid=348462050",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1GJdgFLrKpjg3oyUvieW1mIbN7vWnJC2yxaEbwbAllbw",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1GJdgFLrKpjg3oyUvieW1mIbN7vWnJC2yxaEbwbAllbw/edit?usp=drivesdk",
          "cachedResultName": "leads_template"
        },
        "descriptionType": "manual",
        "toolDescription": "Set the lead_score and lead_status"
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "check-lead-exists-crm",
      "name": "Check if Lead Exists in CRM",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        -1008,
        512
      ],
      "parameters": {
        "options": {
          "returnFirstMatch": true
        },
        "filtersUI": {
          "values": [
            {
              "lookupValue": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('email_to_lookup', 'The email address to check in the CRM', 'string') }}",
              "lookupColumn": "email"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 348462050,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1GJdgFLrKpjg3oyUvieW1mIbN7vWnJC2yxaEbwbAllbw/edit#gid=348462050",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1GJdgFLrKpjg3oyUvieW1mIbN7vWnJC2yxaEbwbAllbw",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1GJdgFLrKpjg3oyUvieW1mIbN7vWnJC2yxaEbwbAllbw/edit?usp=drivesdk",
          "cachedResultName": "leads_template"
        },
        "descriptionType": "manual",
        "toolDescription": "Check if a lead with this email already exists in the CRM.\n\nCALL THIS TOOL FIRST when a user provides their email address, BEFORE deciding to use Append or Update.\n\nReturns:\n- If lead EXISTS: Returns the lead's row data (email, name, created_at, etc.)\n- If lead NOT FOUND: Returns empty result\n\nBased on the result:\n- Empty result \u2192 Lead is NEW \u2192 Use 'Append row in Google Sheets CRM'\n- Has data \u2192 Lead EXISTS \u2192 Use 'Update row in Google Sheets CRM' only"
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "6567e584-ff64-4523-8c7f-797dc9cab9d1",
      "name": "Append row in Google Sheets CRM",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        -848,
        512
      ],
      "parameters": {
        "columns": {
          "value": {
            "name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('name', ``, 'string') }}",
            "email": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('email', ``, 'string') }}",
            "scored": "FALSE",
            "created_at": "={{ $now.toISO() }}",
            "score_after": "={{ $now.plus({minutes: 30}).toISO() }}",
            "last_message_at": "={{ $now.toISO() }}"
          },
          "schema": [
            {
              "id": "email",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "lead_score",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "lead_score",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "lead_status",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "lead_status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "interests",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "interests",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "conversation_summary",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "conversation_summary",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "notes",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "notes",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "last_message_at",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "last_message_at",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "score_after",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "score_after",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "scored",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "scored",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "created_at",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "created_at",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 348462050,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1GJdgFLrKpjg3oyUvieW1mIbN7vWnJC2yxaEbwbAllbw/edit#gid=348462050",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1GJdgFLrKpjg3oyUvieW1mIbN7vWnJC2yxaEbwbAllbw",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1GJdgFLrKpjg3oyUvieW1mIbN7vWnJC2yxaEbwbAllbw/edit?usp=drivesdk",
          "cachedResultName": "leads_template"
        },
        "descriptionType": "manual",
        "toolDescription": "Create a NEW lead record in the CRM.\n\nPREREQUISITE: You MUST call 'Check if Lead Exists in CRM' FIRST!\n\nONLY use this tool when:\n- You already called 'Check if Lead Exists in CRM' with the email\n- AND that check returned EMPTY (no data found)\n\nNEVER use this tool if:\n- You haven't checked the CRM first\n- The check returned existing data (lead already exists)\n\nFields: email, name, created_at (auto-set to current time)"
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "85c41b38-d5b2-4f26-aed9-833e3f8911b2",
      "name": "AI Support Specialist",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -1056,
        256
      ],
      "parameters": {
        "text": "={{ $('Chat Trigger').item.json.chatInput }}",
        "options": {
          "systemMessage": "=# OVERVIEW\nYou are [AI AGENT NAME], an AI Sales Assistant for [COMPANY] (a company specializing in [YOUR SERVICES/PRODUCTS/SOLUTIONS]). You help answer questions based on what's in the knowledge base AND you help capture and qualify leads. Greet and introduce yourself briefly ONLY upon receiving the first message.\n\n## CURRENT USER IDENTITY STATUS\n  - Name: {{ $json.name || 'NOT PROVIDED YET' }}\n  - Email: {{ $json.email || 'NOT PROVIDED YET' }}\n  - Session ID: {{ $('Chat Trigger').item.json.sessionId }}\n\n## CRITICAL REQUIREMENTS\n1. Before answering ANY questions, you MUST have BOTH the user's name AND email.\n2. If either is 'NOT PROVIDED YET', ask for the missing information naturally, conversationally, and in a kind yet concise manner.\n3. When the user provides their email address:\n   a) FIRST: Call 'Check if Lead Exists in CRM' tool with their email\n   b) Check the result:\n      - If EMPTY (no data returned) \u2192 Lead is NEW \u2192 Call 'Append row in Google Sheets CRM'\n      - If HAS DATA (row returned) \u2192 Lead EXISTS \u2192 Skip Append, go straight to Update\n   c) Call 'Supabase Upsert - Save User Identity' tool with: name, email, and session_id\n   d) Call 'Update row in Google Sheets CRM' tool to update interests, conversation_summary, and notes\n   e) Call 'Slack Alert - New Lead and Intent' tool to notify the sales team\n4. Once you have name and email stored, answer their questions using the company knowledge base\n5. Be natural, kind, concise, and professional\n6. Focus on brevity when providing answers\n\n## GOOGLE SHEET CRM TOOLS\n\n### Check if Lead Exists in CRM (CALL THIS FIRST!)\n**Purpose:** Check if email already exists in the CRM\n**When to use:** ALWAYS call this FIRST when user provides their email\n**Returns:** Row data if exists, empty if not found\n**CRITICAL:** This determines whether to Append or just Update!\n\n### Append row in Google Sheets CRM\n**Purpose:** Create a NEW lead record\n**When to use:** ONLY if 'Check if Lead Exists in CRM' returned EMPTY (no data)\n**What it writes:** email, name, created_at (auto-set)\n**NEVER use if:** The lookup tool returned existing data\n\n### Update row in Google Sheets CRM\n**Purpose:** Update an EXISTING lead's conversation data\n**When to use:** After EVERY meaningful interaction\n**What it writes:** interests, conversation_summary, notes\n\n## TOOL SEQUENCE WHEN USER PROVIDES EMAIL\n1. Check if Lead Exists in CRM (with their email)\n2. IF empty result \u2192 Append row in Google Sheets CRM (create new lead)\n3. Supabase Upsert - Save User Identity\n4. Update row in Google Sheets CRM (update conversation data)\n5. Slack Alert - New Lead and Intent\n\n## WHEN TO USE SLACK TOOL\n- **Slack - Notify Sales**: When user explicitly asks for pricing, requests a demo, says they're ready to buy, or mentions urgent timeline\n\n## LEAD QUALIFICATION SIGNALS (Listen for anything like this!)\nHigh-value signals that should trigger sales notification:\n- Budget mentions (\"what's the pricing?\", \"within our budget\", \"how much does it cost?\")\n- Urgency (\"need this ASAP\", \"starting next month\", \"urgent requirement\")\n- Decision-maker language (\"my team\", \"I can approve\", \"we're evaluating options\")\n- Specific feature/product questions (indicates serious research)\n- Demo or trial requests\n\n## INSTRUCTIONS\n- Check the identity status above at the start of each response\n- If name or email is missing, ask for it kindly in a conversational yet concise way\n- If asked \"why?\", explain it helps personalize their experience and enables follow-up\n- ALWAYS check CRM for existing lead BEFORE creating a new one\n- When user asks questions, shows intent, or shares information, update their Google Sheet CRM record\n- Notify sales if high-intent signals detected\n- Only answer company questions after identity is complete\n- Use the Vector Store tool to search company documents for answers\n- Be helpful and concise\n- Use \"we\", \"ours\", \"us\" naturally when referring to [COMPANY]"
        },
        "promptType": "define"
      },
      "typeVersion": 3.1
    },
    {
      "id": "01b65962-597c-4d22-b817-82657b15696c",
      "name": "AI Leader Scorer",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -752,
        1056
      ],
      "parameters": {
        "text": "=lead's email: {{ $json.email }}\n\nConversation Summary:\n{{ $json.conversation_summary }}\n\nInterests:\n{{ $json.interests }}\n\nNotes:\n{{ $json.notes }}\n",
        "options": {
          "systemMessage": "# Lead Scoring Analyst\n\nAnalyze the chat conversation and score the lead from 1-10 based on buying signals.\n\n## Scoring Guide\n\n| Score | Level | Signals |\n|-------|-------|---------|\n| **8-10** | Hot | Pricing questions, demo requests, \"ready to buy\", urgency |\n| **5-7** | Warm | Multiple questions, team/company mentions, specific feature interest |\n| **3-4** | Cold | Basic questions, early research, \"just looking\" |\n| **1-2** | New | Only provided name/email, minimal interaction |\n\n## Key Signals to Look For\n\n**High Intent (+2-3 points)**\n- Asks about pricing or cost\n- Requests demo or trial\n- Mentions urgency or deadlines\n\n**Medium Intent (+1-2 points)**\n- Mentions their team or company\n- Asks multiple follow-up questions\n- Discusses specific use cases\n\n**Low Intent (+0-1 points)**\n- Only greeted and provided contact info\n- Single generic question\n- Says \"just browsing\" or \"maybe later\"\n\n## Your Task\n\n1. The email provided corresponds to a lead in the Google Sheets CRM\n2. Analyze the conversation associated with this session\n3. Identify buying signals present\n4. Calculate a score from 1-10\n5. **Use the \"Google Sheets Score Tool\"** to update the lead record with:\n   - **lead_score**: Number 1-10\n   - **lead_status**: \"Hot\", \"Warm\", \"Cold\"\n\n## Important\n- You MUST use the Google Sheets Score Tool to save the scoring results"
        },
        "promptType": "define"
      },
      "typeVersion": 3.1
    },
    {
      "id": "e5a1ca3a-8d83-44f9-af34-254633f927fc",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1808,
        -240
      ],
      "parameters": {
        "color": 7,
        "width": 1408,
        "height": 336,
        "content": "## Sample Output\n\n### Google Sheets CRM updated \n**Creates a new row for a new lead, or updates an existing row for an existing lead. Enters details about the chat, and scores the lead.**\n[Link to Google Sheets CRM sample file](https://docs.google.com/spreadsheets/d/1GJdgFLrKpjg3oyUvieW1mIbN7vWnJC2yxaEbwbAllbw/edit?usp=sharing)\n\n![](https://i.postimg.cc/pV943SPC/lead-crm-record-scored.png)"
      },
      "typeVersion": 1
    },
    {
      "id": "5da9a309-2b23-46cf-b7ce-c7a4cb2f194d",
      "name": "Slack Alert - New Lead and Intent",
      "type": "n8n-nodes-base.slackTool",
      "position": [
        -496,
        512
      ],
      "parameters": {
        "text": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Message_Text', ``, 'string') }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C09G7DR7X52",
          "cachedResultName": "talent"
        },
        "otherOptions": {},
        "authentication": "oAuth2",
        "descriptionType": "manual",
        "toolDescription": "Send a message in Slack to alert the sales team that a new lead has arrived. Make sure to provide their name and email address. \n\nSend a message in Slack if the lead is asking about anything worthy of the sales team's attention (buying intent, pricing, timelines, etc)."
      },
      "credentials": {
        "slackOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.4
    },
    {
      "id": "ceab145b-1968-4990-a00e-1be96e3de4ef",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1808,
        128
      ],
      "parameters": {
        "color": 5,
        "width": 1968,
        "height": 756,
        "content": "## 1. AI Chat with Lead Capture\nLead messages trigger identity verification, RAG-powered responses, CRM updates, and Slack alerts for high-intent leads."
      },
      "typeVersion": 1
    },
    {
      "id": "d3d922c3-ee9a-4de1-b122-97711de27767",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1808,
        912
      ],
      "parameters": {
        "color": 4,
        "width": 1968,
        "height": 592,
        "content": "## 2. AI-Powered Lead Qualification\nPeriodically scores leads based on conversation history - pricing questions, demo requests, and urgency signals drive higher scores."
      },
      "typeVersion": 1
    },
    {
      "id": "10b4a954-9f75-4a0d-84e3-5f9001bc8d07",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2704,
        -240
      ],
      "parameters": {
        "width": 864,
        "height": 1264,
        "content": "# AI Sales Chatbot: RAG, Lead Capture, Scoring, CRM and DB Sync, and Slack Alerts\n\nTurn your website chat into a lead-generating machine. Visitors chat with an AI that answers questions from your knowledge base, captures their contact info, syncs everything to Google Sheets, and automatically scores leads based on buying signals - all without manual intervention.\n\n## What it does\n- Gates conversations behind identity capture (requires name + email before answering questions)\n- Saves user identity to Supabase per session (name, email, session_id)\u2014supports updates if user changes their email\n- Answers visitor questions using RAG from your Supabase vector store with Cohere reranking\n- Detects new vs returning leads by email (prevents duplicate CRM entries)\n- Creates/updates lead records in Google Sheets with:\n  - Contact info (name, email, created date)\n  - Conversation insights (interests, summary, notes)\n  - Scoring metadata (last message time, score timer)\n- Sends Slack alerts when high-intent signals detected (pricing questions, demo requests, urgency)\n- Runs automated lead scoring every 10 minutes:\n  - Finds leads inactive for 30+ minutes\n  - AI analyzes conversation and assigns score (1-10) + status (Hot/Warm/Cold)\n  - Writes results back to Google Sheets\n\n## Requirements\n- Google Sheets OAuth2 credentials\n- Supabase account (for vector store + identity storage)\n- Google Gemini API key\n- Cohere API key (for reranking)\n- Slack OAuth2 credentials\n- Postgres database (for chat memory)\n- A Google Sheet with columns: email, name, lead_score, lead_status, interests, conversation_summary, notes, last_message_at, score_after, scored, created_at\n\n## Setup\n1. Create your Google Sheet with the required columns (or duplicate the template structure)\n2. Set up Supabase tables: `chat_users` (session_id, name, email), `documents` (vector store), `chat_memory` (conversation history)\n3. Connect all credentials to their respective nodes (Google Sheets, Supabase, Gemini, Cohere, Slack, Postgres)\n4. Update the AI agent prompts: replace `[AI AGENT NAME]`, `[COMPANY]`, and `[YOUR SERVICES/PRODUCTS/SOLUTIONS]` with your details\n5. Populate your Supabase vector store with company knowledge base documents\n6. Update the Google Sheet document ID if using your own sheet\n7. Activate the workflow: chat flow runs on every message, scoring runs every 10 minutes\n\n## Next steps\nEmbed the n8n chat widget on your website to start capturing leads. Monitor your Google Sheet to see leads populate with conversation summaries and scores. Use the lead_status column (Hot/Warm/Cold) to prioritize sales follow-up, or connect to your existing CRM via additional nodes.\n\n**Tip:** Test the full flow with a few conversations first: provide name/email \u2192 ask questions \u2192 wait 30 minutes \u2192 verify the lead gets scored. The scoring timer resets with each new message, so leads are only scored after conversation inactivity.\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "callerPolicy": "workflowsFromSameOwner",
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "a8a2369a-aaed-4c32-8155-3294678bca3a",
  "connections": {
    "Reranker": {
      "ai_reranker": [
        [
          {
            "node": "Vector Store",
            "type": "ai_reranker",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings": {
      "ai_embedding": [
        [
          {
            "node": "Vector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Chat Trigger": {
      "main": [
        [
          {
            "node": "Check Identity In DB",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Has Leads": {
      "main": [
        [
          {
            "node": "AI Leader Scorer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Vector Store": {
      "ai_tool": [
        [
          {
            "node": "AI Support Specialist",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get All Leads": {
      "main": [
        [
          {
            "node": "Filter Leads Ready to Score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Respond to Chat": {
      "main": [
        []
      ]
    },
    "AI Leader Scorer": {
      "main": [
        [
          {
            "node": "Mark as Scored",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Identity In DB": {
      "main": [
        [
          {
            "node": "AI Support Specialist",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Postgres Chat Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Support Specialist",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "AI Support Specialist": {
      "main": [
        [
          {
            "node": "Respond to Chat",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Leader Scorer",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "AI Support Specialist",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Check if Lead Exists in CRM": {
      "ai_tool": [
        [
          {
            "node": "AI Support Specialist",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Filter Leads Ready to Score": {
      "main": [
        [
          {
            "node": "If Has Leads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger - Score Leads": {
      "main": [
        [
          {
            "node": "Get All Leads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append row in Google Sheets CRM": {
      "ai_tool": [
        [
          {
            "node": "AI Support Specialist",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Update row in Google Sheets CRM": {
      "ai_tool": [
        [
          {
            "node": "AI Support Specialist",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Slack Alert - New Lead and Intent": {
      "ai_tool": [
        [
          {
            "node": "AI Support Specialist",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Update row in Google Sheets CRM (2)": {
      "ai_tool": [
        [
          {
            "node": "AI Leader Scorer",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Supabase Upsert - Save User Identity": {
      "ai_tool": [
        [
          {
            "node": "AI Support Specialist",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  }
}