{
  "id": "jZWtA2xknueicDbY",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "The Lead Scorer",
  "tags": [],
  "nodes": [
    {
      "id": "ed092c57-bc4d-4bd9-ad6e-da76acf39888",
      "name": "Retrieve required fields",
      "type": "n8n-nodes-base.set",
      "position": [
        -1488,
        -720
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "2511073f-965c-4f41-9968-44519714c899",
              "name": "email",
              "type": "string",
              "value": "={{ $json.email }}"
            },
            {
              "id": "41dc438c-596d-4a65-b68c-e6cf36fb4da9",
              "name": "company",
              "type": "string",
              "value": "={{ $json.company }}"
            },
            {
              "id": "bedafa7b-2a4e-4782-8cc1-082d609a5e3d",
              "name": "source",
              "type": "string",
              "value": "={{ $json.source }}"
            },
            {
              "id": "8fff3882-2617-48d3-99bc-d63cfabea227",
              "name": "message",
              "type": "string",
              "value": "={{ $json.message }}"
            },
            {
              "id": "66c43169-a55c-484a-ab91-c43ee17db5e0",
              "name": "id",
              "type": "number",
              "value": "={{ $json.id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "958643e3-c1ad-468c-9666-d693185a123c",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1264,
        -976
      ],
      "parameters": {
        "color": 7,
        "width": 672,
        "height": 224,
        "content": "AI Agent uses Groq chat model to generate:\n- score (1\u2013100)\n- tier (hot / warm / cold)\n- reply\n- If score > 70 \u2192 send alert to Slack\nUse JavaScript node to:\n- Extract and format AI response into JSON\n- Append generated fields (score, tier, reply) to the existing data table row"
      },
      "typeVersion": 1
    },
    {
      "id": "47411be3-fa2c-4586-bf99-7f60a27dad6b",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1952,
        -864
      ],
      "parameters": {
        "color": 7,
        "width": 592,
        "height": 304,
        "content": "- Collect user input: name, email, company, source, message\n- Store all submitted data in the data table\n- Pass only required fields to the next node\n- Ensure unnecessary fields are filtered out"
      },
      "typeVersion": 1
    },
    {
      "id": "47576062-dc5e-4fbc-a701-228f8ed1c1a6",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -1152,
        -720
      ],
      "parameters": {
        "text": "=You are an expert sales assistant. \nI will give you information about a potential customer (a lead). \nBased on this information, do the following:\n\n1. Score the lead from 1 to 100 based on how valuable they are (consider message quality, company credibility, and source).  \n2. Assign a tier based on the score (If they are from big company or if in their message they provide budget or tech stack or developer need or if they need software for x amount of people then give them higher score):\n   - 70\u2013100: Hot\n   - 40\u201369: Warm\n   - 0\u201339: Cold\n3. Generate a professional, polite, and engaging suggested reply to the lead.\n4. You no need to create message to verify them, The data is coming from my own website, so just assign score, tire and write reply.\n5. If the score is more than 69 (score > 69) then only you have to send an alert on slack about the lead (include lead name, company name, their need in very short message), if score is lesser than 70 then do not use slack tool.\n6. If the score is more than 69 (score > 69) then only you have to create a task in google tasks about the lead (like for demo or meeting or any scheduling), if score is lesser than 70 then do not use google tasks tool.\n\nLead details:\n- Email: {{ $json.email }}\n- Company: {{$json.company}}\n- Source: {{$json.source}}\n- Message: {{$json.message}}\n- id: {{ $json.id }}\n\nOutput your response in **JSON format** like this:\n\n{\n  \"score\": <number between 1-100>,\n  \"tier\": \"<Hot/Warm/Cold>\",\n  \"reply\": \"<Suggested reply>\",\n  \"id\": <id_which_is_provided_in_lead_details>\n} ",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 3.1
    },
    {
      "id": "c9025cb5-f29e-4cb3-b90f-b977f69a46f6",
      "name": "Groq Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGroq",
      "position": [
        -1312,
        -496
      ],
      "parameters": {
        "model": "llama-3.3-70b-versatile",
        "options": {}
      },
      "credentials": {
        "groqApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "c83947a0-6e6d-47a8-a0e1-9329d33b02fd",
      "name": "Send a message in Slack",
      "type": "n8n-nodes-base.slackTool",
      "position": [
        -1152,
        -496
      ],
      "parameters": {
        "text": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Message_Text', ``, 'string') }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C0AP6AD7069",
          "cachedResultName": "all-group-d"
        },
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.4
    },
    {
      "id": "98f7f7b3-9959-47c4-b69b-9e62ce37b314",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2432,
        -1360
      ],
      "parameters": {
        "width": 448,
        "height": 608,
        "content": "**Lead Scorer Workflow (Overview)**\n\n**How it works:**\n\n* Trigger: New row added in **Google Sheets/Data table (Leads)** with Name, Email, Company, Source, Message\n* AI Agent (Groq model) analyzes lead \u2192 generates:\n\n  * **Score (1\u2013100)** based on message quality & company\n  * **Tier:** Hot (\u226570), Warm (40\u201369), Cold (<40)\n  * **Suggested reply**\n* Routing:\n\n  * **Hot (\u226570):** Send Slack alert + create Google Task + update sheet\n  * **Warm (40\u201369):** Update sheet only\n  * **Cold (<40):** Update sheet + archive\n* Final step: Append **score, tier, reply** to the original row\n\n**Setup steps:**\n\n1. Connect **Google Sheets**, **Slack**, and **Google Tasks** accounts\n2. Configure trigger for new row in Leads sheet\n3. Set up AI Agent (Groq) with prompt for scoring + reply generation + tool usage\n4. Use JavaScript node to format AI output (JSON fields)\n5. Update the same sheet row with generated values"
      },
      "typeVersion": 1
    },
    {
      "id": "bef17a09-e80f-42be-a80c-31f23c1da02a",
      "name": "Convert AI response to JSON",
      "type": "n8n-nodes-base.code",
      "position": [
        -672,
        -720
      ],
      "parameters": {
        "jsCode": "let clean = $input.first().json.output.replace(\"```json\", '')\nclean = clean.replace(\"```\", '')\n\nlet json = JSON.parse(clean)\nreturn json"
      },
      "typeVersion": 2
    },
    {
      "id": "2e5c123d-059e-4cc0-8846-f0c6ac7b151b",
      "name": "Update lead row with new data",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        -448,
        -720
      ],
      "parameters": {
        "columns": {
          "value": {
            "tier": "={{ $json.tier }}",
            "reply": "={{ $json.reply }}",
            "score": "={{ $json.score }}"
          },
          "schema": [
            {
              "id": "name",
              "type": "string",
              "display": true,
              "removed": true,
              "readOnly": false,
              "required": false,
              "displayName": "name",
              "defaultMatch": false
            },
            {
              "id": "email",
              "type": "string",
              "display": true,
              "removed": true,
              "readOnly": false,
              "required": false,
              "displayName": "email",
              "defaultMatch": false
            },
            {
              "id": "company",
              "type": "string",
              "display": true,
              "removed": true,
              "readOnly": false,
              "required": false,
              "displayName": "company",
              "defaultMatch": false
            },
            {
              "id": "source",
              "type": "string",
              "display": true,
              "removed": true,
              "readOnly": false,
              "required": false,
              "displayName": "source",
              "defaultMatch": false
            },
            {
              "id": "message",
              "type": "string",
              "display": true,
              "removed": true,
              "readOnly": false,
              "required": false,
              "displayName": "message",
              "defaultMatch": false
            },
            {
              "id": "formMode",
              "type": "string",
              "display": true,
              "removed": true,
              "readOnly": false,
              "required": false,
              "displayName": "formMode",
              "defaultMatch": false
            },
            {
              "id": "submittedAt",
              "type": "dateTime",
              "display": true,
              "removed": true,
              "readOnly": false,
              "required": false,
              "displayName": "submittedAt",
              "defaultMatch": false
            },
            {
              "id": "score",
              "type": "number",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "score",
              "defaultMatch": false
            },
            {
              "id": "tier",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "tier",
              "defaultMatch": false
            },
            {
              "id": "reply",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "reply",
              "defaultMatch": false
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "filters": {
          "conditions": [
            {
              "keyValue": "={{ $json.id }}"
            }
          ]
        },
        "options": {},
        "operation": "update",
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "YGKA3sX5PhPUHuR0",
          "cachedResultUrl": "/projects/XkgejKSYcPusPWyB/datatables/YGKA3sX5PhPUHuR0",
          "cachedResultName": "PT-Parth_Panchal_Lead_scores"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "7950c289-4611-4c7f-ac7c-c673a38a3596",
      "name": "Lead data entry form",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -1936,
        -720
      ],
      "parameters": {
        "options": {},
        "formTitle": "Contact us",
        "formFields": {
          "values": [
            {
              "fieldName": "name",
              "fieldLabel": "Name",
              "placeholder": "FirstName LastName",
              "requiredField": true
            },
            {
              "fieldName": "email",
              "fieldType": "email",
              "fieldLabel": "Email",
              "placeholder": "user@example.com",
              "requiredField": true
            },
            {
              "fieldName": "company",
              "fieldLabel": "Company",
              "placeholder": "company name",
              "requiredField": true
            },
            {
              "fieldName": "source",
              "fieldType": "dropdown",
              "fieldLabel": "Source",
              "fieldOptions": {
                "values": [
                  {
                    "option": "LinkedIn"
                  },
                  {
                    "option": "Facebook / meta"
                  },
                  {
                    "option": "Instagram"
                  },
                  {
                    "option": "Google search"
                  },
                  {
                    "option": "Other"
                  }
                ]
              },
              "requiredField": true
            },
            {
              "fieldName": "message",
              "fieldType": "textarea",
              "fieldLabel": "Message",
              "placeholder": "Suggested Guidance:\n- Describe what you need (product, service, solution)\n- Mention how many people or teams will use it\n- Share your preferred technology or tools (if any)\n- Include budget range (even approximate is fine)\n- Specify deadlines or timelines for the project\n- Give a short overview of your company (industry, size, focus)\n- Explain current challenges or goals you want to solve",
              "requiredField": true
            },
            {
              "fieldName": "score",
              "fieldType": "hiddenField"
            },
            {
              "fieldName": "tier",
              "fieldType": "hiddenField"
            },
            {
              "fieldName": "reply",
              "fieldType": "hiddenField"
            }
          ]
        },
        "formDescription": "Submit us your message and get in touch with us."
      },
      "notesInFlow": false,
      "typeVersion": 2.4,
      "alwaysOutputData": false
    },
    {
      "id": "8c9cc244-481d-4236-a899-809da631c213",
      "name": "save data to data table",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        -1712,
        -720
      ],
      "parameters": {
        "columns": {
          "value": {},
          "schema": [
            {
              "id": "name",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "name",
              "defaultMatch": false
            },
            {
              "id": "email",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "email",
              "defaultMatch": false
            },
            {
              "id": "company",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "company",
              "defaultMatch": false
            },
            {
              "id": "source",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "source",
              "defaultMatch": false
            },
            {
              "id": "message",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "message",
              "defaultMatch": false
            },
            {
              "id": "formMode",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "formMode",
              "defaultMatch": false
            },
            {
              "id": "submittedAt",
              "type": "dateTime",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "submittedAt",
              "defaultMatch": false
            },
            {
              "id": "score",
              "type": "number",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "score",
              "defaultMatch": false
            },
            {
              "id": "tier",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "tier",
              "defaultMatch": false
            },
            {
              "id": "reply",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "reply",
              "defaultMatch": false
            }
          ],
          "mappingMode": "autoMapInputData",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "YGKA3sX5PhPUHuR0",
          "cachedResultUrl": "/projects/XkgejKSYcPusPWyB/datatables/YGKA3sX5PhPUHuR0",
          "cachedResultName": "PT-Parth_Panchal_Lead_scores"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "e7342954-888e-4e51-82da-29f0e10f7c1d",
      "name": "Create a task in Google Tasks",
      "type": "n8n-nodes-base.googleTasksTool",
      "position": [
        -1008,
        -496
      ],
      "parameters": {
        "additionalFields": {}
      },
      "typeVersion": 1
    },
    {
      "id": "925c2dbd-5555-4141-818a-4924990051b1",
      "name": "Append or update row in sheet in Google Sheets",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        -864,
        -496
      ],
      "parameters": {
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "39b9826b-9eaf-4ef1-8a78-a30d41d93fb4",
  "connections": {
    "AI Agent": {
      "main": [
        [
          {
            "node": "Convert AI response to JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Groq Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Lead data entry form": {
      "main": [
        [
          {
            "node": "save data to data table",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a message in Slack": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "save data to data table": {
      "main": [
        [
          {
            "node": "Retrieve required fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Retrieve required fields": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert AI response to JSON": {
      "main": [
        [
          {
            "node": "Update lead row with new data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create a task in Google Tasks": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Append or update row in sheet in Google Sheets": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  }
}