Skip to content

Latest commit

 

History

History
45 lines (30 loc) · 3.54 KB

File metadata and controls

45 lines (30 loc) · 3.54 KB

Lead #690005 — Corrected Root Cause Analysis

Webhook Logs (3 webhooks received)

  1. Contact Created (17:07:54) — detected: unknown, action: fallback_contact

    • NO email/phone in this payload (just name, tags, country)
    • businessName NOT in this payload
  2. Pipeline Stage Changed (17:07:55) — detected: pipeline, action: pipeline_handler

    • Has opportunity info, pipeline stage = New Lead
  3. Customer Replied (17:07:56) — detected: message, action: message_handler

    • HAS the form data in message.body: "Company name: Holiness Church of God, Inc"
    • HAS email, phone, full contact data
    • This is the webhook that should have triggered contact enrichment

BUG 3: Segment "Unclassified" — REVISED ROOT CAUSE

The Contact Created webhook (#1) fired FIRST but had NO businessName or email. It created the lead with NULL businessName.

The Customer Replied webhook (#3) fired 2 seconds later with the form data containing "Company name: Holiness Church of God, Inc". This went through webhook-message.ts (message_handler), NOT webhook-contact.ts. The message handler doesn't run segment classification — it only processes the message content.

The businessName IS in the DB now ("Holiness Church of God, Inc") — it was enriched later via GHL API contact resolution. But by that point, the segment classification code in webhook-contact.ts had already run (and skipped because businessName was NULL at that time).

Wait — actually businessName IS "Holiness Church of God, Inc" in DB now. Let me check if the Contact Created webhook's fallback_contact handler ran classifySegment...

The fallback_contact action means it went through handleContactWebhook but the contact didn't have businessName at that point. The enrichment from GHL API (resolveGhlContactId) happened AFTER, which filled in businessName. But classifySegment runs inside if (lead && lead.businessName) which was FALSE at the time of the Contact Created webhook.

The GHL API enrichment (lines 76-106 of webhook-contact.ts) fills in businessName from the GHL contact, but the segment classification block (lines 108-135) runs AFTER enrichment. So if enrichment added businessName, the classification SHOULD have run.

ACTUAL BUG: The enrichment updates lead object (line 94: lead = { ...lead, ...updates }), and then line 108 checks lead.businessName. If enrichment added businessName, it should be truthy.

BUT: The Contact Created webhook (#1) at 17:07:54 had NO email/phone. The GHL API resolution (resolveGhlContactId) needs email or phone to resolve. If both are null, it returns null and enrichment doesn't happen. The businessName was added later by a different path (possibly the message webhook or a subsequent contact update).

So the flow was:

  1. Contact Created → no email/phone → GHL resolution fails → no enrichment → businessName=NULL → skip classification
  2. Customer Replied → message handler → adds conversation + enriches contact data from payload → businessName gets set
  3. But message handler doesn't run classifySegment!

BUG 2: nextFollowUpAt Stuck in Past

The 24hr stale takeover fix has a createdAt < 3 DAYS AGO filter (line 239). This lead was created Apr 8 (1 day ago). The filter blocks it.

FIX: Remove or reduce the 3-day filter for the stale takeover check specifically. The 24hr agent inactivity check should work regardless of lead age.

BUG 1: Conversation History Missing

Only 1 conversation in DB (the inbound form). Chris's outbound FB message is not captured. User suggests: Add GHL outbound message webhook to capture agent-sent messages.