( domain: string, context?: TriageContext )
| 448 | * Used for inbound website signups where the user will self-serve. |
| 449 | */ |
| 450 | export async function triageAndNotify( |
| 451 | domain: string, |
| 452 | context?: TriageContext |
| 453 | ): Promise<{ triaged: boolean; result: TriageResult }> { |
| 454 | const enabled = await isTriageEnabled(); |
| 455 | if (!enabled) { |
| 456 | return { |
| 457 | triaged: false, |
| 458 | result: { action: 'skip', reason: 'triage_disabled', owner: 'addie', priority: 'standard', verdict: 'Automatic triage is disabled.' }, |
| 459 | }; |
| 460 | } |
| 461 | |
| 462 | let result: TriageResult; |
| 463 | try { |
| 464 | result = await triageEmailDomain(domain, context); |
| 465 | } catch (err) { |
| 466 | logger.error({ err, domain }, 'Triage assessment failed'); |
| 467 | return { |
| 468 | triaged: false, |
| 469 | result: { action: 'skip', reason: 'assessment_error', owner: 'human', priority: 'standard', verdict: '' }, |
| 470 | }; |
| 471 | } |
| 472 | |
| 473 | if (result.action === 'skip') { |
| 474 | handleSkipSideEffects(domain, result, context); |
| 475 | logger.debug({ domain, reason: result.reason }, 'Triage: skip (assess-only)'); |
| 476 | return { triaged: true, result }; |
| 477 | } |
| 478 | |
| 479 | logger.info({ domain, owner: result.owner, priority: result.priority, companyName: result.companyName }, 'Triage: prospect identified (assess-only, no org created)'); |
| 480 | |
| 481 | // Notify Slack so the team has visibility, but don't create an org |
| 482 | notifyNewProspect({ |
| 483 | orgName: result.companyName || domain, |
| 484 | domain, |
| 485 | owner: result.owner, |
| 486 | priority: result.priority, |
| 487 | verdict: result.verdict, |
| 488 | companyType: result.companyType, |
| 489 | source: context?.source ?? 'inbound', |
| 490 | contactName: context?.name, |
| 491 | contactEmail: context?.email, |
| 492 | // No orgId — the user will create their own org during onboarding |
| 493 | }).catch(err => { |
| 494 | logger.warn({ err, domain }, 'Prospect notification failed'); |
| 495 | }); |
| 496 | |
| 497 | return { triaged: true, result }; |
| 498 | } |
| 499 | |
| 500 | // ─── Create prospect + notify ────────────────────────────────────────────── |
| 501 |
no test coverage detected