Back to Recipes

CRM Automation Pipeline

Auto-enrich, auto-tag, auto-assign, and auto-follow-up with leads in your CRM using AI.

Best for: Sales teams drowning in manual CRM data entry

What You Get

  • -Lead enrichment automation
  • -Intelligent lead scoring and tagging
  • -Auto-assignment to sales reps
  • -Follow-up sequence triggers
  • -CRM health dashboard

Step by Step

1. Set up CRM webhook listener

Create a webhook endpoint in Next.js that receives new contact events from HubSpot (or Salesforce). Validate the webhook signature. Incoming lead data includes: name, email, company, phone, source. Store in a local PostgreSQL table as a processing queue.

2. Build the enrichment service

For each new lead, use OpenAI to enrich: look up company domain from email, fetch website content via Playwright, extract company size range, industry, tech stack, and funding stage. Also look up the lead's LinkedIn headline for role seniority.

3. Implement lead scoring

Use OpenAI to score each lead as hot/warm/cold based on: company fit (target industry match), role seniority (C-level/VP vs manager), engagement signals (opened emails, visited pricing page), and budget indicators.

4. Build auto-tagging

Use OpenAI to generate relevant tags from lead and company description. Tag examples: 'tech-startup', 'enterprise-50+', 'e-commerce', 'SaaS', 'marketing', 'founder'. Apply tags to CRM contact record via API.

5. Implement auto-assignment

Build a routing engine: hot leads go to senior sales reps (round-robin), warm leads go to junior reps, cold leads go to a nurture sequence (automated email drip). Validate assignment with a 1-hour cooldown per lead.

6. Build the dashboard

Create a metrics dashboard: enrichment stats (leads enriched, enrichment success rate), assignment accuracy (follow-up rate per rep), pipeline stats (hot/warm/cold distribution), and conversion tracking.

Stack

HubSpot/Salesforce APIOpenAIPostgreSQLNext.jsCron jobs

Build This

Copy this prompt and paste it into Claude Code, OpenCode, Codex, or Cursor to build this recipe.

Build a CRM automation pipeline that enriches, scores, and routes leads automatically. ROLE: You are a lead management system that monitors CRM data, enriches lead information, scores lead quality, assigns leads to appropriate reps, and triggers automated follow-up sequences. CONSTRAINTS: - Lead enrichment must complete within 30 seconds per lead; skip enrichment if timeout occurs and log the failure - Lead scoring must be based on company fit (size, industry, funding) and engagement signals (website visits, email opens) - Auto-assignment rules: hot leads → senior reps, warm leads → junior reps, cold leads → nurture sequence - Follow-up emails must be sent within 5 minutes of hot lead detection - All automation actions must be logged with timestamps for audit and debugging TOOL CALLING: - Use function calling for: watch_hubspot_leads(poll_interval?), enrich_lead(lead_id), score_lead(lead_id, scoring_model?), assign_lead(lead_id, assignment_rules?), send_followup(lead_id, template_id), get_pipeline_stats(date_range?) - Each tool returns structured JSON with lead data and action metadata STRUCTURED OUTPUT: - Lead enrichment must return JSON: { lead_id: string, company: { name: string, size: 'small' | 'medium' | 'large', industry: string, funding_stage?: string }, social_profiles: [{ platform: string, url: string }], enriched_at: string } - Lead score must return JSON: { lead_id: string, score: number, classification: 'hot' | 'warm' | 'cold', factors: [{ factor: string, weight: number, value: string }], scored_at: string } - Pipeline stats must return JSON: { total_leads: number, enriched: number, scored: number, assigned: number, followups_sent: number, conversion_rate: number, period: string } CHAIN OF THOUGHT: - Monitoring: poll HubSpot for new leads → check for duplicates → queue for enrichment - Enrichment: look up company info → find social profiles → compile enrichment data → store in database - Scoring: analyze company fit → evaluate engagement signals → apply scoring model → classify lead - Assignment: check rep availability → match classification to assignment rules → assign lead → log assignment - Follow-up: select email template → personalize with lead data → send via assigned rep → log send FEW-SHOT EXAMPLES: Lead: { name: 'Acme Corp', email: 'contact@acme.com', website_visits: 5, email_opens: 3 } Enrichment: { company: { name: 'Acme Corp', size: 'medium', industry: 'SaaS', funding_stage: 'series-a' }, social_profiles: [{ platform: 'linkedin', url: 'linkedin.com/company/acme' }] } Score: { score: 85, classification: 'hot', factors: [{ factor: 'company_size', weight: 0.3, value: 'medium' }, { factor: 'engagement', weight: 0.4, value: 'high' }] } Assignment: { assigned_to: 'senior_rep_1', reason: 'hot lead with high engagement' } EVALUATION CRITERIA: - Enrichment accuracy: percentage of enrichment fields that are correctly populated - Scoring accuracy: correlation between predicted score and actual conversion - Assignment appropriateness: percentage of leads assigned to the correct rep tier - Follow-up timeliness: percentage of hot leads that receive follow-up within 5 minutes The system should: 1) Watch for new leads in HubSpot (via webhook or polling), 2) For each new lead, enrich their data: look up company info (size, industry, funding), find social profiles, and estimate lead score (hot/warm/cold) using OpenAI based on company fit and engagement signals, 3) Auto-tag leads: assign tags like 'tech-startup', 'enterprise', 'e-commerce', 'SaaS' based on company description, 4) Auto-assign: route hot leads to senior reps, warm to junior reps, cold to nurture sequence, 5) Trigger follow-up: for hot leads within 5 minutes, send a personalized email from the assigned rep, 6) Log all automation actions to a pipeline dashboard showing enrichment stats, assignment accuracy, and conversion rates.

Common Failure Modes

  • !Over-enrichment with irrelevant data
  • !Wrong lead assignment from bad scoring
  • !Email fatigue from over-automation
  • !CRM API quota exhaustion

Implementation Notes

Start with enrichment only (no auto-assign or email) for 1 week to validate data quality. Add auto-assign in week 2. Add email in week 3.

Related skill: neon crm automation

Ship crm automation pipeline in production with 4M Labs

4M Labs designs and ships applied AI systems -- connected to your tools, secured for your team, deployed with monitoring.

  • Connected to your tools and data sources
  • Secured for your team with proper access controls
  • Deployed with monitoring and error handling
  • Documented for handoff and future maintenance
Work With 4M Labs

Frequently Asked Questions

Can I use this recipe in production?
Yes. Every recipe is production-tested with error handling, logging, and deployment guidance.
Which LLM providers are supported?
Recipes support OpenAI, Anthropic Claude, Google Gemini, and open-source models via a unified interface.
How do I customize these recipes?
Each recipe includes a configuration section. Override model selection, API keys, and parameters without changing core logic.