Auto-route new HubSpot contacts to the right sales territory

Every new HubSpot contact gets geocoded, assigned to the closest sales territory, and announced in the right Slack channel within seconds.

Deterministic Code
HubSpotGeolocationSlackSalesOperationsLead EnrichmentNotifications & AlertsData Sync

Build me a code workflow that auto-routes new HubSpot contacts to a sales territory and announces them in Slack.

Trigger: a HubSpot outgoing webhook that fires whenever a new contact is created. Subscribe to contact.creation events and pull the contact id out of the webhook payload.

Step 1. Fetch the contact from HubSpot using the id from the webhook. Read at minimum: firstname, lastname, email, company, address (street), city, state, zip, and the HubSpot record URL for that contact.

Step 2. Geocode the address with the Geolocation integration's Forward Geocode operation. Concatenate street, city, state, and zip into a single query string.

Step 3. If geocoding fails, returns no result, or returns an ambiguous low-confidence match, set territory to "unassigned", skip the distance step, and continue straight to step 6 using the review channel.

Step 4. Pick the closest territory using the Geolocation integration's Calculate Distance Matrix operation. The geocoded contact location is the single origin; the destinations are a configurable list of territory HQs declared at the top of the workflow. Default the list to:

- Northeast HQ: New York, NY -> #sales-northeast

- Southeast HQ: Atlanta, GA -> #sales-southeast

- Central HQ: Chicago, IL -> #sales-central

- West HQ: San Francisco, CA -> #sales-west

Pick the territory with the shortest driving distance. Keep both the chosen territory name and the miles from its HQ for the Slack message.

Step 5. Update the HubSpot contact using the HubSpot Update Contact operation. Write three custom properties: hs_latitude (the geocoded latitude), hs_longitude (the geocoded longitude), and territory (the chosen territory name, or "unassigned" on geocoding failure). Add a short note in the workflow that these three custom contact properties must be created in HubSpot before the workflow runs.

Step 6. Post a Slack message with the Slack integration's Send a Message operation. On a successful match, post to the matched territory's channel. On failure or unassigned, post to a configurable review channel that defaults to #leads-needs-review. The message should be short, one or two lines plus the link, and include: contact full name, company, geocoded address, miles from the territory HQ (rounded), and a link to the contact in HubSpot.

Make the following easy to edit at the top of the workflow: the HubSpot account, the Slack workspace, the territory-to-channel map, and the review channel name. Keep the flow deterministic and linear: webhook -> fetch contact -> geocode -> distance matrix -> update HubSpot -> post to Slack.

Additional information

What does this prompt do?
  • Fires the instant a new contact is created in HubSpot, whether the contact came from a form, an import, or was added by hand.
  • Looks up the contact's address, finds the closest sales territory from a list you define, and writes the territory plus latitude and longitude back to the contact record.
  • Posts a short Slack alert in that territory's channel with the contact name, company, address, miles from HQ, and a one-click link to HubSpot.
  • Routes contacts with missing or ambiguous addresses to a review channel instead of guessing, so your team can sort them by hand.
What do I need to use this?
  • A HubSpot account where you can set up outgoing webhooks and edit contact properties
  • Three custom contact properties in HubSpot for latitude, longitude, and territory
  • A Slack workspace with one channel per sales region, plus a review channel for unclear addresses
  • A short list of territory names and HQ cities you want to route by, for example Northeast HQ in New York and West HQ in San Francisco
How can I customize it?
  • Swap the starter territory list for your real regions, like EMEA, APAC, Central, or Mountain, and point each one at the Slack channel you already use.
  • Change what shows up in the Slack alert. Add lifecycle stage, lead source, deal owner, or any other HubSpot property your team wants to see at a glance.
  • Tweak the routing logic. After the workflow is generated, you can layer in company size, industry, or annual revenue to override pure geography for strategic accounts.

Frequently asked questions

Will this work for contacts created by form submissions, imports, or other integrations?
Yes. The workflow listens for any contact creation event in HubSpot, so form fills, manual entry, CSV imports, and inbound integrations are all covered.
What happens if the contact's address is missing or unrecognizable?
The contact's territory is set to unassigned and the alert goes to a review channel instead of a regional one, so a human can sort it without slowing down the rest of your team.
Does it use straight-line distance or actual driving distance?
Driving distance. The workflow calculates real travel distance from each territory HQ, so a contact two hours away by car beats one that is closer as the crow flies but across a mountain range.
Do I need a Google Maps account or my own API key?
No. Geocoding and distance lookups run on the General Input platform, so there is no extra account to set up and no separate billing to track.
Can I route on more than just location, like company size or industry?
Yes. The starter workflow routes by geography, but once it is built you can add HubSpot properties like company size, industry, or annual revenue as additional rules on top.

Stop hand-routing new HubSpot leads.

Connect HubSpot, Slack, and your territory list once, and every new contact lands in front of the right rep within seconds.