Skip to content

Add AI synopsis to new company domain signup emails - #504

Closed
shanerbaner82 wants to merge 1 commit into
mainfrom
feature/company-domain-synopsis
Closed

Add AI synopsis to new company domain signup emails#504
shanerbaner82 wants to merge 1 commit into
mainfrom
feature/company-domain-synopsis

Conversation

@shanerbaner82

Copy link
Copy Markdown
Contributor

Summary

  • When the first user registers with a non-consumer email domain, the queued NewCompanyDomainRegistered mail to accounts@nativephp.com now optionally includes a Synopsis: line (30–50 words) covering what the company does and who the person is.
  • Synopsis generation runs inside the already-queued notification (toMail), so signup stays fast. It fetches https://{domain} (short timeout, HTML stripped to a text excerpt), then prompts an Anthropic Haiku agent via Laravel AI (CompanyDomainAnalyst).
  • Soft-fail: HTTP/AI errors are logged as warnings and the basic domain/name/email/time email still sends without a synopsis. Consumer domains and non-first users remain skipped.

How it works

  1. NotifyAccountsOfNewCompanyDomain unchanged (consumer skip + first-user-only).
  2. Queued NewCompanyDomainRegistered::toMail() calls CompanyDomainSynopsisGenerator.
  3. Generator fetches the company site excerpt → builds prompt (name/email/domain/excerpt) → CompanyDomainAnalyst::make()->prompt(...).
  4. Agent instructions: only confident public facts; no invented URLs; plain 30–50 word paragraph.

Config / prod

  • Published config/ai.php (laravel/ai). Anthropic key via ANTHROPIC_API_KEY.
  • Added ANTHROPIC_API_KEY= to .env.example.
  • Prod needs ANTHROPIC_API_KEY set (same as Bifrost). Without it, synopsis soft-fails and the basic email still goes out.
  • Note: this app is on laravel/ai v0.1.5, so the agent uses #[Provider('anthropic')] (string). Bifrost’s newer SDK accepts Lab::Anthropic / HasProviderOptions for disabling thinking; that API is not available here yet.

Tests

  • Extended NewCompanyDomainRegistrationTest: synopsis included on success (Http + AI faked); email still sent when AI throws; gmail still skipped; first/second user behavior unchanged.
  • ./vendor/bin/phpunit --filter NewCompanyDomainRegistrationTest — 5 passed.

Test plan

  • Confirm staging/prod has ANTHROPIC_API_KEY
  • Register a fresh company-domain user and verify accounts@ mail includes Synopsis when the site/AI succeed
  • Break AI key or block outbound HTTP and confirm the basic accounts email still arrives
  • Confirm gmail / second user on same domain still do not notify

Enrich the accounts@ notification with a soft-failing 30–50 word
Anthropic synopsis (company + person) generated off the web request
via the existing queued notification, using a site excerpt plus
Laravel AI Haiku agent.
@shanerbaner82

Copy link
Copy Markdown
Contributor Author

Closing — Shane wants this on Bifrost only, not nativephp.com.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant