Skip to content
MaccabiCapitalPublic

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Talkerstein Proposal Automation

Next.js 14 App Router application that turns an 18-field intake form into a branded Google Doc proposal, a GoHighLevel contact/opportunity, an audit row in a Google Sheet, and a Slack notification — all from a single POST.

Stack

  • Next.js 14 (App Router) + TypeScript
  • Tailwind CSS with Talkerstein brand tokens (navy #152857, orange #FF8731, burnt sienna #B3530E, beige #F7F6F3, Jost font)
  • Node 20+
  • @anthropic-ai/sdk for proposal copy (Claude claude-sonnet-4-5, override with ANTHROPIC_MODEL)
  • googleapis for Drive, Docs, Sheets
  • fetch for GoHighLevel API v2 and Slack incoming webhook
  • zod for schema + env validation

No database. No auth. No DocuSign. No PandaDoc. No new SaaS.

Repo layout

/app
  layout.tsx                 Root layout, brand header
  page.tsx                   Redirect to /intake
  globals.css                Tailwind + brand variables
  /intake
    page.tsx                 18-field intake form page
    /success
      page.tsx               Confirmation + proposal ref #
  /api
    /generate/route.ts       Main POST orchestrator (90s budget)
    /health/route.ts         GET health check
/components
  IntakeForm.tsx             Form with conditional GHL section + live margin
  FormField.tsx              Reusable field wrapper
  PackagePicker.tsx          Multi-select for package codes
/lib
  anthropic.ts               Claude client + generateProposalContent()
  google-auth.ts             Shared service-account JWT
  google-docs.ts             Copy template + replaceAllText render
  sheets.ts                  nextRefNumber() + logProposal()
  ghl.ts                     Contact, opportunity, contract, e-sign, Stripe
  slack.ts                   notify() + notifyFailure()
  prompt.ts                  Exported PROPOSAL_SYSTEM_PROMPT
  packages.ts                Package module library (B/W/M/G/GM/C)
  schema.ts                  Zod schema for intake
  margin.ts                  Margin calc (RED < 55%)
  retry.ts                   Exponential-backoff retry helper
/config
  env.ts                     Typed, Zod-validated env loader
/public
  talkerstein-logo.svg       Placeholder logo
README.md
ARCHITECTURE.md
.env.example
package.json, tsconfig.json, tailwind.config.ts, postcss.config.js,
next.config.js, railway.json, vercel.json, .gitignore

Local setup

git clone <this repo>
cd intake
cp .env.example .env
# fill in the values (see sections below)
npm install
npm run build
npm run start   # or: npm run dev

The build does not require real env vars — env is only validated when a route or function that touches an external API is actually called. /api/health works with zero secrets.

Environment variables

All ten variables in .env.example must be present in production. Build passes without them; runtime integration calls will throw a descriptive Zod error.

Var What it is Where to get it
ANTHROPIC_API_KEY Anthropic API key console.anthropic.com → API Keys
GOOGLE_SERVICE_ACCOUNT_JSON Full service-account JSON, stringified See Google setup below
GOOGLE_DOCS_TEMPLATE_ID Google Doc template file ID URL of template doc
GOOGLE_DRIVE_FOLDER_ID Destination Drive folder for generated docs URL of folder
GOOGLE_SHEETS_AUDIT_ID Audit Sheet ID URL of sheet
GHL_API_KEY GoHighLevel private integration key GHL → Settings → Integrations
GHL_LOCATION_ID GHL sub-account ID GHL → Settings → Business Info
GHL_WORKFLOW_ID_SEND_PROPOSAL Workflow to trigger after contract created GHL → Automation → Workflows
SLACK_WEBHOOK_URL Incoming webhook URL api.slack.com/apps → Incoming Webhooks
APP_BASE_URL Public URL of this app e.g. https://proposals.talkerstein.com
ANTHROPIC_MODEL (Optional) Override Claude model ID. Defaults to claude-sonnet-4-5. Anthropic model catalog

Google setup

  1. Create a new Google Cloud project (or reuse one).
  2. Enable the Google Docs API, Google Drive API, and Google Sheets API.
  3. Create a service account and generate a JSON key. Download the file.
  4. Paste the entire JSON contents (single line, quoted) into GOOGLE_SERVICE_ACCOUNT_JSON. Both \n and real newlines in private_key are handled by lib/google-auth.ts.
  5. In Google Drive, share the template doc, destination folder, and audit sheet with the service account's client_email as an Editor.
  6. Copy the template file ID, folder ID, and sheet ID from each item's URL and put them in the matching env var.

Template placeholders

The template must contain these literal tokens. They are replaced via docs.documents.batchUpdate → replaceAllText.

{{COMPANY_NAME}}      {{CONTACT_NAME}}      {{DATE}}
{{REF_NUMBER}}        {{PROBLEM_STATEMENT}} {{PACKAGE_CODES}}
{{PACKAGE_DESCRIPTION}}  {{SCOPE_IN}}       {{SCOPE_OUT}}
{{TOTAL_UPFRONT}}     {{MONTHLY}}           {{PAYMENT_TERMS}}
{{MILESTONE_1}}       {{MILESTONE_2}}       {{MILESTONE_3}}

To swap in a new template: update the doc → make sure every placeholder above still appears verbatim → put the new file ID in GOOGLE_DOCS_TEMPLATE_ID. No code changes needed.

GoHighLevel setup

  1. Get a Private Integration API key from GHL → Settings → Integrations → API. This is the v2-compatible Bearer token.
  2. Copy your Location ID from Settings → Business Info.
  3. (Optional) Create a workflow named "Send Proposal" and copy its ID into GHL_WORKFLOW_ID_SEND_PROPOSAL.

Deploy to Railway

  1. Create a new Railway service from this repo.
  2. Add all env vars from .env.example.
  3. Railway auto-reads railway.json — build runs npm run build, start runs npm run start, and /api/health is polled as the healthcheck.

Deploy to Vercel

  1. vercel → link the project.
  2. Add all env vars in the Vercel dashboard.
  3. vercel.json pins /api/generate to Node 20 with a 90s function timeout.

Sample curl

curl -X POST https://proposals.talkerstein.com/api/generate \
  -H 'Content-Type: application/json' \
  -d '{
    "companyName": "Ridgeline HVAC",
    "primaryContact": {
      "name": "Sam Novak",
      "email": "sam@ridgelinehvac.com",
      "phone": "+15551234567",
      "title": "COO"
    },
    "industry": "Home services",
    "websiteUrl": "https://ridgelinehvac.com",
    "painPoint": "More than half of inbound after-hours calls are never returned.",
    "priorAttempts": "Hired a part-time answering service last year; volume and quality were inconsistent.",
    "urgencyTrigger": "Entering peak season in 4 weeks.",
    "packageCodes": ["B2"],
    "ghlAddOns": ["G2"],
    "ghlManagedAddOns": ["GM2"],
    "consultingAddOns": [],
    "markupPercent": 30,
    "scopeIn": {
      "bullet1": "Two-pipeline CRM build with lead routing",
      "bullet2": "Missed-call-text-back and reactivation sequences",
      "bullet3": "Calendar booking for service windows"
    },
    "scopeOut": {
      "bullet1": "Paid media spend and ad account management",
      "bullet2": "New marketing website"
    },
    "totalUpfront": 28000,
    "monthlyRecurring": 3750,
    "paymentSplit": "50/50",
    "milestones": {
      "m1": { "description": "Intake + pipeline build", "date": "2026-05-08" },
      "m2": { "description": "Automation + missed-call flows", "date": "2026-05-22" },
      "m3": { "description": "Training + go-live", "date": "2026-06-05" }
    },
    "salesOwner": "Rish",
    "deliveryLead": "Rems"
  }'

Response shape:

{
  "success": true,
  "requestId": "req_…",
  "refNumber": "TCG-2026-0001",
  "docUrl": "https://docs.google.com/document/d/…/edit",
  "ghlContractId": null,
  "ghlContactId": "…",
  "ghlOpportunityId": "…",
  "ghlWarnings": ["TODO: GHL upload-contract endpoint …"],
  "internalFlags": [],
  "marginPercent": 62.3,
  "marginIsRed": false
}

Known Unknowns (GHL)

GoHighLevel's public v2 API surface is not stable for contract/document workflows. We refused to guess. The following calls are intentionally unimplemented and emit a TODO warning plus a console.warn:

  1. Upload Google Doc as a signable Contract/Document. There is no reliable public v2 endpoint. Fallback: attach the doc URL as a note on the contact.
  2. Enable e-sign on a contract. Handle manually in the GHL UI until the endpoint is confirmed.
  3. Attach a Stripe deposit link to an opportunity. The deposit amount is calculated per the paymentSplit rule and logged; attach manually.
  4. Opportunity pipeline/stage IDs. Required fields are not part of the intake. Opportunities are attempted without pipelineId and a warning is surfaced if GHL rejects.

The warnings are returned in the ghlWarnings array on the success response and posted to Slack. Once Rishon confirms the correct endpoints, wire them up inside lib/ghl.ts — no other file needs to change.

Maintainer's Guide

Everything operators typically want to change lives in three files. None of them require touching the orchestrator (app/api/generate/route.ts).

  • Prompt / tone / output shape: edit PROPOSAL_SYSTEM_PROMPT in lib/prompt.ts. Few-shot examples live in lib/anthropic.ts (FEW_SHOT_EXAMPLES). Update the JSON shape in both places if you add a field and also extend GeneratedProposal in lib/anthropic.ts and the template placeholders in lib/google-docs.ts.
  • Package codes, names, descriptions, costs, prices: edit the PACKAGES object in lib/packages.ts. The UI picker, margin calculator, Claude prompt, and Doc renderer all read from this single source of truth.
  • Brand colors: edit tailwind.config.ts (colors.navy, colors.orange, colors.sienna, colors.beige) and the :root variables in app/globals.css.
  • Margin threshold: MARGIN_RED_THRESHOLD in lib/margin.ts.
  • Ref number format: nextRefNumber in lib/sheets.ts.

Quality bar

  • External APIs retry 3× with exponential backoff (lib/retry.ts). Claude is called once (no retry).
  • Every external call logs with a request ID (req_<timestamp>_<nonce>).
  • Type-safe end to end. any is avoided in application code.
  • Build passes without real env vars — env is validated lazily at call time.
  • Node 20+ only.

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages