Quick Overview
This workflow runs every six hours to pull open Salesforce opportunities, enriches selected deals with Gmail and Microsoft Outlook email context, uses OpenAI to score deal risk, writes the assessment back to Salesforce, and notifies teams in Slack with optional email escalation for critical deals.
How it works
- Runs every 6 hours and queries Salesforce for up to 100 open Opportunities via the REST API.
- Stops the run and posts a Slack message if the Salesforce fetch returns an error.
- Normalizes each Opportunity, computes activity/close-date metrics, and routes deals with missing required fields to a Slack channel for manual data cleanup.
- Applies a heuristic triage and immediately marks non-risky deals as healthy in Salesforce to avoid unnecessary AI analysis.
- For triaged deals, pulls recent related messages from Gmail and Microsoft Outlook, merges them, and builds a compact email engagement context (participants, reply counts, and silence gap).
- Sends the CRM and email context to OpenAI to produce a structured risk score, drivers, and recommended actions, then validates and cleans the AI output.
- Updates Salesforce with the assessed risk fields and, for non-low risk deals, posts a detailed Slack alert (with cooldown suppression) and emails leadership when the risk level is Critical.
Setup
- Add Salesforce OAuth2 credentials, set the SALESFORCE_INSTANCE_URL environment variable, and ensure the Opportunity custom fields used for risk tracking (for example Risk_Score__c, Risk_Level__c, Risk_Summary__c, and Deal_Health__c) exist.
- Add OpenAI credentials and confirm the selected model (gpt-4o-mini) is available in your OpenAI account.
- Add Slack OAuth2 credentials and update the target channel IDs for Salesforce failure alerts, incomplete-deal alerts, and risk alerts.
- Add Gmail OAuth2 credentials and Microsoft Outlook credentials (optional) so the workflow can retrieve deal-related email threads.
- Set the LEADERSHIP_EMAIL environment variable (or edit the node default) to define where Critical-risk escalation emails are sent.