# Lead Notes Button Sales

A GoHighLevel (GHL) browser extension script that injects a **Lead Notes** button into the conversation and contact detail views, enabling sales teams to log structured lead dispositions, milestone updates, and date tracking without leaving the CRM.

---

## Overview

This script runs inside a GHL environment and injects a **"Lead Notes"** navigation button into the conversation composer area. Clicking the button opens a modal that allows agents to:

- Select a lead disposition (organized by sales stage)
- Log date milestones tied to the lead's journey
- Submit a contract info form to trigger a DocuSign workflow
- Automatically apply CRM tags, update custom fields, and create notes on the contact record

The script is scoped to a **specific GHL location** (`Yjkpt82b8Vqjm10Ir9tD`) and will not activate on other accounts.

---

## Features

- **Stage-based disposition grid** — Buttons grouped into Pre Call 1, Call 1, Demo, and Post Demo stages
- **Smart date inputs** — Date fields that toggle between a date picker and a human-readable formatted display (e.g., `November 2nd 2025`)
- **Sidebar contact fields** — Pulls existing custom field values from the contact record and pre-fills the sidebar
- **Auto-highlight empty fields** — Empty date inputs are flagged in red and auto-focused when a disposition is selected
- **Contract submission form** — Collects package, pricing, and contact info, then submits via a reCAPTCHA-protected form endpoint
- **Automatic CRM updates** on save:
  - Adds tags to the contact
  - Creates a note on the contact record
  - Updates lead milestone and lead action custom fields
  - Updates stage-specific date custom fields
  - Optionally creates a follow-up task
- **Route change listener** — Re-injects the button when navigating between conversations without a full page reload

---

## Configuration

| Constant | Location in Code | Description |
|---|---|---|
| `locationid` | `getLocationId()` | Parsed from the current URL automatically |
| Target Location ID | Hardcoded: `Yjkpt82b8Vqjm10Ir9tD` | The script only activates for this GHL location |
| reCAPTCHA Site Key | `generateCaptchaTokenForSendContract()` | `6LeDBFwpAAAAAJe8ux9-imrqZ2ueRsEtdiWoDDpX` |
| Contract Form ID | `submitSendContractForm()` | `ANeDHfijzFRMFJka5TAD` |
| Contract Submit Location | `submitSendContractForm()` | `ynCWf3Y4AEJ7hfQ4lVWE` |

Custom field IDs are hardcoded throughout `getSidebarFields()`, `sideBarCall1Fields`, and `sideBarDemoFields`. Update these if your GHL custom fields change.

---

## Usage

1. Navigate to a **conversation** (`/conversations/conversations/...`) or a **contact detail** page (`/contacts/detail/...`) in GHL.
2. The **Lead Notes** link will appear in the composer toolbar area.
3. Click **Lead Notes** to open the disposition modal.
4. Select a disposition button from the grid. The modal will show a notes text area and any relevant date fields.
5. Fill in the reason and any date fields, then click **Submit**.

---

## Lead Dispositions

Dispositions are grouped into four sales stages:

### Pre Call 1
| Button | Tags Applied |
|---|---|
| Not Interested | `not_interested`, `ni` |
| Bad Phone | `bad number` |
| Hot / Interested | `hot` |
| Blacklist | `blacklist` |

### Call 1
| Button | Tags Applied |
|---|---|
| Call 1 - Not Interested | `not_interested`, `ni` |
| Call 1 Scheduled | `call_1_scheduled` |
| Cant Afford | `call_1_complete`, `cant_afford` |
| Not Ready / Future | `call_1_complete`, `future-followup` |
| Call 1 No-Show | `call_1_no-show` |

### Demo
| Button | Tags Applied |
|---|---|
| Demo Scheduled | `call_1_complete`, `demo_scheduled`, `demo_upcoming` |
| Demo No-Show | `demo_no-show` |
| Gave Demo | `gave-demo` |
| Not Ready / Future | `gave-demo`, `future-followup` |
| Cant Afford | `gave-demo`, `cant_afford` |
| Demo Given - Not Interested | `not_interested`, `ni` |

### Post Demo
| Button | Tags Applied |
|---|---|
| Around the Boat | `gave-demo`, `around-the-boat` |
| Send Document | `gave-demo`, `around-the-boat`, `send_contract` |
| Send Lead Pricing | `gave-demo`, `Send_Lead_Price` |
| Closed / DND from Sales | `close_complete`, `dnd` |


---

## Contract Form

When a "Send Document" disposition is selected, a form collects:

- Full Name, Phone, Email
- Package selection (Standard / Sweet Spot / Enterprise)
- Promotional offers
- Upfront buildout fee description
- Client buildout fee (numeric, in USD)
- Ongoing retainer fee (numeric, in USD)
- Additional notes for DocuSign

On submit, the form:
1. Validates all required fields.
2. Generates a fresh reCAPTCHA Enterprise token.
3. POSTs the payload to the GHL form submission endpoint.
4. Updates the lead milestone and lead action custom fields on the contact.
5. Creates a note and applies tags to the contact record.

---

## API Integrations

All API calls target `https://services.leadconnectorhq.com/` and authenticate using `window.getToken()`.

| Function | Endpoint | Purpose |
|---|---|---|
| `getContactDetails()` | `GET /contacts/:id` | Fetch contact custom fields |
| `getConversationDetails()` | `GET /conversations/:id` | Resolve contact ID from conversation |
| `updateCustomField()` | `PUT /contacts/:id` | Update a custom field value |
| `getCustomValues()` | `GET /locations/:id/customValues/search` | Fetch location-level custom values |
| `getCustomFields()` | `GET /locations/:id/customFields` | Fetch custom field definitions |
| `getPipeline()` | `GET /opportunities/pipelines` | Fetch pipeline and stage data |
| `createOpportunityOrStage()` | `POST/PUT /opportunities/...` | Create opportunity or update pipeline stages |
| `getAssignedUser()` | `GET /users/:id` | Fetch assigned closer's name |
| `getuserdetails()` | `GET /locations/:id` | Fetch location timezone |
| `set_monetaryValue()` | `PUT /locations/:id/customValues/:id` | Update location-level custom values |
| `get_data_api()` | Generic wrapper | Notes, tags, tasks |
| `submitSendContractForm()` | `POST backend.leadconnectorhq.com/forms/submit` | Submit contract form |

---

## Code Structure

```
├── getLocationId()                  — Parses location ID from the current URL
├── appendLeadNotesButtonSpecial()   — Injects the Lead Notes button into the UI
├── modal_endchat()                  — Opens and populates the disposition modal
├── trigger_actions()                — Attaches all event listeners to modal elements
│   ├── .reason_action click         — Handles disposition button selection
│   ├── .btn_save_endchat click      — Saves note, tags, and custom fields
│   └── .green-lead-note-contract-button click — Handles contract form submission
├── getSidebarFields()               — Maps contact custom fields to sidebar inputs
├── getSpecialLocationData()         — Returns the disposition grid configuration
├── renderLeadNotesHTMLModals()      — Returns the modal HTML string
└── API helpers                      — getContactDetails, updateCustomField, etc.
```

---