AI Automation

AI Legal Intake & Revenue Automation - n8n, Gemini, VAPI & MyCase

AI Automation Engineer / Systems Integrator

Business summary
Legal & Professional Services • AI intake chatbot, voice agent for no-shows, and automated payroll commissions
  • Replaced $200+/mo third-party chat widget with owned AI agent booking directly in MyCase
  • Cut attorney commission calculations from 2 days to a single automated file upload
  • Caught a $54,560 double-counting payroll error on first automated run

What I built

Replaced a $200+/month third-party chatbot with a custom AI intake agent (n8n, Google Gemini) embedded on WordPress that qualifies leads across 8 practice areas, queries attorney availability, and books consultations directly in MyCase CRM. Built an AI voice agent on VAPI for no-show recovery and objection handling. Engineered an automated attorney commission reconciliation engine ingesting billing and trust-accounting reports, cutting payroll prep from 2 days to a single upload and catching a $54,560 billing calculation error on its first automated run.

Tech stack

n8nGoogle GeminiVAPIMyCase APIAI AgentsMyCaseWordPressPostgreSQLRailwayJavaScriptAI Voice AgentsAI Intake AgentLegal TechCommission AutomationTrust AccountingError AlertingLead QualificationPrompt Engineering
Deep Dive Case Study

AI Intake & Revenue Automation for a Utah Family Law Firm

Role: Solo AI Automation Engineer
Client: Ammon Nelson Law, PLLC - family law firm, South Ogden, Utah
Duration: May - October 2026 (ongoing)
Stack: n8n · Google Gemini · VAPI · MyCase API · WordPress · PostgreSQL · Railway · JavaScript · Google Workspace APIs


Summary

A six-attorney family law firm was losing leads to a chatbot that couldn't book anything, and burning two days per pay cycle on commission calculations done by hand in a spreadsheet.

I replaced their $200+/month third-party chatbot with a custom AI intake agent that creates leads and books consultations directly in their case management system, built an AI voice agent that calls no-shows, and automated a commission engine that reconciles attorney payouts against both billing and trust-account data.

Headline results

  • Replaced a paid SaaS chatbot with an owned system that does strictly more
  • Commission calculation went from ~2 days of manual work to a single file upload
  • Caught a $54,560 calculation error in the first automated run
  • Proved a suspected trust-accounting problem was a false alarm, using data

1. The AI Intake Agent

Problem

The firm used Intaker, a third-party legal chat widget. It captured a name and phone number and stopped there. Every lead then had to be manually typed into MyCase, and every consultation manually scheduled. Leads arriving outside business hours often went cold.

What I built

A conversational intake agent ("Callee") running on n8n with Google Gemini, embedded on the firm's WordPress site.

The agent:

  • Qualifies the matter across 8 practice areas
  • Collects name, phone, and email conversationally, one question at a time
  • Creates the lead in MyCase via API
  • Reads attorney calendars and offers real open slots
  • Books the consultation directly onto the correct attorney's calendar
  • Links the calendar event back to the lead record so staff get one-click access to the phone number, email, and full chat transcript
  • Sends a branded HTML confirmation email
  • Captures UTM parameters, referrer, gclid and fbclid for attribution

It also ships as a standalone full-page chat at /chat - one link that works in Facebook Messenger, SMS, email signatures, Google Business profiles and QR codes.

Engineering problems solved

Tool-calling reliability. The agent was re-firing its tools on every conversational turn, creating duplicate leads in the client's CRM. I researched the root cause - a documented n8n issue where memory nodes drop tool-call messages, so the model never sees that an action already happened - and designed a prompt-side fix: an explicit STATE block, a per-tool "CALL ONLY IF / NEVER IF" contract, and idempotency rules. Combined with a database-backed leadCreated flag, duplicates stopped.

Timezone bug. MyCase interprets timestamps ending in Z as UTC. A 9:00 AM booking was landing on the calendar at 3:00 AM. Fixed by explicitly emitting Mountain Time offsets and verifying end-times stayed in the same zone.

A silent default that booked the wrong attorney. The firm's owner reported being booked for consultations he wasn't supposed to take. The prompt had been updated to exclude him, but the booking code contained attorneyMap[attorney] || 5382894 - a fallback to his own staff ID whenever the attorney name didn't match exactly. Removing the fallback and assigning randomly among bookable attorneys fixed it. A good reminder that prompt changes don't fix code defaults.

WordPress deployment. The widget rendered as unstyled plain text on the live site. The cause was WPCode's HTML sanitizer stripping <style> tags and long base64 image sources. Solution: split the widget into three snippets by code type (CSS / HTML / JavaScript) and inject the avatar image through JavaScript, which isn't sanitized. Also had to account for WP Rocket and Kinsta caching masking every change.

I verified layout fixes in a headless browser rather than guessing - measuring computed element heights to confirm, for example, that short words like "Divorce" no longer wrapped mid-word inside message bubbles.

Result

Intaker retired. The firm now owns an intake agent that books appointments, creates CRM records, and attributes every lead to its marketing source.


2. AI Voice Agent for No-Show Recovery

Built on VAPI, integrated with the same n8n backend.

When a prospect no-shows a consultation, the agent calls them, acknowledges the missed appointment empathetically, checks live attorney availability, and rebooks - using the same checkAvailability and bookAppointment tools as the web chat, so both channels stay consistent.

Designed the full conversation script including objection handling for cost concerns, experience questions, and voicemail fallback, with a hard rule never to give legal advice.


3. Attorney Commission Automation

This was the highest-value piece of the project.

Problem

Every two weeks the bookkeeper manually:

  1. Opened each invoice individually
  2. Worked out how much of it each attorney had billed
  3. Hand-calculated each person's commission percentage
  4. Typed the result into a spreadsheet
  5. Had a second person re-check the arithmetic

The client's own words: "calculates it all by hand, which is why I hate it, because it's terrible." Attorneys were regularly over- or underpaid.

The commission rules

Rule Rate
Originating attorney - on all collections for their case 20%
Working attorney - on what they personally collected 40%
One senior attorney - negotiated rate 45%
Originator who also works the case 60% (stacked)

Multiple attorneys routinely share a single case, so each payment has to be split proportionally by who billed what. Payments must also be applied to expenses first - commission is only earned on the fee portion, and partial payments mean tracking when expenses finish clearing.

Discovery: the API was a dead end

Before building, I mapped what the MyCase API could actually provide:

Endpoint Result
/events, /users, /leads Working
/invoices (list) Totals only - no line items, no attorney attribution
/invoices/{id} "Invoice retrieval is not yet supported"
/payments Endpoint does not exist
/time_entries Not found
Webhooks Never fire for manual or cash payments

The client had previously attempted this in Zapier and hit the same wall. I documented the findings and pivoted the architecture to CSV report ingestion, which is the only path the vendor actually supports.

What I built

A JavaScript engine that parses the firm's Fee Allocation Report and produces a full per-attorney, per-case commission breakdown with an audit trail.

Handling the report format required reverse-engineering several quirks:

  • Attorney names appear as standalone grouping header rows, not as a column
  • A Total subtotal row follows each attorney's block
  • Originating attorney is sometimes blank
  • Currency formatting includes $, commas, and parentheses for negatives

Catching a $54,560 error

The first automated run produced a payout that looked plausible. It wasn't.

Those Total subtotal rows were being parsed as if they were real cases, double-counting an entire period - $54,560 of phantom collections, inflating the payout by roughly 68%.

I fixed the parser and then added a permanent safeguard: after parsing, each attorney's computed collections must equal that attorney's own Total row in the source file. If they don't match, the run halts. Every attorney now reconciles to the cent, every cycle.

Settling the trust-accounting question with data

The client raised a serious concern: some payments were client retainers paid into trust, which are not earned income and must not generate commission. He pointed to a $2,500 line he believed was a retainer.

Rather than guess, I ingested the trust ledger report and cross-referenced it against the billing report. First I verified the ledger's direction by tracing a client's running balance - credits increase the trust balance (deposits), debits decrease it (money applied to an invoice, i.e. earned).

One case settled it:

Case Billing report counts Deposited into trust Applied from trust
Client A $472.50 $5,000.00 $472.50

The report counts only what was applied to invoices, never the raw deposit. The $2,500 the client flagged turned out to be two legitimate debits against a real invoice - genuinely earned.

I still built the cross-check into the engine as a verification layer. Every case is now tagged OPERATING, TRUST VERIFIED, TRUST DEPOSIT ONLY, or REVIEW, with a needs_review flag for the bookkeeper. I validated the flag by injecting a synthetic retainer-only case and confirming it fired with the correct amounts - rather than assuming "zero flags" meant the check worked.

Result

One month's commissions across 91 cases, fully reconciled, with trust verification - from a single file upload.

Attorney Origination Working Total
Attorney A $10,033.68 $2,472.83 $12,506.48
Attorney B $824.20 $8,718.68 $9,542.93
Attorney C - $4,058.27 $4,058.27
Attorney D $84.50 $3,812.40 $3,896.92
Attorney E - $3,718.03 $3,718.03
$33,722.63

91 cases · 0 flagged · 46 trust-verified · 44 paid direct to operating.

I also surfaced a business question the manual process had hidden: because origination stacks on top of working commission, total payout was running at 61% of collections. The firm had never seen that number as a single figure.


4. Reliability Engineering

Error alerting. Built a centralized error workflow that captures the failing node, the error message, the stack trace, and the input data that caused the failure, and emails a formatted report. Designed so the alert still sends even if the enrichment step itself fails.

Infrastructure recovery. The self-hosted n8n instance entered a crash loop. Log analysis showed it was not a memory or billing issue as assumed, but a Redis connection failure - and that Redis wasn't needed at all for a single-instance deployment. Removing the dependency eliminated the failure mode entirely.

Model migration. The deployment broke when Google retired Gemini 2.0 Flash. Diagnosed the 429/503 errors as a retired-model problem plus an unbilled API project, and migrated to a current model.


5. Product Strategy

The client raised building a full competitor to their case management vendor. Rather than accept the brief, I researched and scoped it honestly.

I produced a complete feature inventory of the incumbent platform - 11 modules, ~110 engineering weeks for full parity - weighted by what this firm actually uses. That analysis surfaced two things:

  • Document management, normally the largest module, was nearly irrelevant here. The firm stores almost nothing in it. That reprioritized months of work.
  • Trust accounting is the real risk. IOLTA compliance, per-client sub-ledgers, three-way reconciliation. An error there is a bar complaint, not a support ticket. I recommended it be deferred until professional sign-off and that the first release deliberately not touch client money.

My recommendation was to not build a replacement first. Instead, ship an add-on that sits on top of the system the firm already runs - commission tracking plus AI intake, which is ~70% built and carries zero migration risk. Migration fear is the single biggest objection in this market; one vendor had quoted the client eight months to switch.

Delivered a full technical specification: multi-tenant data model, trust accounting compliance rules, phased 20-month roadmap, and a stack recommendation that runs under $100/month pre-revenue.


6. Skills Demonstrated

AI engineering - agentic tool-calling, prompt gating and idempotency, conversation state management, multi-channel agents (web, voice, messaging)
Integration - REST API reverse-engineering, OAuth 2.0, undocumented endpoint discovery, CSV ingestion when APIs fall short
Data engineering - financial reconciliation, multi-source cross-validation, trust vs. operating fund logic, audit trails
Debugging - root-cause analysis across six systems: n8n, WordPress, WPCode sanitization, Railway infrastructure, Google Cloud billing, vendor API limits
Verification discipline - headless browser testing for UI fixes, synthetic data injection to prove validators actually fire, cross-checking parsed output against source-of-truth totals
Product & communication - scoping a 110-week build honestly, translating technical findings into decisions a non-technical owner can make, and pushing back with evidence when a stated assumption didn't hold