Phase 2 part 5: find people and verify emails with Hunter.io

Review gets Find people (Domain Search by the departments, seniority and
count set in Settings → Lead sources), Find their email (Email Finder for
a named person at a company), and Verify (one, or every unchecked address
in New). Every call is kept in enrich_runs (schema 9) with its result and
credits, and shown on the card. Nothing runs on a schedule. Sources are
shown by name (Hunter.io, origami.chat, explee.com).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 05:53:52 -07:00
co-authored by Claude Opus 5.5
parent efca73bcd4
commit 82d569da9c
18 changed files with 1348 additions and 11 deletions
+66 -1
View File
@@ -29,7 +29,18 @@ var Statuses = []string{StatusNew, StatusAccepted, StatusRejected}
// Where prospects come from. Later parts add discovery, enrichment and
// outside lead sources.
const SourceManual = "manual"
const (
SourceManual = "manual"
SourceHunter = "hunter" // people found by enrichment
)
// Email statuses. Empty means not checked.
const (
EmailValid = "valid"
EmailRisky = "risky" // the server accepts everything, or a personal webmail address
EmailInvalid = "invalid" // bounces, or a disposable address
EmailUnknown = "unknown" // the check couldn't tell
)
// Company is a prospective customer.
type Company struct {
@@ -279,6 +290,52 @@ func AddContact(d *db.DB, c Contact, now time.Time) (id int64, added bool, err e
return id, true, err
}
// SetEmail gives a person an email address found for them, with its
// verification status. It refuses a suppressed address, and one another
// prospect already has. The person's funnel steps get the address too, so
// the CRM and Stripe can be matched to them later.
func SetEmail(d *db.DB, id int64, email, status string) error {
email = strings.ToLower(strings.TrimSpace(email))
if crm.EmailDomain(email) == "" {
return fmt.Errorf("%q isn't an email address", email)
}
if sup, err := IsSuppressed(d, email, ""); err != nil || sup {
if err == nil {
err = fmt.Errorf("%s: %w", email, ErrSuppressed)
}
return err
}
var other int64
err := d.QueryRow(`SELECT id FROM prospect_contacts WHERE email = ? AND id != ?`, email, id).Scan(&other)
if err == nil {
return fmt.Errorf("%s already belongs to another prospect", email)
}
if !errors.Is(err, sql.ErrNoRows) {
return err
}
res, err := d.Exec(`UPDATE prospect_contacts SET email = ?, email_status = ? WHERE id = ?`, email, status, id)
if err != nil {
return err
}
if n, _ := res.RowsAffected(); n == 0 {
return ErrNotFound
}
_, err = d.Exec(`UPDATE funnel_events SET email = ? WHERE subject = ? AND email = ''`, email, Subject("contact", id))
return err
}
// SetEmailStatus records how a person's address checked out.
func SetEmailStatus(d *db.DB, id int64, status string) error {
res, err := d.Exec(`UPDATE prospect_contacts SET email_status = ? WHERE id = ?`, status, id)
if err != nil {
return err
}
if n, _ := res.RowsAffected(); n == 0 {
return ErrNotFound
}
return nil
}
// SetSignal changes the signal a company or person is tagged with (0:
// none), and moves their funnel events with them. A company's people who
// had the company's old signal follow it.
@@ -788,6 +845,14 @@ func SourceLabel(source string) string {
switch source {
case SourceManual:
return "added by hand"
case SourceHunter:
return "Hunter.io"
case signals.SourceOrigami:
return "origami.chat"
case signals.SourceExplee:
return "explee.com"
case "discovery":
return "Claude web search"
}
return source
}