Route new HubSpot leads to a sales territory and ping Slack

By General Input

When a HubSpot contact lands with a street address, figure out the sales territory, write it back to HubSpot, and post the lead to the right Slack channel.

Integrations

  • HubSpot
  • OpenStreetMap Nominatim
  • Slack

Type

Agentic Task

Categories

  • Sales
  • Operations

Build an agent workflow that auto-routes new HubSpot contacts to a sales territory and posts a heads-up in Slack the moment they land.

Trigger: a HubSpot webhook on the contact.creation event. The webhook should hand the agent the new contact's ID so it can fetch the full record.

Integrations:

1. HubSpot (Get Contact, Update Contact).

2. OpenStreetMap Nominatim (Search / Forward Geocode).

3. Slack (Send a Message).

What the agent should do, in order:

Step 1. Read the contact. Pull the contact from HubSpot by ID and read firstname, lastname, email, company, address, city, state, zip, and country.

Step 2. Bail early if there is no usable street address. If only a country is present, or every address field is empty, do not geocode. Clear the territory property by writing an empty string and exit without posting to Slack.

Step 3. Geocode with Nominatim. Build a one-line address string from the available fields and call Search (Forward Geocode) with format=jsonv2 and limit=1. Send a descriptive User-Agent identifying this workflow (Nominatim rejects generic library defaults). Make exactly one Nominatim call per contact, never in parallel: the public instance is capped at one request per second. If you get HTTP 429 or 403, sleep at least 1500ms and retry once before giving up.

Step 4. Decide the territory from the geocoded country_code and state. Use this default matrix (edit to fit the team):

- West Coast: country=us AND state in California, Oregon, Washington. Slack channel #sales-west.

- East Coast: country=us AND state in New York, Massachusetts, New Jersey, Connecticut, Pennsylvania. Slack channel #sales-east.

- US Central: country=us AND everything else. Slack channel #sales-central.

- Canada: country=ca. Slack channel #sales-canada.

- EMEA: country in gb, ie, fr, de, nl, es, it, se, dk, no, fi, pl, pt, be, at, ch. Slack channel #sales-emea.

- APAC: country in jp, au, nz, sg, hk, in, kr, tw, my, th, id, ph, vn. Slack channel #sales-apac.

- LATAM: country in br, mx, ar, cl, co, pe, uy. Slack channel #sales-latam.

- Anything that doesn't match (or geocode returned no country) is treated as unmatched.

Step 5. Write the territory back to HubSpot. Use Update Contact to set a custom single-line-text contact property (default name: territory). On a match, set it to the territory name (e.g. West Coast). On unmatched or skipped-geocode cases, set it to an empty string so reporting cleanly surfaces 'no territory yet'.

Step 6. Post to Slack (only on a confident match). Use Send a Message to post into the territory's channel. Keep it short and scannable:

🆕 New {territory} lead: {first} {last} ({company if present})

📍 {full address}

🗺️ <https://www.google.com/maps/search/?api=1&query={lat},{lon}|View on Google Maps>

đź”— <https://app.hubspot.com/contacts/{portal_id}/contact/{contact_id}|Open in HubSpot>

Build the Google Maps link from the geocoded lat,lon. Format the message in Slack's mrkdwn (single asterisks for bold, <url|text> for links).

Step 7. On unmatched results, do not post to the territory channels. Either skip the post entirely or post a single-line note to a fallback channel like #sales-unrouted naming the country and state we did get, so a human can route it by hand. Make the fallback channel configurable.

Failure modes the agent should handle:

- HubSpot returns 404 (contact already deleted): log and exit cleanly.

- Nominatim returns an empty array or a result with no country: treat as unmatched.

- Slack returns channel_not_found for the territory's channel: fall back to the unrouted channel and mention the expected territory.

- HubSpot Update Contact fails because the territory property doesn't exist: surface a clear setup message ('Create a single-line text contact property named territory in HubSpot, then re-run') and exit.

Configuration knobs the user should be able to edit without touching code:

- The territory matrix (country/state → territory name + Slack channel).

- The HubSpot property name to write back to (default: territory).

- The fallback Slack channel for unrouted leads.

- Whether to include the contact's email and HubSpot owner mention in the Slack post.

Related prompts

Explore more prompts
Call overdue Xero customers with an AI collections agentWin back LiveChat visitors whose chats went unansweredTurn Mailjet email clicks into ranked HubSpot follow-upsiMessage campaign console with pre-flight checks and delivery boardChat quality review board for LiveChat support leadsA searchable RFP answer library your bid team drafts fromSee which target accounts just started advertising on LinkedInAccount health board that puts product usage next to your CRMLook up a customer's full chat history mid conversationLusha prospecting workbench with credit-safe reveals