Docs / How it works
Leads in the core
Layer: core. Decisions: crm/@dev/decisions/0019-leads-and-the-notion-pack-follow-the-live-crm.md, and 0044-a-lead-becomes-a-client-at-the-first-reply-sent.md (P97), which amends its point 1. Field list: app/projects/_template/notion-crm/schema/leads.json, module page 03-leads.md.
A lead is a request that is not yet a client: a website form, a message from an unknown email sender, a referral. Every project that sells has a Leads database, at the top level of its teamspace. The core does not care what writes it, only that the writer follows this contract; people handle the rows; the agent reads them and drafts.
Who writes what
| Writer | Writes | Never writes |
|---|---|---|
| The owner's backend (a site's form handler, e.g. django_notion), mail agent for an unknown sender | Name, Status = New (on create only), Source, Received at, Email, Phone, Company, Message, Details, Form, Source page, Page URL, Locale, Brand, Mailbox, Hub run id, ad-click columns | Status after create, Owner, Next step, Notes, Client |
| The Hub (core, P97, P145) | Status In progress at the first confirmed send of a reply to the lead, Spam on the owner's click and New on its Undo; Client at that send (the one Clients card with the lead's address, or the card it creates); one new Clients page per person who had none (Name, Email, Phone, Relationship Lead, Projects = the lead's project); on a known card it links, the lead's project added to Projects (never one removed) |
every intake field, Owner, Next step, Notes; never a delete; never another field of an existing Clients card |
| The agent (a session, P138) | Conversation summary: one line, its read of the lead (who, where, size, the next step), written once after the first draft when empty; the lead card shows it on top |
every other field; never overwrites a summary |
| People | Status, Owner, Next step, Notes, Client, Conversation summary | Hub run id |
- Idempotency.
Hub run idis the writer's key for one submission. A writer looks the row up by it before creating, so a retry never makes a second lead. - Brand is the project key of the lead's origin (P145, decision 0053): the site or product it came from. Leads keeps
Brand(the other databases useProjects): the backend writes it, the silence check filters on it and Clients'Project signalsreads it. Its options are named like the project's## Brandsrows (doc 16 section 3C) and match them by project key; a project's options never name another project's brands. A django_notion backend sets the key on the server, per site (NotionConfig.project_keys), never from the form; it writes the one option with that key,Project key: <key>as the first Details line, and in its admin notice anX-Project-Key: <key>header plus the same fixed first body line (a forward may drop the header). A lead for two products carries two. - The notice names the project (P145): only for a sender on
leads.notice_senders, the Mail reader takes the key fromX-Project-Key, else from the body line, and names the brand in its "lead notice" ops line. A header a stranger sets never chooses a brand: people's mail is branded by its recipient headers only (resolveBrand). The lead's brand of record staysLead.Brand. - A missing option stops the writer, not the form: if
SourcelacksEmailorBrandlacks the site, the writer must report it, never invent an option (django_notion leavesBrandempty and still writes the lead).hub install --only notion.projectsadds every brand's option. - Spam is a Status, not a deletion.
- A form field with no column of its own goes to
Details, oneLabel: valueline each. Secrets and honeypot fields never.
What the core does with leads
- Reads them (read only):
notion-dump leads <project>(token) prints the counts by Status, Brand and Source and three lists that mirror the live views: needs reply (New or no status, received before today), overdue (In progress, Next step before today), won without a client. A session without a token reads the same rows through the Notion connector and applies the same three rules. - Shows them (P97 S2): the server's Leads reader (
apps/server/src/clients/leads-reader.ts) lists the project's Leads with the hub token at start, every 15 minutes, and at once when the Mail reader sees a new lead notice. Mail ▸ Inbox has a New leads group below the clients who wrote (P98: a client who wrote is a conversation in progress, so it comes first): Status New or empty, received in the lastleads.window_days(default 14), one row per person, not dismissed and with no draft yet; older New rows are one muted count the Hub never writes.lead_rowskeeps decision 0013's minimum (page id, name, the reply address and the account email, brand, when, the Status as read, 120 characters of the Message, the person's own words: never Details, the form's metadata, P98; and since P138 four short facts of the form for the list row: the website or first site, the country, the segment, the expected volume, 60 characters each); the card reads the page from Notion when it opens and shows the form itself (P138): what they want first (known Details labels in a fixed order, then every other label), the contact channel and the sites they named, the agent's read fromConversation summaryon top, the checks before a reply (a mistyped domain from a fixed list, a client with the address or the company's domain, the forms one address sent), and the technical lines (locale, hosts, consent, environment, tracking) last and smaller, never folded. Mail ▸ Leads (P134, P138): a views control in the list header (New, Not now, Spam, Replied), the rows grouped by day. No token: the line says so and the dock reads Leads through the connector. - A notice is never a person (P97 S1): the mail a site's backend sends when a form lands (a sender on
leads.notice_senders, or a machine address the mail filters whitelist, such asrobot@…) is never an Inbox client row and is never answered. It only makes the Leads reader read at once. - Drafts for them (P97 S3): the lead card's Prepare reply pastes the bulk-drafts first-mail phrase into the dock; the agent writes a new thread to the lead's reply address (the email typed on the form, the
Contact channel: Email: …line of Details, else the LeadsEmail), signed asLead.Brand(draft_write'sbrand).draft_writeadmits a Leads row (Status not Spam) as a known person. A lead with only a phone or Telegram gets no mail draft.triage-mailstep 3b and the workflownew-website-leadstay for a lead that wrote by mail. - A Clients card at the first reply sent (P97 S4, decision 0044): after a confirmed send to a stored lead, before the P89 stamp, the server links the lead's Clients card (exactly one with that Email or Other emails), creates one (none: Relationship Lead) or says that several have the address, and sets Status New to In progress. Not at arrival (spam would fill Clients), not at the draft. A refusal (403: Insert content or Update content missing) is a note on the lead card and the doctor's
notion lead writesrow, never a failure of the send;notion.convert_leads offwrites nothing. - Spam (P97 S5): the card's Spam sets Status Spam, Undo sets New. The agent may propose it, never set it.
The daily passes (P147, decision 0055)
The server drafts the first replies itself, once a day per project, and sends nothing: the owner's one click does.
- The lead pass (
leads.pass, off in the core;leads.pass_at, default 09:30): one headless turn per open lead inleads.window_days, one at a time, in the autopilot pool's free slots (apps/server/src/passes/). Each turn is bound to its lead by page id and has eight hub tools (LEAD_PASS_HUB_TOOLS), no send tool. It decides one ofreply,client,spam,not_now,hand_over(lead_decide), with one sentence of reason, and writes the reply as a draft in the day's lead batch. A do-not-contact or already-answered lead is decided without a turn. It reads the form site and a non-free reply domain only (link_fetch) and answers in the client's language. - The mail pass (
mail.pass, off in the core;mail.pass_at, default 10:00;mail.pass_window_days, default 3): the same runner over Mail ▸ Needs you, one turn per sender's newest open message (mail_decide:reply,client,no_reply,spam,hand_over). Phishing and junk arespam. Its drafts join the same batch. A reply to an address the project never wrote to is a new sender: it opens unticked, and autosend holds it (mail-pass-first-reply). - Budgets: 30 turns a pass, one ledger (
lead_passes, itskind) and 60 turns a day on the Mac for both; three failed turns in a row stop a pass. Run now (the pass bar in Mail ▸ Leads, orlead_pass_startfrom the dock) at most 3 a day each. - Notion: a decision taken is mirrored to Leads'
Hub decisionandHub reason, only where Leads has them (hub install --only notion.lead-pass); never Status, Owner or Notes. - The one click (Mail ▸ Needs you and Leads, "Send all ready (N)"): one sheet of the day's replies, read from Mail when it opens, each ticked if it can go now. "Needs your input" holds a draft with an
[Owner: …]placeholder (a field per marker, filled through the one Mail writer), and "New senders" sits apart, both unticked. The proposals are one line ("Also mark 7 as spam / not now"), and the button is Send N. The click marks exactly the shown text accepted (the served hash), applies the ticked proposals, and leaves out of today only the rows the owner unticked. The run then sends one at a time, 20 s apart, within the day's cap, and stops on a Mail failure. The sheet opens at once on the Hub's own copy, then Send waits until Mail was read ("Checking N drafts in Mail…"); a selection reads only its drafts. After the click Mail ▸ Sent shows the run on top (rows, Stop), then "10 sent, 1 not sent (reason)" with Send again, read from the database so it stays after a restart; nothing resumes by itself. Other lists keep one line, "Sending 3 of 11 · Open". The run waits out its own spacing and never refuses its own mail for it. A fixed bug's note from the follow-up sweep (P145 B4) is one more row. The messenger door refuses a text with a placeholder left in it, as the mail door does. A list selection's Send N opens the same sheet with only those drafts;/mail/leads/review/<batch>is the same list as a page. - Junk: a mail pass's
spamproposal, once ticked, moves the message to its account's Junk in Mail (recoverable) and takes the sender out of Needs you, with an Activity line. The owner's Spam and Delete (the conversation pane, the list's selection; P147 3n) move any sender's message to Junk or Trash, both recoverable in Mail, never a permanent delete. In the sessions the owner starts,mail_junkmoves one at once (to: junkortrash), and is refused for a known sender: a Clients card, a mail we sent, a lead.
Whether a form still delivers a lead at all (page, CSP, endpoint, the signed canary) is a separate check: 22-lead-forms.md.
Access
Which integration needs access to Leads and Clients (the backend that writes, the hub that reads) and how to share it: ../setup/access.md. hub doctor fails notion.access on leads when the hub's integration cannot see it.
Update this page when the architecture changes.