{"connections":{"AI Agent — Qualify Lead":{"main":[[{"index":0,"node":"Update Lead Log — Status DEDUP_CHECKED","type":"main"}]]},"Append Nurture List":{"main":[[{"index":0,"node":"Update Lead Log — Status NURTURED","type":"main"}]]},"Build Qualified Alert":{"main":[[{"index":0,"node":"Telegram — Qualified Alert","type":"main"}]]},"Build Summary Message":{"main":[[{"index":0,"node":"Telegram — Send Summary","type":"main"}]]},"CONFIG — Notifications":{"main":[[{"index":0,"node":"Prepare Lead Record","type":"main"}]]},"CONFIG — Pipeline Settings":{"main":[[{"index":0,"node":"CONFIG — Notifications","type":"main"}]]},"Detect Duplicate":{"main":[[{"index":0,"node":"IF — Duplicate Email?","type":"main"}]]},"GHL — Add Score Note":{"main":[[{"index":0,"node":"Update Lead Log — Status QUALIFIED","type":"main"}]]},"GHL — Create Contact":{"main":[[{"index":0,"node":"GHL — Create Opportunity","type":"main"}]]},"GHL — Create Opportunity":{"main":[[{"index":0,"node":"GHL — Add Score Note","type":"main"}]]},"IF — Duplicate Email?":{"main":[[{"index":0,"node":"Log Duplicate — Status DISCARDED","type":"main"}],[{"index":1,"node":"Log Lead — Status LEAD_RECEIVED","type":"main"}]]},"IF — Verdict Nurture?":{"main":[[{"index":0,"node":"Append Nurture List","type":"main"}],[{"index":1,"node":"Update Lead Log — Status DISCARDED (Junk)","type":"main"}]]},"IF — Verdict Qualified?":{"main":[[{"index":0,"node":"GHL — Create Contact","type":"main"}],[{"index":1,"node":"IF — Verdict Nurture?","type":"main"}]]},"Lead Intake — Form Trigger":{"main":[[{"index":0,"node":"CONFIG — Pipeline Settings","type":"main"}]]},"Log Duplicate — Status DISCARDED":{"main":[[{"index":0,"node":"Build Summary Message","type":"main"}]]},"Log Lead — Status LEAD_RECEIVED":{"main":[[{"index":0,"node":"AI Agent — Qualify Lead","type":"main"}]]},"Merge — Combine Verdict Branches":{"main":[[{"index":0,"node":"Build Summary Message","type":"main"}]]},"OpenAI Chat Model — Qualifier":{"ai_languageModel":[[{"index":0,"node":"AI Agent — Qualify Lead","type":"ai_languageModel"}]]},"Prepare Lead Record":{"main":[[{"index":0,"node":"Search Existing Leads","type":"main"}]]},"Search Existing Leads":{"main":[[{"index":0,"node":"Detect Duplicate","type":"main"}]]},"Structured Output Parser — Qualification":{"ai_outputParser":[[{"index":0,"node":"AI Agent — Qualify Lead","type":"ai_outputParser"}]]},"Telegram — Qualified Alert":{"main":[[{"index":0,"node":"Merge — Combine Verdict Branches","type":"main"}]]},"Update Lead Log — Status DEDUP_CHECKED":{"main":[[{"index":0,"node":"IF — Verdict Qualified?","type":"main"}]]},"Update Lead Log — Status DISCARDED (Junk)":{"main":[[{"index":2,"node":"Merge — Combine Verdict Branches","type":"main"}]]},"Update Lead Log — Status NURTURED":{"main":[[{"index":1,"node":"Merge — Combine Verdict Branches","type":"main"}]]},"Update Lead Log — Status QUALIFIED":{"main":[[{"index":0,"node":"Build Qualified Alert","type":"main"}]]}},"meta":{"instanceId":"","templateCredsSetupCompleted":false},"name":"AI Lead Qualification Pipeline for GoHighLevel","nodes":[{"id":"11f2b3a4-5c6d-4e78-9abc-def011223344","name":"STICKY — Title","parameters":{"color":5,"content":"## 🎯 AI LEAD QUALIFICATION PIPELINE FOR GOHIGHLEVEL\n**What it does:** New lead submits the n8n form → duplicate submissions are discarded → AI scores intent (0–100) and picks a verdict → QUALIFIED leads are created as GHL contacts + open opportunities + a scored note on the contact record → NURTURE leads go to a nurture list → JUNK leads are logged and ignored. Every stage is logged in Google Sheets and you get a Telegram summary.\n\n**You'll need:**\n- GoHighLevel account (gohighlevel.com) → Settings → Integrations → create an API key (scope: contacts, opportunities)\n- OpenAI API key (platform.openai.com)\n- Google Sheets OAuth2 credential + one spreadsheet with 2 tabs (see guide)\n- Telegram bot token + your chat ID (@BotFather → /newbot)\n\n**Status flow in Sheets:** `LEAD_RECEIVED` → `DEDUP_CHECKED` → `QUALIFIED` / `NURTURED` / `DISCARDED`\n\n**Hard rules:** no credentials in the workflow — everything user-editable lives in CONFIG nodes with PASTE_YOUR_* placeholders. The AI never invents a lead: junk verdicts are logged, never synced to GHL.","height":220,"width":5500},"position":[-240,-160],"type":"n8n-nodes-base.stickyNote","typeVersion":1},{"id":"22a3b4c5-6d7e-4f89-abcd-ef1223344556","name":"STICKY — STEP 1","parameters":{"color":4,"content":"## STEP 1 — Lead intake & config\nLead Intake — Form Trigger (name / email / phone / service interest / message) → CONFIG — Pipeline Settings (GHL API key, Location ID, Pipeline + Stage IDs, score threshold, booking link — all PASTE_YOUR_* placeholders) + CONFIG — Notifications (Telegram chat ID) → Prepare Lead Record builds the LEAD-YYYYMMDD-XXXX reference → Search Existing Leads reads the Lead Log → Detect Duplicate compares emails → IF — Duplicate Email?.","height":900,"width":1620},"position":[-240,20],"type":"n8n-nodes-base.stickyNote","typeVersion":1},{"id":"33b4c5d6-7e8f-4a90-bcde-f12334455667","name":"STICKY — STEP 2","parameters":{"color":4,"content":"## STEP 2 — Dedupe + AI qualification\nDuplicates → Log Duplicate (status DISCARDED) → skip to the final summary. Fresh leads → Log Lead — Status LEAD_RECEIVED → AI Agent — Qualify Lead (gpt-4o-mini + Structured Output Parser: service_interest / budget_range / timeline / intent_score / verdict / summary) → Update Lead Log — Status DEDUP_CHECKED with the score + verdict.","height":900,"width":1220},"position":[1400,20],"type":"n8n-nodes-base.stickyNote","typeVersion":1},{"id":"44c5d6e7-8f90-4b01-cdef-123445566778","name":"STICKY — STEP 3","parameters":{"color":4,"content":"## STEP 3 — Verdict routing + GoHighLevel sync\nIF — Verdict Qualified? (verdict == qualified) → GHL — Create Contact (HTTP POST /contacts/ with Bearer {{ config }} header) → GHL — Create Opportunity (POST /opportunities/, pipeline + stage from config) → GHL — Add Score Note (POST /contacts/{id}/notes) → Update Lead Log — Status QUALIFIED (stores the GHL contact id) → Build Qualified Alert → Telegram — Qualified Alert with the booking link. IF — Verdict Nurture? catches nurture verdicts; everything else falls to the junk branch (see STEP 4).","height":900,"width":1720},"position":[2640,20],"type":"n8n-nodes-base.stickyNote","typeVersion":1},{"id":"55d6e7f8-90a1-4b12-def0-234556677889","name":"STICKY — STEP 4","parameters":{"color":4,"content":"## STEP 4 — Nurture / junk + final summary\nNURTURE: Append Nurture List (Nurture List tab, follow_up_status PENDING) → Update Lead Log — Status NURTURED. JUNK: Update Lead Log — Status DISCARDED (nothing is synced to GHL). Branches merge → Build Summary Message → Telegram — Send Summary with name, verdict, score and the GHL link.","height":900,"width":800},"position":[4400,20],"type":"n8n-nodes-base.stickyNote","typeVersion":1},{"id":"a340d4b5-ce77-4ab3-a937-e739f4b8ae92","name":"Lead Intake — Form Trigger","parameters":{"formDescription":"Tell us what you need and the best time to reach you. An AI qualifier reviews every request before it hits our CRM.","formFields":{"values":[{"fieldLabel":"lead_name","fieldType":"text","placeholder":"Your full name","requiredField":true},{"fieldLabel":"lead_email","fieldType":"text","placeholder":"you@example.com","requiredField":true},{"fieldLabel":"lead_phone","fieldType":"text","placeholder":"+1 555 000 1234","requiredField":true},{"fieldLabel":"service_interest","fieldType":"text","placeholder":"e.g. home insurance quote, SEO retainer, web redesign…","requiredField":true},{"fieldLabel":"message","fieldType":"textarea","placeholder":"Anything else we should know? (optional)","requiredField":false}]},"formTitle":"New Lead — Get a Callback","options":{"appendAttribution":true,"respondWithOptions":{"values":{"formSubmittedText":"Thanks! Your request is received — we will be in touch shortly."}}},"responseMode":"lastNode"},"position":[0,300],"type":"n8n-nodes-base.formTrigger","typeVersion":2.2},{"id":"6201fa73-0766-4f07-81d1-f5aa1e1367a4","name":"CONFIG — Pipeline Settings","parameters":{"assignments":{"assignments":[{"id":"1d769369-e488-4a28-af19-f837ef859b52","name":"spreadsheet_id","type":"string","value":"PASTE_YOUR_SPREADSHEET_ID"},{"id":"2e87a480-f599-4b39-b02a-08ff00aa11bb","name":"lead_log_sheet","type":"string","value":"Lead Log"},{"id":"3f98b591-06aa-4c4a-c13b-19gg11bb22cc","name":"nurture_sheet","type":"string","value":"Nurture List"},{"id":"40a9c602-17bb-4d5b-d24c-20hh22cc33dd","name":"ghl_api_key","type":"string","value":"PASTE_YOUR_GHL_API_KEY"},{"id":"51ba0d713-28cc-4e6c-e35d-31ii33dd44ee","name":"ghl_location_id","type":"string","value":"PASTE_YOUR_GHL_LOCATION_ID"},{"id":"62cb1e824-39dd-4f7d-f46e-42jj44ee55ff","name":"ghl_pipeline_id","type":"string","value":"PASTE_YOUR_GHL_PIPELINE_ID"},{"id":"73dc2f935-40ee-408e-057f-53kk55ff66gg","name":"ghl_stage_id","type":"string","value":"PASTE_YOUR_GHL_STAGE_ID"},{"id":"84ed30a46-51ff-419f-1680-64ll66gg77hh","name":"score_threshold","type":"string","value":"70"},{"id":"95fe41b57-6200-420a-2791-75mm77hh88ii","name":"booking_link","type":"string","value":"PASTE_YOUR_BOOKING_LINK"},{"id":"a60f52c68-7311-431b-3802-86nn88ii99jj","name":"business_name","type":"string","value":"PASTE_YOUR_BUSINESS_NAME"},{"id":"b71a63d79-8422-442c-4913-97oo99jj00kk","name":"owner_name","type":"string","value":"PASTE_YOUR_NAME"}]},"options":{}},"position":[240,300],"type":"n8n-nodes-base.set","typeVersion":3.4},{"id":"633c7c9b-8035-4bf9-b1db-db7ac7cb40a4","name":"CONFIG — Notifications","parameters":{"assignments":{"assignments":[{"id":"1d769369-e488-4a28-af19-f837ef859b53","name":"telegram_chat_id","type":"string","value":"PASTE_YOUR_TELEGRAM_CHAT_ID"}]},"options":{}},"position":[480,300],"type":"n8n-nodes-base.set","typeVersion":3.4},{"id":"94fb5455-0f35-418f-916f-bd5b507f45cc","name":"Prepare Lead Record","parameters":{"jsCode":"// Build the lead record from the form submission.\nconst form = $('Lead Intake \\u2014 Form Trigger').first().json;\nconst d = new Date();\nconst ref = 'LEAD-' + d.toISOString().slice(0, 10).replace(/-/g, '') + '-' + Math.floor(1000 + Math.random() * 9000);\nreturn [{ json: {\n  lead_ref: ref,\n  name: String(form.lead_name || '').trim(),\n  email: String(form.lead_email || '').trim().toLowerCase(),\n  phone: String(form.lead_phone || '').trim(),\n  service_interest: String(form.service_interest || '').trim(),\n  message: String(form.message || '').trim(),\n  received_at: d.toISOString(),\n  stage: 'LEAD_RECEIVED',\n  status: 'LEAD_RECEIVED',\n}}];","mode":"runOnceForAllItems"},"position":[720,300],"type":"n8n-nodes-base.code","typeVersion":2},{"credentials":{"googleSheetsOAuth2Api":{"id":"","name":"Google Sheets API"}},"id":"e624e023-f21d-462c-8a2c-35b7e58a136d","name":"Search Existing Leads","parameters":{"documentId":{"__rl":true,"mode":"list","value":"={{ $('CONFIG \\u2014 Pipeline Settings').first().json.spreadsheet_id }}"},"operation":"read","options":{},"resource":"sheetWithinDocument","sheetName":{"__rl":true,"mode":"list","value":"={{ $('CONFIG \\u2014 Pipeline Settings').first().json.lead_log_sheet }}"}},"position":[960,300],"type":"n8n-nodes-base.googleSheets","typeVersion":4.5},{"id":"33398091-dfc5-4759-888b-07ef61d0ced3","name":"Detect Duplicate","parameters":{"jsCode":"// Duplicate check: any existing row with the same email counts as a duplicate.\nconst rec = $('Prepare Lead Record').first().json;\nconst email = String(rec.email || '').toLowerCase();\nlet is_duplicate = false;\nif (email) {\n  for (const item of $('Search Existing Leads').all()) {\n    if (String(item.json.email || '').toLowerCase() === email) { is_duplicate = true; break; }\n  }\n}\nreturn [{ json: { is_duplicate: is_duplicate } }];","mode":"runOnceForAllItems"},"position":[1200,300],"type":"n8n-nodes-base.code","typeVersion":2},{"id":"45ce5e9c-1d48-400d-a81b-79829f4d6546","name":"IF — Duplicate Email?","parameters":{"conditions":{"combinator":"and","conditions":[{"id":"if-dup","leftValue":"={{ $json.is_duplicate }}","operator":{"name":"filter.operator.boolean.true","operation":"true","type":"boolean"},"rightValue":true}],"options":{"caseSensitive":true,"leftValue":"","typeValidation":"loose"}},"options":{}},"position":[1440,300],"type":"n8n-nodes-base.if","typeVersion":2.2},{"credentials":{"googleSheetsOAuth2Api":{"id":"","name":"Google Sheets API"}},"id":"3feebf44-c2eb-4666-97fb-0b314388334a","name":"Log Duplicate — Status DISCARDED","parameters":{"columns":{"attemptToConvertTypes":false,"convertFieldsToString":false,"mappingMode":"defineBelow","matchingColumns":[],"schema":[],"value":{"email":"={{ $('Prepare Lead Record').first().json.email }}","ghl_contact_id":"","intent_score":"","lead_ref":"={{ $('Prepare Lead Record').first().json.lead_ref }}","name":"={{ $('Prepare Lead Record').first().json.name }}","notes":"Duplicate submission — skipped AI scoring and GHL sync","phone":"={{ $('Prepare Lead Record').first().json.phone }}","received_at":"={{ $('Prepare Lead Record').first().json.received_at }}","service_interest":"={{ $('Prepare Lead Record').first().json.service_interest }}","stage":"DISCARDED","status":"DISCARDED","summary":"","verdict":"duplicate"}},"documentId":{"__rl":true,"mode":"list","value":"={{ $('CONFIG \\u2014 Pipeline Settings').first().json.spreadsheet_id }}"},"operation":"append","options":{},"resource":"sheetWithinDocument","sheetName":{"__rl":true,"mode":"list","value":"={{ $('CONFIG \\u2014 Pipeline Settings').first().json.lead_log_sheet }}"}},"position":[1680,140],"type":"n8n-nodes-base.googleSheets","typeVersion":4.5},{"credentials":{"googleSheetsOAuth2Api":{"id":"","name":"Google Sheets API"}},"id":"998c078b-0cd2-41cd-af79-edc85b80e3c4","name":"Log Lead — Status LEAD_RECEIVED","parameters":{"columns":{"attemptToConvertTypes":false,"convertFieldsToString":false,"mappingMode":"defineBelow","matchingColumns":[],"schema":[],"value":{"email":"={{ $('Prepare Lead Record').first().json.email }}","ghl_contact_id":"","intent_score":"","lead_ref":"={{ $('Prepare Lead Record').first().json.lead_ref }}","name":"={{ $('Prepare Lead Record').first().json.name }}","notes":"","phone":"={{ $('Prepare Lead Record').first().json.phone }}","received_at":"={{ $('Prepare Lead Record').first().json.received_at }}","service_interest":"={{ $('Prepare Lead Record').first().json.service_interest }}","stage":"LEAD_RECEIVED","status":"LEAD_RECEIVED","summary":"","verdict":""}},"documentId":{"__rl":true,"mode":"list","value":"={{ $('CONFIG \\u2014 Pipeline Settings').first().json.spreadsheet_id }}"},"operation":"append","options":{},"resource":"sheetWithinDocument","sheetName":{"__rl":true,"mode":"list","value":"={{ $('CONFIG \\u2014 Pipeline Settings').first().json.lead_log_sheet }}"}},"position":[1680,460],"type":"n8n-nodes-base.googleSheets","typeVersion":4.5},{"id":"185c312e-3268-4db3-9442-8201877fd21b","name":"AI Agent — Qualify Lead","parameters":{"options":{"systemMessage":"=You are a strict B2B/B2C lead qualification assistant for {{ $('CONFIG \\u2014 Pipeline Settings').first().json.business_name }}. Read the lead details and judge buying intent.\n\nScoring (intent_score 0\\u2013100):\n- Specific service asked + timeline urgency = high (70+)\n- Vague interest, no urgency, research-style wording = low (0\\u201340)\n- Fake/empty fields, spam wording, competitor snooping = junk\n\nVerdict rules:\n- verdict = \\u201cqualified\\u201d if intent_score >= {{ $('CONFIG \\u2014 Pipeline Settings').first().json.score_threshold }} AND a valid phone or email is present\n- verdict = \\u201cnurture\\u201d if some genuine interest but intent_score < threshold\n- verdict = \\u201cjunk\\u201d if spam, fake data, or no real service interest\n\nBudget: estimate a range from the service interest when possible, else \\u201cunknown\\u201d. Timeline: infer from the message (e.g. \\u201cASAP\\u201d, \\u201cthis month\\u201d), else \\u201cunknown\\u201d. Summary: one plain-English sentence explaining the verdict. Output ONLY via the structured output parser."},"text":"=LEAD DETAILS:\nName: {{ $('Prepare Lead Record').first().json.name }}\nEmail: {{ $('Prepare Lead Record').first().json.email }}\nPhone: {{ $('Prepare Lead Record').first().json.phone }}\nService interest: {{ $('Prepare Lead Record').first().json.service_interest }}\nMessage: {{ $('Prepare Lead Record').first().json.message }}"},"position":[1920,460],"type":"@n8n/n8n-nodes-langchain.agent","typeVersion":1.7},{"credentials":{"openAiApi":{"id":"","name":"OpenAI API"}},"id":"568e46f8-20b4-4bea-a812-8b9cc3ecc2af","name":"OpenAI Chat Model — Qualifier","parameters":{"model":{"__rl":true,"mode":"list","value":"gpt-4o-mini"},"options":{}},"position":[1920,720],"type":"@n8n/n8n-nodes-langchain.lmChatOpenAi","typeVersion":1.2},{"id":"526993a8-40d4-4bca-8efa-6da0c08d6a9c","name":"Structured Output Parser — Qualification","parameters":{"inputSchema":"{\n  \"service_interest\": \"home insurance quote\",\n  \"budget_range\": \"$100\\u2013$300/month or unknown\",\n  \"timeline\": \"this month or unknown\",\n  \"intent_score\": 82,\n  \"verdict\": \"qualified | nurture | junk\",\n  \"summary\": \"Lead asked for a home insurance quote and needs coverage before month-end; strong intent.\"\n}","schemaType":"manual"},"position":[2160,720],"type":"@n8n/n8n-nodes-langchain.outputParserStructured","typeVersion":1.2},{"credentials":{"googleSheetsOAuth2Api":{"id":"","name":"Google Sheets API"}},"id":"a5888274-8056-4ef6-aa7a-ce8459c4a146","name":"Update Lead Log — Status DEDUP_CHECKED","parameters":{"columns":{"attemptToConvertTypes":false,"convertFieldsToString":false,"mappingMode":"defineBelow","matchingColumns":["lead_ref"],"schema":[],"value":{"intent_score":"={{ $('AI Agent \\u2014 Qualify Lead').first().json.output.intent_score }}","lead_ref":"={{ $('Prepare Lead Record').first().json.lead_ref }}","stage":"DEDUP_CHECKED","status":"DEDUP_CHECKED","summary":"={{ $('AI Agent \\u2014 Qualify Lead').first().json.output.summary }}","verdict":"={{ $('AI Agent \\u2014 Qualify Lead').first().json.output.verdict }}"}},"documentId":{"__rl":true,"mode":"list","value":"={{ $('CONFIG \\u2014 Pipeline Settings').first().json.spreadsheet_id }}"},"operation":"update","options":{},"resource":"sheetWithinDocument","sheetName":{"__rl":true,"mode":"list","value":"={{ $('CONFIG \\u2014 Pipeline Settings').first().json.lead_log_sheet }}"}},"position":[2400,460],"type":"n8n-nodes-base.googleSheets","typeVersion":4.5},{"id":"35117daf-7429-4d67-bedc-3d39c8291919","name":"IF — Verdict Qualified?","parameters":{"conditions":{"combinator":"and","conditions":[{"id":"if-qualified","leftValue":"={{ $('AI Agent \\u2014 Qualify Lead').first().json.output.verdict }}","operator":{"name":"filter.operator.string.equals","operation":"equals","type":"string"},"rightValue":"qualified"}],"options":{"caseSensitive":true,"leftValue":"","typeValidation":"loose"}},"options":{}},"position":[2640,460],"type":"n8n-nodes-base.if","typeVersion":2.2},{"id":"5cd217d4-01e9-4d34-8f0e-6f3c21d63860","name":"GHL — Create Contact","parameters":{"headerParameters":{"parameters":[{"name":"Authorization","value":"=Bearer {{ $('CONFIG \\u2014 Pipeline Settings').first().json.ghl_api_key }}"},{"name":"Version","value":"2021-07-28"},{"name":"Content-Type","value":"application/json"}]},"jsonBody":"={{ JSON.stringify({ locationId: $('CONFIG \\u2014 Pipeline Settings').first().json.ghl_location_id, name: $('Prepare Lead Record').first().json.name, email: $('Prepare Lead Record').first().json.email, phone: $('Prepare Lead Record').first().json.phone, source: 'n8n Lead Pipeline', tags: ['n8n-qualified', 'intent-score-' + $('AI Agent \\u2014 Qualify Lead').first().json.output.intent_score] }) }}","method":"POST","options":{},"sendBody":true,"sendHeaders":true,"specifyBody":"json","url":"https://services.leadconnectorhq.com/contacts/"},"position":[2880,300],"type":"n8n-nodes-base.httpRequest","typeVersion":4.2},{"id":"10d5fa05-15cc-470e-926a-65736e8fbb19","name":"GHL — Create Opportunity","parameters":{"headerParameters":{"parameters":[{"name":"Authorization","value":"=Bearer {{ $('CONFIG \\u2014 Pipeline Settings').first().json.ghl_api_key }}"},{"name":"Version","value":"2021-07-28"},{"name":"Content-Type","value":"application/json"}]},"jsonBody":"={{ JSON.stringify({ pipelineId: $('CONFIG \\u2014 Pipeline Settings').first().json.ghl_pipeline_id, locationId: $('CONFIG \\u2014 Pipeline Settings').first().json.ghl_location_id, name: $('Prepare Lead Record').first().json.name + ' \\u2014 Qualified lead', pipelineStageId: $('CONFIG \\u2014 Pipeline Settings').first().json.ghl_stage_id, contactId: $('GHL \\u2014 Create Contact').first().json.contact.id, status: 'open' }) }}","method":"POST","options":{},"sendBody":true,"sendHeaders":true,"specifyBody":"json","url":"https://services.leadconnectorhq.com/opportunities/"},"position":[3120,300],"type":"n8n-nodes-base.httpRequest","typeVersion":4.2},{"id":"d0446846-e85d-4f28-8a47-da4ce7a5c0f3","name":"GHL — Add Score Note","parameters":{"headerParameters":{"parameters":[{"name":"Authorization","value":"=Bearer {{ $('CONFIG \\u2014 Pipeline Settings').first().json.ghl_api_key }}"},{"name":"Version","value":"2021-07-28"},{"name":"Content-Type","value":"application/json"}]},"jsonBody":"={{ JSON.stringify({ body: 'AI qualification \\u2014 intent score ' + $('AI Agent \\u2014 Qualify Lead').first().json.output.intent_score + '/100 (' + $('AI Agent \\u2014 Qualify Lead').first().json.output.verdict + '). ' + $('AI Agent \\u2014 Qualify Lead').first().json.output.summary + ' Budget: ' + $('AI Agent \\u2014 Qualify Lead').first().json.output.budget_range + '. Timeline: ' + $('AI Agent \\u2014 Qualify Lead').first().json.output.timeline + '.' }) }}","method":"POST","options":{},"sendBody":true,"sendHeaders":true,"specifyBody":"json","url":"=https://services.leadconnectorhq.com/contacts/{{ $('GHL \\u2014 Create Contact').first().json.contact.id }}/notes"},"position":[3360,300],"type":"n8n-nodes-base.httpRequest","typeVersion":4.2},{"credentials":{"googleSheetsOAuth2Api":{"id":"","name":"Google Sheets API"}},"id":"fd3d3e63-839f-493c-a091-a7b19acacb65","name":"Update Lead Log — Status QUALIFIED","parameters":{"columns":{"attemptToConvertTypes":false,"convertFieldsToString":false,"mappingMode":"defineBelow","matchingColumns":["lead_ref"],"schema":[],"value":{"ghl_contact_id":"={{ $('GHL \\u2014 Create Contact').first().json.contact.id }}","lead_ref":"={{ $('Prepare Lead Record').first().json.lead_ref }}","notes":"Synced to GoHighLevel — contact + opportunity created","stage":"QUALIFIED","status":"QUALIFIED"}},"documentId":{"__rl":true,"mode":"list","value":"={{ $('CONFIG \\u2014 Pipeline Settings').first().json.spreadsheet_id }}"},"operation":"update","options":{},"resource":"sheetWithinDocument","sheetName":{"__rl":true,"mode":"list","value":"={{ $('CONFIG \\u2014 Pipeline Settings').first().json.lead_log_sheet }}"}},"position":[3600,300],"type":"n8n-nodes-base.googleSheets","typeVersion":4.5},{"id":"92089809-c3bb-4e11-8964-053206beb261","name":"Build Qualified Alert","parameters":{"jsCode":"// Telegram alert for a freshly qualified lead, with the booking link and GHL contact link.\nconst rec = $('Prepare Lead Record').first().json;\nconst cfg = $('CONFIG \\u2014 Pipeline Settings').first().json;\nconst q = $('AI Agent \\u2014 Qualify Lead').first().json.output;\nconst contactId = $('GHL \\u2014 Create Contact').first().json.contact.id;\nconst ghlUrl = `https://app.gohighlevel.com/v2/location/${cfg.ghl_location_id}/contacts/detail/${contactId}`;\nreturn [{ json: { message:\n`<b>\\u2705 Qualified lead synced to GoHighLevel</b>\\n<b>${rec.name}</b> \\u2014 intent score <b>${q.intent_score}/100</b>\\nService: ${rec.service_interest}\\nPhone: ${rec.phone} | Email: ${rec.email}\\n${q.summary}\\n\\n\\uD83D\\uDCC5 Book a call: ${cfg.booking_link}\\n\\uD83D\\uDC64 GHL contact: ${ghlUrl}`\n}}];","mode":"runOnceForAllItems"},"position":[3840,300],"type":"n8n-nodes-base.code","typeVersion":2},{"credentials":{"telegramApi":{"id":"","name":"Telegram Bot API"}},"id":"029832dc-ce77-4a20-9429-e806de43acc6","name":"Telegram — Qualified Alert","parameters":{"additionalFields":{"parse_mode":"HTML"},"chatId":"={{ $('CONFIG — Notifications').first().json.telegram_chat_id }}","text":"={{ $json.message }}"},"position":[4080,300],"type":"n8n-nodes-base.telegram","typeVersion":1.2},{"id":"db3e0971-76cd-43f9-9526-85c0613c4347","name":"IF — Verdict Nurture?","parameters":{"conditions":{"combinator":"and","conditions":[{"id":"if-nurture","leftValue":"={{ $('AI Agent \\u2014 Qualify Lead').first().json.output.verdict }}","operator":{"name":"filter.operator.string.equals","operation":"equals","type":"string"},"rightValue":"nurture"}],"options":{"caseSensitive":true,"leftValue":"","typeValidation":"loose"}},"options":{}},"position":[2880,620],"type":"n8n-nodes-base.if","typeVersion":2.2},{"credentials":{"googleSheetsOAuth2Api":{"id":"","name":"Google Sheets API"}},"id":"000a1da2-31b7-4880-9822-7fe094a0774f","name":"Append Nurture List","parameters":{"columns":{"attemptToConvertTypes":false,"convertFieldsToString":false,"mappingMode":"defineBelow","matchingColumns":[],"schema":[],"value":{"email":"={{ $('Prepare Lead Record').first().json.email }}","follow_up_status":"PENDING","intent_score":"={{ $('AI Agent \\u2014 Qualify Lead').first().json.output.intent_score }}","lead_ref":"={{ $('Prepare Lead Record').first().json.lead_ref }}","name":"={{ $('Prepare Lead Record').first().json.name }}","phone":"={{ $('Prepare Lead Record').first().json.phone }}","service_interest":"={{ $('Prepare Lead Record').first().json.service_interest }}","status":"NURTURED","summary":"={{ $('AI Agent \\u2014 Qualify Lead').first().json.output.summary }}"}},"documentId":{"__rl":true,"mode":"list","value":"={{ $('CONFIG \\u2014 Pipeline Settings').first().json.spreadsheet_id }}"},"operation":"append","options":{},"resource":"sheetWithinDocument","sheetName":{"__rl":true,"mode":"list","value":"={{ $('CONFIG \\u2014 Pipeline Settings').first().json.nurture_sheet }}"}},"position":[3120,460],"type":"n8n-nodes-base.googleSheets","typeVersion":4.5},{"credentials":{"googleSheetsOAuth2Api":{"id":"","name":"Google Sheets API"}},"id":"4b5c6d7e-8f90-4a1b-c2d3-e4f5a6b7c8d9","name":"Update Lead Log — Status NURTURED","parameters":{"columns":{"attemptToConvertTypes":false,"convertFieldsToString":false,"mappingMode":"defineBelow","matchingColumns":["lead_ref"],"schema":[],"value":{"lead_ref":"={{ $('Prepare Lead Record').first().json.lead_ref }}","notes":"Added to nurture list — not yet ready to buy","stage":"NURTURED","status":"NURTURED"}},"documentId":{"__rl":true,"mode":"list","value":"={{ $('CONFIG \\u2014 Pipeline Settings').first().json.spreadsheet_id }}"},"operation":"update","options":{},"resource":"sheetWithinDocument","sheetName":{"__rl":true,"mode":"list","value":"={{ $('CONFIG \\u2014 Pipeline Settings').first().json.lead_log_sheet }}"}},"position":[3360,460],"type":"n8n-nodes-base.googleSheets","typeVersion":4.5},{"credentials":{"googleSheetsOAuth2Api":{"id":"","name":"Google Sheets API"}},"id":"5c6d7e8f-90a1-4b2c-d3e4-f5a6b7c8d9e0","name":"Update Lead Log — Status DISCARDED (Junk)","parameters":{"columns":{"attemptToConvertTypes":false,"convertFieldsToString":false,"mappingMode":"defineBelow","matchingColumns":["lead_ref"],"schema":[],"value":{"lead_ref":"={{ $('Prepare Lead Record').first().json.lead_ref }}","notes":"Junk verdict by AI — never synced to GoHighLevel","stage":"DISCARDED","status":"DISCARDED"}},"documentId":{"__rl":true,"mode":"list","value":"={{ $('CONFIG \\u2014 Pipeline Settings').first().json.spreadsheet_id }}"},"operation":"update","options":{},"resource":"sheetWithinDocument","sheetName":{"__rl":true,"mode":"list","value":"={{ $('CONFIG \\u2014 Pipeline Settings').first().json.lead_log_sheet }}"}},"position":[3120,780],"type":"n8n-nodes-base.googleSheets","typeVersion":4.5},{"id":"865ed60b-c13c-4d35-bac1-8708f9cbcb41","name":"Merge — Combine Verdict Branches","parameters":{"mode":"append","options":{}},"position":[4440,460],"type":"n8n-nodes-base.merge","typeVersion":3},{"id":"df68c5cb-3232-4431-a4e4-7e3a24619188","name":"Build Summary Message","parameters":{"jsCode":"// Final Telegram summary of the lead run (any verdict).\nconst rec = $('Prepare Lead Record').first().json;\nconst isDup = $('Detect Duplicate').first().json.is_duplicate;\nlet line;\nif (isDup) {\n  line = `Status: <b>DISCARDED</b> (duplicate submission \\u2014 skipped AI scoring)`;\n} else {\n  const q = $('AI Agent \\u2014 Qualify Lead').first().json.output;\n  const st = q.verdict === 'qualified' ? 'QUALIFIED' : (q.verdict === 'nurture' ? 'NURTURED' : 'DISCARDED');\n  line = `Verdict: <b>${q.verdict}</b> | Score: <b>${q.intent_score}/100</b> | Status: <b>${st}</b>\\n${q.summary}`;\n}\nreturn [{ json: { message:\n`<b>\\uD83C\\uDFAF New lead processed</b>\\n<b>${rec.name}</b> (${rec.lead_ref})\\nService: ${rec.service_interest} | Phone: ${rec.phone} | Email: ${rec.email}\\n${line}`\n}}];","mode":"runOnceForAllItems"},"position":[4680,460],"type":"n8n-nodes-base.code","typeVersion":2},{"credentials":{"telegramApi":{"id":"","name":"Telegram Bot API"}},"id":"5818ee89-a1c9-4291-8b1a-ed58d13b0cae","name":"Telegram — Send Summary","parameters":{"additionalFields":{"parse_mode":"HTML"},"chatId":"={{ $('CONFIG — Notifications').first().json.telegram_chat_id }}","text":"={{ $json.message }}"},"position":[4920,460],"type":"n8n-nodes-base.telegram","typeVersion":1.2}],"pinData":{}}