3.2 n8n - The "Central Brain" Router

The Logic that sorts the mail.

This is the most critical logic in the entire system. It lives inside the n8n Ingestion Workflow.

The Logic Flow

When an email arrives, we run this 3-step check:

Check 1: Who is the Sender? (The Stakeholder Match)

  • Query: Search Supabase stakeholders table where email matches the sender.

  • Result A: 0 Matches.

    • Action: Is the subject "New Deal"? If yes, start Onboarding Workflow. If no, mark as Spam/Unknown.

  • Result B: 1 Match.

    • Action: Check if the linked Deal is active. If yes, Route to Deal.

  • Result C: >1 Matches. (The Lender Problem).

    • Scenario: This lender is working on 5 active deals with us.

    • Action: Proceed to Check 2.

Check 2: Semantic Subject Match

  • Logic: If we have multiple potential deals, check the Email Subject Line against the property_address of the candidate deals.

  • Example:

    • Subject: "Appraisal for Maple"

    • Candidate 1: "123 Maple Ave" (Match!)

    • Candidate 2: "456 Oak St" (No match)

  • Action: If a clear winner is found, Route to Deal.

Check 3: The "Reply-To" ID

  • Logic: When Amy sends an email, she adds a hidden Message-ID header or a Ticket Reference (e.g., [DT-1234]) in the subject.

  • Action: Regex match the subject line for DT-xxxx. If found, force route to that Deal ID.

Gemini_Generated_Image_ugwzhdugwzhdugwz.png


Was this article helpful?
© 2025 DealTrail 3.0