Integration and API Spec
The reference during the build: every tool connection, auth scope, field mapping, and error-handling rule.
Integration and API Spec
Lost Lead Re-engagement
[YourCompany.com] · Sales Department · Prepared by FullSpec · [Today's Date]
This document is the authoritative integration reference for the Lost Lead Re-engagement automation. It covers every tool connected to the orchestration layer, the exact authentication method and OAuth scopes required for each, field-level mappings between agent handoffs, the credential store structure, and defined error handling behaviour for every integration point. The FullSpec team uses this document to build, configure, and validate all connections. No credentials should be hardcoded in workflow logic; all secrets are stored in the centralised credential store as described in section 04.
01Tool inventory
02Per-tool integration detail
CRM of record. Used by Agent 1 to query inactive contacts, by Agent 2 to read contact context and log sent emails, and by Agent 3 to update lifecycle stage on sequence completion or warm reply.
Outbound email channel and inbound reply monitor. Agent 2 sends re-engagement emails from the assigned rep's Gmail account. Agent 3 monitors the same inbox for replies to tracked threads.
AI inference layer. Agent 2 calls the Chat Completions API to generate personalised re-engagement email copy for each sequence touch. Agent 3 calls the same API to score reply intent.
Alert delivery channel. Agent 3 posts a structured message to the assigned rep's Slack channel or direct message when a warm reply is detected.
Audit log and sequence tracker. Agent 1 writes one row per triggered lead at the start of each workflow run. Subsequent agents append status updates to the same row.
03Field mappings between tools
The following tables define the exact field-level mappings for each agent handoff in the automation. Field names are shown in monospace format as they appear in the respective tool's API response or payload schema. All intermediate values are passed as named variables in the orchestration layer's run context.
Handoff 1: Agent 1 (Lead Inactivity Monitor) to Agent 2 (Sequence Copywriter Agent)
Handoff 2: Agent 2 (Sequence Copywriter Agent) to Gmail and HubSpot
Handoff 3: Agent 3 (Reply Classifier and Router) to HubSpot and Slack
04Build stack and orchestration
// Credential store contents (all values stored as encrypted secrets)
// HubSpot
HUBSPOT_API_TOKEN // Private App bearer token
HUBSPOT_PORTAL_ID // HubSpot account portal ID (numeric)
HUBSPOT_PIPELINE_ID // Default deal pipeline ID
HUBSPOT_CLOSEDLOST_STAGE_ID // Pipeline stage ID for Closed Lost
// Gmail (one entry per rep; {REP_ID} is the HubSpot owner ID)
GMAIL_OAUTH_CLIENT_ID // Google Cloud OAuth 2.0 client ID
GMAIL_OAUTH_CLIENT_SECRET // Google Cloud OAuth 2.0 client secret
GMAIL_REFRESH_TOKEN_{REP_ID} // Per-rep refresh token (one per authorised account)
GMAIL_PUBSUB_TOPIC // Google Cloud Pub/Sub topic name for inbox push
GMAIL_TRACKED_LABEL_ID // Gmail label ID for 're-engagement-tracked'
// OpenAI
OPENAI_API_KEY // Organisation-level API key
OPENAI_MODEL // e.g. gpt-4o
OPENAI_DRAFT_TEMPERATURE // Float, e.g. 0.7
OPENAI_SCORE_TEMPERATURE // Float, e.g. 0.2
OPENAI_MAX_TOKENS_DRAFT // Integer, e.g. 600
OPENAI_MAX_TOKENS_SCORE // Integer, e.g. 100
// Slack
SLACK_BOT_TOKEN // OAuth bot token (xoxb-...)
SLACK_USER_MAP // JSON object: { "<hubspot_owner_id>": "<slack_user_id>" }
SLACK_FALLBACK_CHANNEL_ID // Channel ID for unroutable alerts
// Google Sheets
GOOGLE_SERVICE_ACCOUNT_JSON // Full service account key JSON (stringified)
SHEETS_AUDIT_LOG_ID // Spreadsheet ID of the audit log workbook
SHEETS_TAB_NAME // Sheet tab name, e.g. 're-engagement-log'
// Prompt templates (stored as configuration strings, not code)
PROMPT_EMAIL_TOUCH_1 // System + user prompt template for first touch email
PROMPT_EMAIL_TOUCH_2 // System + user prompt template for second touch email
PROMPT_EMAIL_TOUCH_3 // System + user prompt template for third touch email
PROMPT_REPLY_CLASSIFIER // System + user prompt template for intent scoring
// Orchestration
SEQUENCE_INTERVAL_TOUCH_2 // Integer days between touch 1 and touch 2, e.g. 5
SEQUENCE_INTERVAL_TOUCH_3 // Integer days between touch 2 and touch 3, e.g. 7
INACTIVITY_THRESHOLD_DAYS // Integer, e.g. 2105Error handling and retry logic
Every integration point has a defined failure behaviour. Unhandled exceptions must never fail silently. All errors must be logged to the orchestration platform's internal error log and, where appropriate, to the Google Sheets audit log. Retries use exponential backoff unless otherwise stated.
More documents for this process
Every document generated for Lost Lead Re-engagement.