Outcome: Signed inbound event in. Enriched, scored, and routed lead out. Provider failures queue for review, never silently reject.

Overview

What I built: an in-house inbound revenue router. A local Express service receives the signed webhook event, normalizes the lead, records it in SQLite, enriches via Apollo, scores with a language model against a strict ICP, validates the assessment in code, and routes qualified and manual-review leads to HubSpot sandbox and Slack. A small dashboard shows leads, audit timelines, and stats.

The problem this solves: inbound events arrive faster than RevOps can enrich and route them, and a failed provider call looks exactly like a rejected lead. This system tells the two apart every time. Rejected, malformed, freemail, and duplicate records stay auditable. They never create CRM records or qualified-lead cards.

The system, 6 stages: signed ingress with header auth. Event normalization with a stable idempotency key and an audit row. Apollo enrichment behind a gate that skips freemail, duplicates, and invalid events. Bounded model scoring that returns assessment JSON only. Deterministic validation plus ICP hard gates recomputed in code. Qualified or manual-review routing to HubSpot and Slack, rejections audit-only.

Results: 13 currently qualified events wrote CRM records plus Slack, each read back from the API, with zero stray writes across replay, conflict, rejection, and freemail. 12 complete with contact, company, deal, and association. One partial (Linear, company plus deal, contact predates the fix) caught a dead contact endpoint. 47 backend assertions green. The earlier n8n workflow proved the same routing before the in-house port. Full era tallies live in NOTES.md. Test portal only.

The model scores. Code decides. The scoring step returns JSON and cannot write anywhere. Separate tested service functions own HubSpot, Slack, and routing.

Tools and Integrations

Tool Role
Node plus Express plus SQLite Local service on port 3001. Webhook, normalization, audit store, scoring, routing, plus a dashboard with leads, audit, and stats endpoints
ngrok Ingress tunnel exposing the signed webhook for external delivery
Apollo Organization enrichment behind the enrichment gate. Domain pinned so the model can trigger enrichment but cannot point it elsewhere
OmniRoute model Self-hosted OpenAI-compatible gateway on the same host. Scores against the strict ICP, selected model recorded in the audit
HubSpot Sandbox Company plus Contact plus Deal with six custom props, search before create, update in place
Slack Qualified channel plus separate review channel. v5 SDR sections with links. URL buttons only in v1

History note: the n8n era (single 18-node local workflow, T1 through T5) proved ingress, ledger, gating, and routing before the port. It is superseded. n8n retirement is still open in the repo.

Architecture

graph LR
    A["ngrok<br/>Signed webhook<br/>X-Webhook-Secret"] --> B["Express<br/>Normalize +<br/>idempotency key"]
    B --> C["SQLite<br/>Audit row<br/>duplicate check"]
    C --> D{"Known<br/>event?"}
    D -->|no| Q["Audit only<br/>rejected"]
    D -->|yes| E["Enrich gate<br/>freemail + dup<br/>skip Apollo"]
    E --> F["Scoring step<br/>Apollo enrich +<br/>model JSON"]
    F --> G["Validate<br/>Strict contract<br/>code recomputes"]
    G --> H{"Gates<br/>pass?"}
    H -->|unknown| R["Manual review<br/>review channel"]
    H -->|known-no| Q2["Rejected<br/>audit only"]
    H -->|yes| I["HubSpot<br/>Search, create<br/>or update"]
    I --> J["Slack<br/>Qualified card<br/>with links"]
    C --> K["Dashboard<br/>Leads + audit<br/>stats API"]

    style A fill:#111111,stroke:#111111,color:#ffffff
    style B fill:#111111,stroke:#111111,color:#ffffff
    style C fill:#111111,stroke:#111111,color:#ffffff
    style E fill:#111111,stroke:#111111,color:#ffffff
    style F fill:#111111,stroke:#111111,color:#ffffff
    style G fill:#111111,stroke:#111111,color:#ffffff
    style I fill:#111111,stroke:#111111,color:#ffffff
    style J fill:#111111,stroke:#111111,color:#ffffff
    style K fill:#111111,stroke:#111111,color:#ffffff
    style Q fill:#333333,stroke:#333333,color:#ffffff
    style Q2 fill:#333333,stroke:#333333,color:#ffffff
    style R fill:#333333,stroke:#333333,color:#ffffff

1. Signed Ingress Plus Idempotency Ledger

Objective

Every event accepted once, auditable forever. Retries and replays change nothing.

Step by Step Process

Step What happens Detail
1 Authenticate the call Header secret on the webhook. Missing or wrong secret rejected. Secrets never in URLs or committed files
2 Require the envelope Production events carry event_id, source, event_type, and occurred_at. Accepted types are signup, demo_request, and pricing_view. Unknown types and missing IDs are auditable outcomes, never silent drops
3 Normalize and fingerprint Deterministic normalization plus payload fingerprint. Same event_id with same fingerprint replays the stored previous outcome with zero repeat writes. Same event_id with a different fingerprint returns a 409 conflict
4 Write one audit row One durable audit row per event, readable from the dashboard by event ID with a full timeline. Missing event IDs are exempt from dedupe so two of them never collapse into one

Live proof on the port: byte-identical replay returned the duplicate with zero repeat writes. Changed-payload replay returned 409 with the previous outcome preserved. The n8n era proved the same semantics. Tallies in NOTES.md.

Deliverables

Signed ingress, a strict event envelope, dashboard endpoints for leads, audit by event, and stats. Fixtures kept for every provider shape.