Skip to content

About

AI-powered lead conversion system with 4 specialized agents

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

35 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Lead Conversion System

AI-powered lead management system for marketing agencies. Automatically responds to leads, follows up, and tracks engagement.

πŸš€ Live URLs

Resource URL
Live App https://lead-conversion-system.onrender.com
Dashboard https://lead-conversion-system.onrender.com/dashboard
Health Check https://lead-conversion-system.onrender.com/health
API (Leads) https://lead-conversion-system.onrender.com/leads

✨ Features

  • Auto-Response - Sends personalized email within seconds of lead submission
  • Lead Tracking - All leads saved to database with status updates
  • Dashboard - Real-time view of all leads and metrics
  • Interest Scoring - Track lead engagement (0-100 score)
  • Follow-up Ready - System prepared for automated follow-up sequences

πŸ“ Project Structure

lead-conversion-system/
β”œβ”€β”€ main.py                    # FastAPI app - webhook, API endpoints, dashboard
β”œβ”€β”€ requirements.txt           # Python dependencies
β”œβ”€β”€ render.yaml              # Render deployment config (web + worker)
β”œβ”€β”€ Procfile                # Alternative deployment config
β”œβ”€β”€ .env.example            # Environment variables template
β”‚
β”œβ”€β”€ integrations/            # External service integrations
β”‚   β”œβ”€β”€ supabase_client.py # Database operations
β”‚   β”œβ”€β”€ email.py          # Email sending (Resend)
β”‚   └── sms.py            # SMS sending (Twilio)
β”‚
β”œβ”€β”€ agents/                 # AI Agent system (LangGraph)
β”‚   β”œβ”€β”€ orchestrator.py   # Routes leads to appropriate agents
β”‚   β”œβ”€β”€ speed_to_lead.py  # First response agent
β”‚   β”œβ”€β”€ follow_up_engine.py # Follow-up sequence agent
β”‚   β”œβ”€β”€ database_reactivation.py # Dead lead reactivation
β”‚   β”œβ”€β”€ scoring.py       # Interest score tracking
β”‚   β”œβ”€β”€ scheduler.py      # Background job scheduler
β”‚   └── __main__.py      # Worker entry point
β”‚
β”œβ”€β”€ dashboard/             # Frontend UI
β”‚   └── crm-dashboard.html # Full CRM dashboard
β”‚
β”œβ”€β”€ scripts/               # Utility scripts
β”‚   β”œβ”€β”€ setup_database.sql # Database schema
β”‚   └── setup_test_client.py # Create test client
β”‚
└── supabase/
    └── schema.sql       # Complete database schema

πŸ’° Free Stack

Service Free Tier Purpose
Render 750 hrs/mo Python API hosting
Supabase 500MB PostgreSQL database
Google Gemini 15 RPM AI responses
Resend 100/day Email sending
Twilio $15 trial SMS (optional)

πŸ”‘ API Keys Needed

Service Key Name Purpose
Supabase SUPABASE_URL Database connection
Supabase SUPABASE_SERVICE_ROLE_KEY Admin database access
Google Gemini GEMINI_API_KEY AI response generation
Resend RESEND_API_KEY Email sending
Twilio TWILIO_ACCOUNT_SID SMS (optional)
Twilio TWILIO_AUTH_TOKEN SMS auth (optional)
Twilio TWILIO_PHONE_NUMBER SMS from number (optional)

🌐 API Endpoints

Lead Management

Endpoint Method Description
/webhook/new-lead POST Receive new lead β†’ save + send email
/leads GET Get all leads
/leads/{id}/followup POST Manually trigger follow-up

System

Endpoint Method Description
/health GET Health check
/test-email GET Test email sending
/dashboard GET CRM dashboard UI
/ GET Root page

πŸ“ Webhook Payload Format

{
  "client_id": "YOUR_CLIENT_ID",
  "name": "John Doe",
  "email": "john@example.com",
  "phone": "+1234567890",
  "source": "website",
  "message": "I'm interested in your services"
}

Required Fields:

  • client_id - Your client/agency ID (UUID)
  • name - Lead's name
  • email - Lead's email address
  • message - Lead's message

Optional Fields:

  • phone - Lead's phone number
  • source - Where lead came from (default: "website")

πŸ—„οΈ Database Schema

clients Table

Column Type Description
id UUID Primary key
agency_name TEXT Agency name
email TEXT Contact email
config JSONB Settings

leads Table

Column Type Description
id UUID Primary key
client_id UUID Foreign key to clients
name TEXT Lead's name
email TEXT Lead's email
phone TEXT Lead's phone
source TEXT Where lead came from
original_message TEXT Lead's message
status TEXT new, contacted, nurturing, dead, booked, won, lost
interest_score INT 0-100 engagement score
follow_up_count INT Number of follow-ups sent
last_contact TIMESTAMPTZ Last interaction timestamp
created_at TIMESTAMPTZ Record creation time
updated_at TIMESTAMPTZ Last update time

conversations Table

Column Type Description
id UUID Primary key
lead_id UUID Foreign key to leads
role TEXT user, assistant
content TEXT Message content
channel TEXT email, sms, chat
strategy TEXT Follow-up strategy used

events Table

Column Type Description
id UUID Primary key
lead_id UUID Foreign key to leads
event_type TEXT Type of event
metadata JSONB Additional data

πŸš€ Deployment

Render (Recommended)

  1. Push to GitHub
  2. Connect repo to Render
  3. Add environment variables
  4. Deploy!

See deploy.md for detailed instructions.

πŸ§ͺ Testing

Test Client ID

00814277-181b-47a1-94e5-e04827edaa2f

Test Webhook

curl -X POST https://lead-conversion-system.onrender.com/webhook/new-lead \
  -H "Content-Type: application/json" \
  -d '{
    "client_id": "00814277-181b-47a1-94e5-e04827edaa2f",
    "name": "Test Lead",
    "email": "test@example.com",
    "message": "Hello!"
  }'

πŸ“Š How It Works

1. Lead Submits Form
        ↓
2. POST /webhook/new-lead
        ↓
3. Lead Saved to Database (Supabase)
        ↓
4. Status Updated: "new" β†’ "contacted"
        ↓
5. Auto-Email Sent (Resend)
        ↓
6. Lead Appears in Dashboard

πŸ”§ Troubleshooting

Email not sending?

  • Check RESEND_API_KEY is set in Render environment
  • Check Resend dashboard for sent emails
  • Check spam folder

Webhook returning 500?

  • Verify database tables exist (run setup_database.sql)
  • Check RLS policies are disabled or allow inserts
  • Verify SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY are correct

Leads not showing in dashboard?

  • Refresh the page
  • Check browser console for errors
  • Verify /leads endpoint returns data

πŸ€– Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     LEAD CONVERSION SYSTEM                   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”‚
β”‚  β”‚   Webhook   β”‚  β”‚   Chat     β”‚  β”‚   Dashboard  β”‚         β”‚
β”‚  β”‚   (Leads)   β”‚  β”‚   API      β”‚  β”‚   UI        β”‚         β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜       β”‚
β”‚         β”‚               β”‚               β”‚                  β”‚
β”‚         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                  β”‚
β”‚                         β–Ό                                  β”‚
β”‚              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                       β”‚
β”‚              β”‚      SUPABASE       β”‚                       β”‚
β”‚              β”‚    (PostgreSQL)     β”‚                       β”‚
β”‚              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ License

MIT License - Use freely!


⭐ Star this repo if it helps you!

About

AI-powered lead conversion system with 4 specialized agents

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages