A fully automated customer referral system built for LEX Air Conditioning. Integrates with ServiceTitan, Chiirp, and Tango Card.
- Job completes in ServiceTitan → ST fires a webhook to this app
- App creates/updates customer record in Supabase with a unique referral link
- Chiirp sends a referral invite text to the customer automatically
- Customer shares their link — the landing page on lexair.com handles everything
- Friend clicks the link → lands on the referral page, calls to book
- Friend's job completes in ST → app validates the referral (job ≥ $150)
- Tango Card sends a $75 gift card to the referrer's email automatically
- Chiirp sends a "your reward is on the way" text to the referrer
Zero manual steps for your office staff.
lex-referral-app/
├── src/
│ ├── index.js # Express server entry point
│ ├── db.js # Supabase client
│ ├── routes/
│ │ ├── webhooks.js # ServiceTitan webhook handler (core logic)
│ │ └── api.js # Public API for WordPress frontend
│ ├── services/
│ │ ├── chiirp.js # Text messaging
│ │ └── tango.js # Gift card fulfillment
│ └── utils/
│ └── slugs.js # Referral link generation
├── sql/
│ └── schema.sql # Supabase database schema (run once)
├── wordpress/
│ └── lex-referral.php # WordPress plugin (upload to site)
├── .env.example # Environment variable template
├── package.json
└── README.md
- Go to supabase.com and create a free account
- Create a new project (name it "lex-referral")
- Go to SQL Editor and paste the contents of
sql/schema.sql→ Run it - Go to Settings → API and copy:
- Project URL →
SUPABASE_URL - Service role key (secret) →
SUPABASE_SERVICE_KEY
- Project URL →
- Push this repo to GitHub (make sure
.envis in.gitignore!) - Go to railway.app and create a new project
- Connect your GitHub repo
- Add environment variables (copy from
.env.example, fill in real values) - Railway auto-deploys — copy your app URL (e.g.
https://lex-referral-app.up.railway.app)
- In ServiceTitan: Settings → Integrations → Webhooks
- Add a new webhook:
- URL:
https://your-railway-url.up.railway.app/webhooks/servicetitan - Events: Job Completed, Booking Created
- Secret: Use the value you set for
ST_WEBHOOK_SECRET
- URL:
- Upload
wordpress/lex-referral.phpto/wp-content/plugins/lex-referral/ - Activate it in WordPress → Plugins
- Update the
LEX_REFERRAL_API_URLconstant at the top of the file to your Railway URL - Create a WordPress page:
- Title: "Referral"
- Slug:
referral(so URL is lexair.com/referral) - Content:
[lex_referral]
- Create an account at tangocard.com
- Fund your account (they draw from this balance for gift cards)
- Get your API credentials → add to
.env
- In Chiirp: Settings → API → Generate Key
- Get your sending phone number
- Add both to
.env
| Variable | Default | Description |
|---|---|---|
MIN_JOB_VALUE |
150 | Minimum job total for referral to qualify |
REFERRER_REWARD |
75 | Gift card amount sent to referrer |
NEW_CUSTOMER_DISCOUNT |
50 | Discount shown on landing page |
Your Supabase project includes a built-in table editor that shows you the full referral pipeline. No custom admin panel needed to start.
Monitor these tables:
- referrals — filter by
statusto see pending/booked/rewarded - texts_log — see every text sent
- job_events — raw ST webhook log for debugging
- Phase 5: Custom admin dashboard showing the pipeline visually
- Phase 6: Customer portal where customers can see their referral stats
- Phase 7: Multi-tier rewards (refer 3 get a bonus, etc.)
- Phase 8: Chiirp follow-up sequence for customers who got the link but haven't shared it
Built for LEX Air Conditioning | (972) 466-1917 | lexair.com