Repository navigation
feat(console): enrich Salesforce leads with Console account status - #54387
Conversation
There was a problem hiding this comment.
One of the four promised behaviours doesn't work yet: Enterprise form Leads still get LeadSource: "Website". I tested the handlers directly (no Salesforce org or Console lookup available).
How I checked
- The three new test files pass (25 tests), and
typecheckpasses inpackages/console/app. - I sent the exact body the
/enterprisepage posts throughhandleEnterpriseRequest, with the Console lookup set to fail. It returned 200 and the Lead was created with Description set to just the message, but withLeadSource: "Website". Details inline.
Public API: OpenCode's public API (SDK, server, plugins, config, CLI) is unchanged. On the Console website only, this adds a token-protected POST /api/console-signup endpoint, the CONSOLE_CRM_TOKEN secret and the CONSOLE_CRM_LOOKUP_URL link. The new endpoint needs Console to send a matching token, so the secret must be set on both sides before deploying.
Other concerns, most important first
- Lead source: the form never sends
leadSource(see inline). - Dev-only code in production: the dev-only hooks in the production handler and the
sfCLI dev server (see inline). - Tests: they could be much smaller.
console-signup.test.tsmakes its checks inside a fake Salesforce HTTP server and runs a 14-row table of email providers.salesforce.test.tsstarts a real server and rewritesprocess.envwhen the file loads.- Pure tests of
syncConsoleAccountwith a recordingrequestfunction, plus a few company-name cases, would cover the same ground.
- Salesforce metadata:
salesforce/checks in full copies of the org's Lead/Contact layouts and LeadSource values, and it's already applied to the org. That's a lot of org-specific config to keep in this open-source repo. Consider keeping only the field and permission metadata, or moving it next to the Console repo.
| email: body.email, | ||
| phone: body.phone, | ||
| inferenceSpend: inferenceSpend?.salesforceValue, | ||
| leadSource: body.leadSource === "enterprise website form" ? body.leadSource : undefined, |
There was a problem hiding this comment.
Enterprise form Leads will still get LeadSource: "Website". This line only uses enterprise website form when the request body says so, and routes/enterprise/index.tsx posts formData(), which has no leadSource. Nothing else in the repo calls /api/enterprise.
I confirmed it by running the handler with the page's exact body: the payload came out with LeadSource: "Website". Since this endpoint only serves the Enterprise form, could it set the source on the server and drop the field from the request body? Then clients can't control the value either.
| export async function handleEnterpriseRequest( | ||
| request: Request, | ||
| options: { | ||
| salesforceSubmit?: (payload: Record<string, unknown>) => Promise<boolean> |
There was a problem hiding this comment.
salesforceSubmit and notifications exist only for script/dev-enterprise.ts and the tests, but they're now part of the production handler. dev-enterprise.ts also brings a sf-CLI transport (salesforce-cli-response.ts plus its test) and a new dev:enterprise script. That's a second way to run the endpoint, and it needs its own upkeep.
Could this PR keep only accountLookup (or no options at all) and leave the local sf dev server out? The syncConsoleAccount(account, request) split already makes the logic testable without these hooks.
# Conflicts: # infra/console.ts # packages/console/app/package.json # packages/console/app/src/routes/api/enterprise.ts
Issue for this PR
No issue; internal sales tooling. Replaces #54255, which was closed when
devmoved to V2.Type of change
What does this PR do?
Sales needs to tell Enterprise form inquiries apart from Console signups in Salesforce, and to see whether someone already has a Console account.
enterprise website form, from both the current opencode.ai/enterprise page and the new Console page. Monthly spend goes only in its own field, and Description is exactly the visitor's message./api/console-signupendpoint, called by Console after a verified signup. It updates a matching Contact or Lead without changing its original source, or creates aconsole signupLead. Company is the email domain, orIndividualfor personal email providers.salesforce/holds the field, layout, permission, and Lead-conversion metadata (already applied to our Salesforce org).Both directions use a shared server token. Set the
CONSOLE_CRM_TOKENSST secret (same value as Console's) before deploying. Companion Console PR: anomalyco/opencode-console#3392.How did you verify your code works?
bun test(Salesforce, signup, and CLI-response tests) andbun typecheckinpackages/console/app;bun run checkpasses.Screenshots / recordings
No UI changes.
Checklist