Insurance Email Copilot
AI-powered email management for insurance agencies. Built by Ashlr.AI.
What is this?
A custom email tool that helps insurance agencies manage their inbox by:
- Auto-categorizing incoming emails (claims, billing, quotes, etc.)
- Generating draft responses using AI (Grok 4.1 Fast)
- Approval workflow - humans review and approve before sending
- Smart notifications - get alerted for urgent emails
Quick Start
Prerequisites
- Node.js 18+
- pnpm (
npm install -g pnpm) - PostgreSQL database
- Microsoft 365 account (for Graph API access)
- xAI API key (for Grok)
Setup
- Clone the repo:
git clone <repo-url>
cd insurance-email-copilot
- Install dependencies:
pnpm install
- Copy environment variables:
cp .env.example .env
Fill in your
.envfile (see Configuration below)Set up the database:
pnpm db:generate
pnpm db:migrate
- Run the development server:
pnpm dev
Configuration
Required Environment Variables
# Microsoft Graph API (Azure AD App Registration)
AZURE_CLIENT_ID=your-client-id
AZURE_CLIENT_SECRET=your-client-secret
AZURE_TENANT_ID=common # Use "common" for multi-tenant
# xAI Grok API
XAI_API_KEY=your-xai-api-key
XAI_MODEL=grok-4-1-fast-reasoning
# Database
DATABASE_URL=postgresql://user:pass@host:5432/dbname
# NextAuth
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=generate-a-random-secret
# Slack (optional)
SLACK_BOT_TOKEN=xoxb-your-token
SLACK_CHANNEL_ID=C0123456789
Microsoft Azure Setup
- Go to Azure Portal > Azure Active Directory > App Registrations
- New Registration:
- Name: "Insurance Email Copilot"
- Supported account types: "Accounts in any organizational directory" (multi-tenant)
- Redirect URI:
http://localhost:3000/api/auth/callback/azure-ad
- Note the Application (client) ID
- Create a client secret under Certificates & Secrets
- Add API permissions:
- Microsoft Graph > Delegated:
Mail.ReadMail.ReadWriteMail.SendUser.Readoffline_access
- Microsoft Graph > Delegated:
xAI API Setup
- Go to console.x.ai
- Create an API key
- You get $25 free credit to start
Project Structure
├── apps/
│ └── web/ # Next.js frontend + API
├── packages/
│ ├── ai/ # AI categorization + drafts
│ ├── email/ # Microsoft Graph client
│ ├── database/ # Prisma schema
│ └── shared/ # Shared types
└── docs/ # Documentation
Development
Commands
pnpm dev # Start development server
pnpm build # Build for production
pnpm db:studio # Open Prisma Studio (database GUI)
pnpm db:migrate # Run database migrations
pnpm lint # Run linter
pnpm test # Run tests
Testing Webhooks Locally
Use ngrok to expose your local server:
ngrok http 3000
Then use the ngrok URL for Microsoft Graph webhook subscriptions.
Deployment
Vercel (Frontend)
- Connect your GitHub repo to Vercel
- Set environment variables in Vercel dashboard
- Deploy
Railway (Database)
- Create a PostgreSQL database on Railway
- Copy the connection string to
DATABASE_URL - Run migrations:
pnpm db:migrate
API Reference
Webhook Endpoint
POST /api/webhook - Receives Microsoft Graph notifications
Draft Endpoints
GET /api/drafts- List pending draftsPOST /api/drafts/:id/approve- Approve and sendPOST /api/drafts/:id/reject- Reject draftPATCH /api/drafts/:id- Edit draft
Email Endpoints
GET /api/emails- List emailsGET /api/emails/:id- Get single email
Support
Built by Ashlr.AI for Valley Trust Insurance.
Questions? Contact mason@ashlr.ai
License
Proprietary - AshlrAI, Inc.