I built an n8n workflow for GHL lead scoring and automated proposal sending on WhatsApp

Workflow Code: Lead scoring and automated whatsapp proposal sender · GitHub

Here is a node-by-node explanation of the n8n workflow below:

1. Lead Scoring and Routing Pipeline

This flow ingests new leads, researches them, scores them against an Ideal Customer Profile (ICP), and routes them into your CRM.

  • When New Lead Received (Webhook): Acts as the entry point. It listens for a POST request at the /newlead endpoint, expecting a JSON payload containing the lead’s basic info (name, email, phone, etc.).
  • Prepare Lead Data (Set): Extracts and normalizes variables from the incoming webhook (First Name, Last Name, Full Name, Email, Phone, Contact ID) to make them easily accessible for downstream nodes.
  • Fetch Google AI Lead Overview (Apify): Triggers an Apify actor to perform a web search (including public directories and LinkedIn) using the lead’s name and email. It extracts their current job title, employer, and past experience to build a professional profile.
  • Lead Processor Agent (AI Agent): This is the brain of the scoring process. It takes the enriched candidate profile from Apify and evaluates it against a detailed prompt defining your ICP (focusing on automation agencies, e-commerce, real estate, etc., with 10-100 employees).
    • Gemini Chat Model: Provides the underlying LLM (Gemini 3.1 Flash Lite) powering the agent’s logic.
    • Parse Structured Output: Forces the LLM to output a strict JSON schema containing a lead_score (0-100), score_breakdown , recommendation , and next_steps .
  • Route by Lead Type (Switch): Evaluates the integer from the lead_score .
    • Route 0 (High Priority): For scores >= 80.
    • Route 1 (Medium Priority): For scores between 40 and 79.
    • (Scores below 40 are routed to an empty Path 2, essentially discarding or halting the automated outreach).

High-Priority Path (Route 0 - B Nodes)

  • Upsert Contact B (HighLevel): Updates or creates the GoHighLevel (GHL) contact, saving the AI-generated lead score, breakdown, and next steps into custom fields.
  • Create Opportunity B (HighLevel): Generates a new pipeline opportunity in GHL named [Full Name] | ai_scored_lead .
  • Send WhatsApp Template B (WhatsApp): Sends an initial outreach template (hvac|en ) to the lead via the WhatsApp Business API.
  • Update Opportunity B (HighLevel): Updates the GHL opportunity, likely moving it to a specific stage to indicate that initial contact has been initiated.

Medium-Priority Path (Route 1 - A Nodes)

  • Upsert Contact A, Create Opportunity, Send WhatsApp Template A, Update Opportunity A: These nodes perform the exact same CRM and messaging sequence as the high-priority path, but run in parallel to allow for different pipeline stages or tags if you decide to customize the medium-priority routing later.

2. Customer Service AI Interaction Flow

This flow acts as an autonomous sales and support assistant that handles incoming WhatsApp messages, negotiates based on requirements, and uses tools to update the CRM.

  • When WhatsApp Message Received (WhatsApp Trigger): Listens for incoming WhatsApp messages and triggers the workflow.
  • If Valid Sender Exists (If): A simple validation node that checks if the incoming message payload actually contains a sender phone number before proceeding.
  • Fetch GHL Contacts (HighLevel): Looks up the sender’s phone number in GoHighLevel to pull their existing contact record and CRM context.
  • Get Opportunities (HighLevel): Fetches any open pipeline opportunities associated with that specific contact’s phone number.
  • If Opportunity Exists (If): Validates that an active opportunity ID was found in the previous step so the AI agent knows it is dealing with a tracked lead.
  • Customer Service Agent (AI Agent): A sophisticated conversational agent tasked with uncovering client needs, providing quotes (distinguishing between n8n and Python complexity), and handing the deal off to the team.
    • Gemini Chat Model Service: The LLM (Gemini) driving the conversational intelligence.
    • Get Redis Chat History (Memory): Uses Redis to store and retrieve the context window of the conversation, using the sender’s WhatsApp number as the session key. This allows the AI to “remember” previous messages in the thread.
    • Agent Tools (What the AI can do):
      • Save User Requirements: Saves a summary of the client’s needs into the notes field of their GHL profile.
      • Update Stage to Proposal Sent: Moves the user’s GHL opportunity to a specific stage once a quote is generated.
      • Send Telegram Message: Notifies your internal team via Telegram with a summary of the requirements and the estimated quote.
      • Close Opportunity: A strictly constrained tool the AI is instructed to use only if the user rejects the budget or explicitly states they are no longer interested.
  • Send WhatsApp Response (WhatsApp): Takes the final conversational output generated by the Customer Service Agent and sends it back to the user as a WhatsApp text message.
2 Likes

The combination of AI-scored lead profiling through Apify and then a conversational customer service agent for proposal delivery is a solid end-to-end design. The constrained tool approach for Close Opportunity - only allowing the AI to call it when explicitly rejected - is a good guardrail to prevent premature opportunity closures. How are you handling cases where the AI misclassifies the score tier and routes to the wrong proposal template?

This is a pretty solid flow, especially the lead scoring → proposal routing piece.

The one thing I’d probably watch out for is having the AI score be the only thing determining which proposal gets sent. AI can be surprisingly accurate most of the time, but those edge cases are usually where things get interesting.

I’d be tempted to add either a confidence threshold or some kind of review path for borderline scores. That way the obvious leads can move through automatically, while the questionable ones get a quick human check before the wrong proposal goes out.

Just curious, are you storing the score, the reasoning behind it, and the proposal that was selected? Being able to look back at that data later makes it much easier to see whether the routing logic is actually lining up with lead quality or if it needs some tuning.

yeah, we can expand with confidence score and it was a good idea…

and i am already saving the whole ai output so the reason, score breakdown, AI recommendation, next steps will be saved directly to our GHL. But if you mean is there a individual loggin for now nope. but as you know we can always expand features to any n8n workflow to save logs

Nice, that sounds like the right direction. If the full AI output is already in GHL, I’d probably add a tiny separate log only for decisions you may want to audit later: lead ID, score, confidence, selected proposal, and whether a human reviewed it. That gives you a cleaner way to spot patterns without digging through the whole AI response every time.