# HubSpot Integration

Two-way sync contacts and companies with HubSpot CRM.

## Setup

1. Go to Settings → Integrations
2. Click Connect on HubSpot
3. Enter your HubSpot Private App Token (starts with `pat-`)
4. Click Save

## Getting Your HubSpot API Key

1. Log in to HubSpot → Settings → Integrations → Private Apps
2. Create a new Private App
3. Grant scopes: `crm.objects.contacts.read`, `crm.objects.contacts.write`, `crm.objects.companies.read`
4. Copy the token (starts with `pat-`)

## Features

- Contact Sync: Push MailTrixy contacts to HubSpot in chunks of 100.
- Bulk Sync: Click "Sync Contacts Now" on the HubSpot card in Settings → Integrations to fire a one-shot bulk sync.
- Test Connection: The Connect flow verifies the Private App token before saving.

## HubSpot Card in the Inbox

When the HubSpot integration is active AND the conversation's contact email matches a HubSpot contact, a HubSpot card appears in the right-side details panel of that conversation.

How to see it:

1. Open a conversation.
2. Click the right-panel toggle in the top-right of the conversation header.
3. The HubSpot card appears below the Contact card.

What the card shows:

- Lifecycle stage badge — Lead / MQL / SQL / Customer / Evangelist / Other (from HubSpot's `lifecyclestage` property).
- Company & Job Title — from the matched HubSpot contact.
- Lead Status — if set in HubSpot.
- Deals — up to 5 associated deals with name, stage, and amount.
- "Open in HubSpot" — deep-link to the contact record in your HubSpot portal.

When the card does NOT appear:

- HubSpot integration is not connected for the workspace.
- The contact has no email.
- The contact's email is not in your HubSpot contacts list.

> Caching: the card is cached per-email for 5 minutes so repeated polling does not hammer the HubSpot API. New HubSpot records show up on the next refresh.