{
  "id": "2D5q8CitVinlx3Es",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Lead scoring and automated whatsapp proposal sender",
  "tags": [],
  "nodes": [
    {
      "id": "64a93eff-97f1-4bb4-a791-96f53d51e25f",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1184,
        -176
      ],
      "parameters": {
        "width": 480,
        "height": 512,
        "content": "## Lead scoring and automated whatsapp proposal sender\n\n### How it works\n\n1. Webhook data is parsed and analyzed by Google AI to classify leads.\n2. Leads are routed through distinct CRM update paths based on the AI analysis.\n3. An independent module handles incoming WhatsApp messages for customer support.\n4. An AI agent manages customer conversations using Redis for memory and updates CRM records accordingly.\n\n### Setup steps\n\n- Configure the Webhook URL in your external source.\n- Set up Google Gemini API credentials for both AI agent nodes.\n- Connect your HighLevel and WhatsApp Business API accounts.\n- Configure Redis for chat memory in the Customer Service AI Agent.\n\n### Customization\n\nAdjust the AI prompt in the agent nodes to better align with your specific industry tone and business requirements."
      },
      "typeVersion": 1
    },
    {
      "id": "48c802e9-f705-430a-9406-010954a3028d",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1712,
        -336
      ],
      "parameters": {
        "color": 7,
        "width": 640,
        "height": 304,
        "content": "## Ingest and process lead data\n\nTriggered by a webhook, this flow processes lead data using Google AI to classify and update HighLevel contacts and opportunities."
      },
      "typeVersion": 1
    },
    {
      "id": "0e2d0f4d-f2d5-423e-bf8d-872fd33b5bd8",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2384,
        -336
      ],
      "parameters": {
        "color": 7,
        "width": 480,
        "height": 512,
        "content": "## Analyze lead with AI agent\n\nUses an AI agent to analyze lead info and determine the next business action."
      },
      "typeVersion": 1
    },
    {
      "id": "5549e3e3-ebd9-471c-87e9-49b70e1a4efb",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2896,
        -336
      ],
      "parameters": {
        "color": 7,
        "height": 528,
        "content": "## Route CRM actions via switch\n\nBranches logic based on AI decisions to route leads to different CRM workflows."
      },
      "typeVersion": 1
    },
    {
      "id": "7d2fa381-1607-4dba-a9b0-b18e20c0a3f8",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3168,
        -32
      ],
      "parameters": {
        "color": 7,
        "width": 800,
        "height": 272,
        "content": "## Execute primary CRM update sequence\n\nUpdates HighLevel contacts and opportunities following the primary business path."
      },
      "typeVersion": 1
    },
    {
      "id": "b9b03156-bca5-4b34-a5d6-8a6c2d2372ec",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3168,
        -336
      ],
      "parameters": {
        "color": 7,
        "width": 800,
        "height": 272,
        "content": "## Execute secondary CRM update sequence\n\nUpdates HighLevel contacts and opportunities following the secondary business path."
      },
      "typeVersion": 1
    },
    {
      "id": "b69d7a60-c75f-4a66-bb93-469e37d00879",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1712,
        272
      ],
      "parameters": {
        "color": 7,
        "width": 416,
        "height": 304,
        "content": "## Handle WhatsApp incoming trigger\n\nListens for incoming WhatsApp messages and validates the sender."
      },
      "typeVersion": 1
    },
    {
      "id": "69eb4ffe-2948-4565-87ee-85626f8e571d",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2160,
        272
      ],
      "parameters": {
        "color": 7,
        "width": 624,
        "height": 304,
        "content": "## Fetch customer CRM context\n\nFetches contact and opportunity history to provide context for AI-driven customer service."
      },
      "typeVersion": 1
    },
    {
      "id": "51c5bd1f-388e-46a7-a6ad-d2d86d6f058f",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2816,
        272
      ],
      "parameters": {
        "color": 7,
        "width": 1024,
        "height": 544,
        "content": "## Customer service AI interaction flow\n\nAn AI agent manages customer service conversations, updates CRM status, and sends automated responses."
      },
      "typeVersion": 1
    },
    {
      "id": "97b238a2-14f7-47a2-85dc-af9b00567549",
      "name": "When New Lead Received",
      "type": "n8n-nodes-base.webhook",
      "position": [
        1760,
        -208
      ],
      "parameters": {
        "path": "newlead",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2.1
    },
    {
      "id": "1180d5fe-93e9-49e2-bb2e-de8014d029a1",
      "name": "Prepare Lead Data",
      "type": "n8n-nodes-base.set",
      "position": [
        2000,
        -208
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "454da762-2578-490f-ba4a-d37f0aef060c",
              "name": "First Name",
              "type": "string",
              "value": "={{ $json.body.first_name }}"
            },
            {
              "id": "dbd6eb35-a9da-43ef-8758-929fedcb368b",
              "name": "Last Name",
              "type": "string",
              "value": "={{ $json.body.last_name }}"
            },
            {
              "id": "0cf6a455-a151-48d5-8e9b-8b9c1656f7be",
              "name": "Full Name",
              "type": "string",
              "value": "={{ $json.body.full_name }}"
            },
            {
              "id": "d4741882-7cca-4de6-a262-09492133446a",
              "name": "Email",
              "type": "string",
              "value": "={{ $json.body.email }}"
            },
            {
              "id": "9712bb37-2247-44e5-81a8-c85586b19f18",
              "name": "Phone",
              "type": "string",
              "value": "={{ $json.body.phone }}"
            },
            {
              "id": "b4538227-7384-47e0-af46-fccbfe989e9b",
              "name": "contactId",
              "type": "string",
              "value": "={{ $json.body.contact_id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "8a56e1f1-e4cb-4995-837e-48604b517f14",
      "name": "Lead Processor Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        2512,
        -208
      ],
      "parameters": {
        "text": "=Candidate Profile Overview: [{{ $json.aiModeResult.text }}]\n\nStructured Output:\n{\n  \"lead_score\": 0,\n  \"score_breakdown\": \"No candidate profile data provided to evaluate against ICP criteria.\",\n  \"recommendation\": \"Unable to assess fit without candidate information.\",\n  \"next_steps\": \"Please provide the candidate profile overview to generate an accurate lead score.\"\n}",
        "options": {
          "systemMessage": "You are an AI Lead Scorer. Score leads out of 100 based on how well the candidate profile aligns with the Ideal Customer Profile (ICP). and i take automation agencies so when you found automation agency memeber just score 100\n\nAnd my ICP is:\n\ud83d\udcbc The Ideal Customer Profile (ICP) Your best-fit companies usually have repeatable digital workflows, messy data, or high customer service volumes. Industry: E-commerce, Real Estate, Legal, Professional Services (Agencies, Consulting), Healthcare clinics, or SaaS. Company Size: 10 to 100 employees (Small enough to move fast; large enough to have a budget and scaling problems). Tech Stack: Already using tools like Shopify, HubSpot, Salesforce, Slack, or Zapier. Pain Point: High operational overhead, slow response times, or staff spending hours on manual data entry. \ud83d\udc64 The Buyer Personas These are the specific individuals within those companies who have the power to hire your agency. The CEO / Founder (Small Business): Focused on saving money and scaling revenue without adding headcount. They care about ROI and speed. The COO / VP of Operations (Mid-market): Focused on broken processes and team efficiency. They care about accuracy, saved hours, and smooth integration. The Customer Support Manager: Focused on high ticket volumes and stressed agents. They care about reducing response times and automating FAQs.\n\n**Output Structure:**\n```json\n{\n  \"lead_score\": 0,\n  \"score_breakdown\": \"Industry Match: X/25 | Company Size: X/20 | Tech Stack: X/20 | Pain Points: X/20 | Buyer Persona: X/15. Brief explanation of scoring rationale.\",\n  \"recommendation\": \"Clear recommendation based on score tier (80-100: High Priority, 60-79: Medium Priority, 40-59: Low Priority, Below 40: Disqualify or Nurture).\",\n  \"next_steps\": \"Specific action items based on the lead's score and profile gaps.\"\n}\n```"
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3.1
    },
    {
      "id": "20e6191f-803c-486b-8fe1-7b495089a5b5",
      "name": "Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        2432,
        16
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-3.1-flash-lite"
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "bd314551-2774-4f2a-86c3-87e92ec15e82",
      "name": "Parse Structured Output",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        2736,
        16
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"lead_score\": 0,\n  \"score_breakdown\": \"No candidate profile data provided to evaluate against ICP criteria.\",\n  \"recommendation\": \"Unable to assess fit without candidate information.\",\n  \"next_steps\": \"Please provide the candidate profile overview to generate an accurate lead score.\"\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "6e6eaba1-cef6-48ef-b4a1-face5fcfc032",
      "name": "Route by Lead Type",
      "type": "n8n-nodes-base.switch",
      "position": [
        2944,
        -160
      ],
      "parameters": {
        "mode": "expression",
        "output": "={{ $json.output.lead_score >= 80 ? 0 : ($json.output.lead_score >= 40 ? 1 : 2) }}",
        "numberOutputs": 3,
        "looseTypeValidation": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "8953e00e-d55e-48d6-a300-61a0e227876a",
      "name": "Create Opportunity",
      "type": "n8n-nodes-base.highLevel",
      "position": [
        3424,
        80
      ],
      "parameters": {
        "name": "={{ $json.fullNameLowerCase }} | ai_scored_lead",
        "resource": "opportunity",
        "contactId": "={{ $json.id }}",
        "requestOptions": {},
        "additionalFields": {
          "stageId": ""
        }
      },
      "credentials": {
        "highLevelOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "70d136dd-2e19-4daf-a79e-1802dc3ac4dc",
      "name": "Send WhatsApp Template A",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        3616,
        80
      ],
      "parameters": {
        "template": "hvac|en",
        "components": {
          "component": [
            {
              "bodyParameters": {
                "parameter": [
                  {
                    "text": "={{ $('Upsert Contact A').item.json.firstName }}"
                  }
                ]
              }
            }
          ]
        },
        "phoneNumberId": "1083481144853090",
        "recipientPhoneNumber": "={{ $('When New Lead Received').item.json.body.phone }}"
      },
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "0b5e98b6-8b6c-4a91-a329-f78bab3bb9a0",
      "name": "Update Opportunity A",
      "type": "n8n-nodes-base.highLevel",
      "position": [
        3824,
        80
      ],
      "parameters": {
        "resource": "opportunity",
        "operation": "update",
        "updateFields": {
          "stageId": "",
          "pipelineId": ""
        },
        "opportunityId": "={{ $('Create Opportunity').item.json.opportunity.id }}",
        "requestOptions": {}
      },
      "credentials": {
        "highLevelOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "aa12a113-bf03-4c92-a970-6a877f1ff7c8",
      "name": "Upsert Contact B",
      "type": "n8n-nodes-base.highLevel",
      "position": [
        3216,
        -224
      ],
      "parameters": {
        "email": "={{ $('Prepare Lead Data').item.json.Email }}",
        "requestOptions": {},
        "additionalFields": {
          "customFields": {
            "values": [
              {
                "fieldId": {
                  "__rl": true,
                  "mode": "id",
                  "value": ""
                },
                "fieldValue": "={{ $json.output.lead_score }}"
              },
              {
                "fieldId": {
                  "__rl": true,
                  "mode": "id",
                  "value": ""
                },
                "fieldValue": "={{ $json.output.score_breakdown }}"
              },
              {
                "fieldId": {
                  "__rl": true,
                  "mode": "id",
                  "value": ""
                },
                "fieldValue": "={{ $json.output.recommendation }}"
              },
              {
                "fieldId": {
                  "__rl": true,
                  "mode": "id",
                  "value": ""
                },
                "fieldValue": "={{ $json.output.next_steps }}"
              }
            ]
          }
        }
      },
      "credentials": {
        "highLevelOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "fa076e69-7223-46f2-a0f8-8ddc6ca85723",
      "name": "Create Opportunity B",
      "type": "n8n-nodes-base.highLevel",
      "position": [
        3424,
        -224
      ],
      "parameters": {
        "name": "={{ $json.fullNameLowerCase }} | ai_scored_lead",
        "resource": "opportunity",
        "contactId": "={{ $json.id }}",
        "requestOptions": {},
        "additionalFields": {
          "stageId": ""
        }
      },
      "credentials": {
        "highLevelOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "3f8625bc-c7a7-4836-bee0-a918c7f257cb",
      "name": "Send WhatsApp Template B",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        3616,
        -224
      ],
      "parameters": {
        "template": "hvac|en",
        "components": {
          "component": [
            {
              "bodyParameters": {
                "parameter": [
                  {
                    "text": "={{ $('Upsert Contact B').item.json.firstName }}"
                  }
                ]
              }
            }
          ]
        },
        "phoneNumberId": "1083481144853090",
        "recipientPhoneNumber": "={{ $('When New Lead Received').item.json.body.phone }}"
      },
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "94809d64-91ec-4e41-af13-a6f073e201b1",
      "name": "Update Opportunity B",
      "type": "n8n-nodes-base.highLevel",
      "position": [
        3824,
        -224
      ],
      "parameters": {
        "resource": "opportunity",
        "operation": "update",
        "updateFields": {
          "stageId": "",
          "pipelineId": ""
        },
        "opportunityId": "={{ $('Create Opportunity B').item.json.opportunity.id }}",
        "requestOptions": {}
      },
      "credentials": {
        "highLevelOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "c7fbaf06-5495-4e0c-8d63-db4b6ff0da96",
      "name": "Send WhatsApp Response",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        3648,
        384
      ],
      "parameters": {
        "textBody": "={{ $json.output }}",
        "operation": "send",
        "phoneNumberId": "1083481144853090",
        "additionalFields": {},
        "recipientPhoneNumber": "={{ $('When WhatsApp Message Received').first().json.messages[0].from }}"
      },
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "40697222-c201-4103-ad54-03fd5b58b2e5",
      "name": "If Valid Sender Exists",
      "type": "n8n-nodes-base.if",
      "position": [
        1984,
        416
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "11bbaeec-d3f0-4e49-a323-10fb6e13a513",
              "operator": {
                "type": "number",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.messages[0].from }}",
              "rightValue": ""
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.3
    },
    {
      "id": "b7bf3334-b768-4c20-b488-b7f83ce6b408",
      "name": "Fetch GHL Contacts",
      "type": "n8n-nodes-base.highLevel",
      "position": [
        2208,
        400
      ],
      "parameters": {
        "filters": {
          "query": "=+{{ $json.messages[0].from }}"
        },
        "options": {},
        "operation": "getAll",
        "requestOptions": {}
      },
      "credentials": {
        "highLevelOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2,
      "alwaysOutputData": true
    },
    {
      "id": "8cbc3c1a-3080-41cb-85d1-09d3ce1bf7ac",
      "name": "When WhatsApp Message Received",
      "type": "n8n-nodes-base.whatsAppTrigger",
      "position": [
        1760,
        416
      ],
      "parameters": {
        "options": {},
        "updates": [
          "messages"
        ]
      },
      "credentials": {
        "whatsAppTriggerApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "24b08d60-6ff8-4787-bc19-8a7f5b785a1d",
      "name": "Get Opportunities",
      "type": "n8n-nodes-base.highLevel",
      "position": [
        2432,
        400
      ],
      "parameters": {
        "filters": {
          "query": "={{ $json.phone }}",
          "stageId": "",
          "pipelineId": ""
        },
        "resource": "opportunity",
        "operation": "getAll",
        "returnAll": true,
        "requestOptions": {}
      },
      "credentials": {
        "highLevelOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2,
      "alwaysOutputData": true
    },
    {
      "id": "29b733f4-cc53-4eb2-aca2-725376fa6182",
      "name": "If Opportunity Exists",
      "type": "n8n-nodes-base.if",
      "position": [
        2640,
        400
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "4529d440-607f-4187-9169-6d2708c8e1a5",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.id }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "56eabf94-2534-4c74-be62-b4877ee4e9cb",
      "name": "Customer Service Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        3280,
        384
      ],
      "parameters": {
        "text": "=<context>\n    <timestamp>\n        {{ $now.toFormat(\"DDDD, HH:mm:ss ZZZZ\") }}\n    </timestamp>\n    \n    <user_details>\n        {{ $json.id ? \"Contact ID: \" + $('Fetch GHL Contacts').item.json.id + \"\\nFirst Name: \" + $('Fetch GHL Contacts').item.json.firstName + \"\\nLast Name: \" + $('Fetch GHL Contacts').item.json.lastName + \"\\nEmail: \" + $('Fetch GHL Contacts').item.json.email + \"\\nPhone Number: \" + $('When WhatsApp Message Received').item.json.messages[0].from : \"Contact ID: EMPTY\\nPhone Number: \" + $('When WhatsApp Message Received').item.json.messages[0].from + \"\\nMissing Info: Contact does not exist. You MUST ask the user for their Name and Email to create a contact profile.\" }}\n    </user_details>\n</context>\n\n<persona>\n    You are a professional sales and customer service AI assistant for an automation agency. Your goal is to uncover the client's needs, quote them accurately based on complexity, manage their pipeline stage, and set up team handoffs for negotiations.\n</persona>\n\n<instructions>\n    1. Greet the client warmly using their First Name (found in <user_details>).\n    2. Ask clarifying questions to understand their exact automation requirements. You must understand the complexity of the task and whether it requires n8n or Python before quoting.\n    3. Once you fully understand the requirement, conclude your part of the interaction by taking these exact steps:\n       - Use the tool \"Save user Requirement in notes\" to log a summary of their needs.\n       - Use the tool \"Update Stage As \\\"Proposal Sent\\\"\" to update their CRM status.\n       - Use the tool \"Send a text message in Telegram\" to notify the internal team with a summary of the client's requirements and the estimated quote.\n       - Send your FINAL message to the client: Provide the quotation based on the <pricing_rules>, and let them know that a member of our team will contact them shortly to take it from here. Do not ask them any further questions to continue the chat.\n    4. Strictly use the tool \"Close Oppurtunity\" ONLY if the user explicitly states they do not have the budget or if they are completely uninterested in our automation services.\n</instructions>\n\n<pricing_rules>\n    Strictly act based on the complexity of the requirements and nothing else:\n    - n8n Automation Workflows: $1500 - $3500 (average cost, scale based on workflow complexity).\n    - Python Automation: $3500 - $5000 (scale based on script/system complexity).\n</pricing_rules>\n\n<user_input>\n    <message>{{ $('When WhatsApp Message Received').item.json.messages[0].text.body }}</message>\n</user_input>\n\n<output_format>\n    Keep responses conversational, concise, and professional, suitable for a WhatsApp message.\n</output_format>\n\n<constraints>\n    - Do not provide a quote until you have enough information to judge the complexity.\n    - Never invent pricing outside of the <pricing_rules>.\n    - NEVER use \"Close Oppurtunity\" for successful deals, agreements, or ongoing negotiations. It is exclusively for budget rejections or lack of interest.\n</constraints>",
        "options": {},
        "promptType": "define"
      },
      "retryOnFail": true,
      "typeVersion": 3.1
    },
    {
      "id": "6f020208-1679-4a93-8ffb-df6b734b842d",
      "name": "Gemini Chat Model Service",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        2864,
        672
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "c6f429fb-5d84-47c3-9200-a60092b98173",
      "name": "Get Redis Chat History",
      "type": "@n8n/n8n-nodes-langchain.memoryRedisChat",
      "position": [
        3040,
        672
      ],
      "parameters": {
        "sessionKey": "={{ $('When WhatsApp Message Received').first().json.messages[0].from }}",
        "sessionTTL": 500000,
        "sessionIdType": "customKey",
        "contextWindowLength": 15
      },
      "credentials": {
        "redis": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.5
    },
    {
      "id": "d11c94b5-306e-4a03-89ae-bcb69732ade2",
      "name": "Update Stage to Proposal Sent",
      "type": "n8n-nodes-base.highLevelTool",
      "position": [
        3344,
        672
      ],
      "parameters": {
        "resource": "opportunity",
        "operation": "update",
        "updateFields": {
          "stageId": "",
          "pipelineId": ""
        },
        "opportunityId": "={{ $json.id }}",
        "requestOptions": {}
      },
      "credentials": {
        "highLevelOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "8cc3ae9a-530f-435d-a88d-1af2de560e20",
      "name": "Close Opportunity",
      "type": "n8n-nodes-base.highLevelTool",
      "position": [
        3712,
        672
      ],
      "parameters": {
        "resource": "opportunity",
        "operation": "update",
        "updateFields": {
          "stageId": "",
          "pipelineId": ""
        },
        "opportunityId": "={{ $json.id }}",
        "requestOptions": {}
      },
      "credentials": {
        "highLevelOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "a4cfee10-60ea-4e91-a5e8-3fed299554d2",
      "name": "Save User Requirements",
      "type": "n8n-nodes-base.highLevelTool",
      "position": [
        3184,
        672
      ],
      "parameters": {
        "email": "={{ $('Get Opportunities').item.json.relations[0].email }}",
        "phone": "=+{{ $('When WhatsApp Message Received').item.json.messages[0].from }}",
        "requestOptions": {},
        "descriptionType": "manual",
        "toolDescription": "Name: Save user Requirement in notes\nDescription: Saves the user's requirement description to their contact profile. Requires the 'Note' parameter containing a brief string summarizing the requirement of the client.",
        "additionalFields": {
          "notes": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Note', `you should add the issue over here in this field`, 'string') }}"
        }
      },
      "credentials": {
        "highLevelOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2,
      "rewireOutputLogTo": "ai_tool"
    },
    {
      "id": "4a8f67a9-7d19-4c04-939a-213ad9c6c021",
      "name": "Send Telegram Message",
      "type": "n8n-nodes-base.telegramTool",
      "position": [
        3520,
        672
      ],
      "parameters": {
        "text": "={{ $fromAI('Text', 'A summary of the user requirements and the estimated price quoted to them. And include the user mobile id for the reference', 'string') }}",
        "chatId": "=enter-your-chat-id",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "16b8c6b3-24ff-41dc-8d14-6b181e2d93d0",
      "name": "Upsert Contact A",
      "type": "n8n-nodes-base.highLevel",
      "position": [
        3216,
        80
      ],
      "parameters": {
        "email": "={{ $('When New Lead Received').item.json.body.email }}",
        "phone": "={{ $('When New Lead Received').item.json.body.phone }}",
        "requestOptions": {},
        "additionalFields": {
          "customFields": {
            "values": [
              {
                "fieldId": {
                  "__rl": true,
                  "mode": "id",
                  "value": ""
                },
                "fieldValue": "={{ $json.output.lead_score }}"
              },
              {
                "fieldId": {
                  "__rl": true,
                  "mode": "id",
                  "value": ""
                },
                "fieldValue": "={{ $json.output.score_breakdown }}"
              },
              {
                "fieldId": {
                  "__rl": true,
                  "mode": "id",
                  "value": ""
                },
                "fieldValue": "={{ $json.output.recommendation }}"
              },
              {
                "fieldId": {
                  "__rl": true,
                  "mode": "id",
                  "value": ""
                },
                "fieldValue": "={{ $json.output.next_steps }}"
              }
            ]
          }
        }
      },
      "credentials": {
        "highLevelOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "d2d37870-702b-459d-9bc7-2460bcce6fcc",
      "name": "Fetch Google AI Lead Overview",
      "type": "@apify/n8n-nodes-apify.apify",
      "position": [
        2208,
        -208
      ],
      "parameters": {
        "actorId": {
          "__rl": true,
          "mode": "id",
          "value": "nFJndFXA5zjCTuudP"
        },
        "operation": "Run actor and get dataset",
        "customBody": "={\n    \"aiModeSearch\": {\n        \"enableAiMode\": true\n    },\n    \"chatGptSearch\": {\n        \"enableChatGpt\": false\n    },\n    \"copilotSearch\": {\n        \"enableCopilot\": false\n    },\n    \"disableGoogleSearchResults\": false,\n    \"focusOnPaidAds\": false,\n    \"forceExactMatch\": false,\n    \"geminiSearch\": {\n        \"enableGemini\": false\n    },\n    \"includeIcons\": false,\n    \"includeUnfilteredResults\": false,\n    \"maxPagesPerQuery\": 1,\n    \"maximumLeadsEnrichmentRecords\": 0,\n    \"mobileResults\": false,\n    \"perplexitySearch\": {\n        \"enablePerplexity\": false,\n        \"returnImages\": false,\n        \"returnRelatedQuestions\": false\n    },\n    \"queries\": \"Provide a professional background summary for \\\"{{ $json['Full Name'] }}\\\" (associated with email: \\\"{{ $json.Email }}\\\"). Search public directories, company websites, and professional networks like LinkedIn. Extract and return: 1. Current Job Title 2. Current Employer 3. Past Experience 4. Links to public professional profiles.\",\n    \"saveHtml\": false,\n    \"saveHtmlToKeyValueStore\": true,\n    \"verifyLeadsEnrichmentRecords\": false\n}"
      },
      "credentials": {
        "apifyApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "7bd6f4fd-8c99-421e-b7e7-93e6de0a9b28",
  "nodeGroups": [],
  "connections": {
    "Upsert Contact A": {
      "main": [
        [
          {
            "node": "Create Opportunity",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upsert Contact B": {
      "main": [
        [
          {
            "node": "Create Opportunity B",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Close Opportunity": {
      "ai_tool": [
        [
          {
            "node": "Customer Service Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Lead Processor Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Get Opportunities": {
      "main": [
        [
          {
            "node": "If Opportunity Exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Lead Data": {
      "main": [
        [
          {
            "node": "Fetch Google AI Lead Overview",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Opportunity": {
      "main": [
        [
          {
            "node": "Send WhatsApp Template A",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch GHL Contacts": {
      "main": [
        [
          {
            "node": "Get Opportunities",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route by Lead Type": {
      "main": [
        [
          {
            "node": "Upsert Contact B",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Upsert Contact A",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Opportunity B": {
      "main": [
        [
          {
            "node": "Send WhatsApp Template B",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lead Processor Agent": {
      "main": [
        [
          {
            "node": "Route by Lead Type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Opportunity Exists": {
      "main": [
        [
          {
            "node": "Customer Service Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Telegram Message": {
      "ai_tool": [
        [
          {
            "node": "Customer Service Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Customer Service Agent": {
      "main": [
        [
          {
            "node": "Send WhatsApp Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Redis Chat History": {
      "ai_memory": [
        [
          {
            "node": "Customer Service Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "If Valid Sender Exists": {
      "main": [
        [
          {
            "node": "Fetch GHL Contacts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save User Requirements": {
      "ai_tool": [
        [
          {
            "node": "Customer Service Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "When New Lead Received": {
      "main": [
        [
          {
            "node": "Prepare Lead Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Structured Output": {
      "ai_outputParser": [
        [
          {
            "node": "Lead Processor Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Send WhatsApp Template A": {
      "main": [
        [
          {
            "node": "Update Opportunity A",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send WhatsApp Template B": {
      "main": [
        [
          {
            "node": "Update Opportunity B",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini Chat Model Service": {
      "ai_languageModel": [
        [
          {
            "node": "Customer Service Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Google AI Lead Overview": {
      "main": [
        [
          {
            "node": "Lead Processor Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Stage to Proposal Sent": {
      "ai_tool": [
        [
          {
            "node": "Customer Service Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "When WhatsApp Message Received": {
      "main": [
        [
          {
            "node": "If Valid Sender Exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}