Skip to content

Field notes04 of 04

From reply to deal, with agents in the loop

Every send and reply logged to the right HubSpot contact, every positive reply turned into a deal for its owner, and follow-ups drafted by Claude inside a workflow action with a send guard.

System
Email-to-deal automation with AI drafts
Stack
HubSpot CRM v3 API · Custom workflow actions · Cloudflare Workers · Workers KV · Cloudflare D1 · Microsoft Graph · Claude API · Resend
FIG. 01REPLY TO DEAL11:48 CTSample log of one positive reply: verified, matched to a contact, duplicate guards passed, deal created for the owner, owner emailed, event key stored.

Figures show illustrative sample data. Names, companies and values in them are invented.

01

The situation

The client runs outbound email to property owners from dozens of mailboxes on its own domains, and was moving to a new sending platform. Every send and every reply had to reach the right HubSpot contact, and a positive reply had to become a deal for the right owner without anyone watching an inbox.

The old setup logged sends through a CSV pipeline and a webhook worker that recorded every reply as an outgoing email, through a deprecated API, with no message or thread IDs to dedupe against.

  1. Component 1: Send logging

    A Worker receives each send event and logs it as an email on the matching contact through HubSpot's CRM v3 emails API. It matches by primary email, then additional emails, then the HubSpot ID stored on the lead, and keys each write so a live event and a later backfill of the same send are logged once.

  2. Component 2: Mailbox sync

    Every 15 minutes a Worker reads the main Microsoft 365 mailboxes through Graph delta queries and logs sent and received mail to the right contact, with the right direction and threading. A unique sync key on each email lets HubSpot reject duplicates itself. Auto-replies and bounces are skipped.

  3. Component 3: Reply routing

    When a reply is tagged Interested, Meeting Request or Information Request, a Worker creates the deal at the qualified stage for the right owner, sets the contact's lead status, and emails the owner the reply with a link to the deal. Replies the platform's AI could not categorize go to a person for review.

  4. Component 4: Guards against duplicates

    An open deal on the contact or the company blocks a new one. A unique same-day key on the deal makes HubSpot itself reject a duplicate. Each event is processed once.

  5. Component 5: Claude-written follow-ups with a send guard

    A custom workflow action sends nurture email through Microsoft Graph. Claude rewrites each approved message from the record and the conversation so far; if the model call fails, the approved text goes out as written. Opt-outs and do-not-contact statuses are checked in code before every send, and one call stops all sending.

  6. Component 6: A throttle gate

    A second custom workflow action holds enrolled records in a queue and releases them inside business hours at a set rate, completing each workflow step through HubSpot's callback API.

  7. Component 7: Webhook upkeep

    An hourly job keeps the send and reply webhooks registered on every active campaign, and fails when one stops delivering.

03Stack

  • HubSpot CRM v3 API
  • Custom workflow actions
  • Cloudflare Workers
  • Workers KV
  • Cloudflare D1
  • Microsoft Graph
  • Claude API
  • Resend

04

Results

  • Every send logged to its contact, with a backfill path that cannot double-log.

  • Mailbox correspondence logged every 15 minutes, replies as incoming, with full headers and threading.

  • A positive reply creates the deal and reaches its owner by email with the reply and a deal link.

  • Follow-up wording written per recipient. If the model fails, the approved text goes out; the AI never blocks a send.

  • Sending paced by a queue the team tunes from the workflow action's own settings: rate, window and time zone.

Your system could be the next note.

Bring the part of your business the CRM can't see yet. We'll show you how we build it.