[TERMINAL · SKILLS]
> mounting /skills...
> indexing skill manifests...
> linking agents: claude · codex · gemini · cursor
> ready.
[░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0%
Use Cases/Build a Smart Email Routing and Auto-Response System

Build a Smart Email Routing and Auto-Response System

Route inbound emails to the right team with AI classification, auto-draft responses for common queries, and track SLA compliance — cutting email response time from 12 hours to 45 minutes.

Development#typescript#tsconfig#type-checking#type-safety#javascript-migration
Works with:claude-codeopenai-codexgemini-clicursor

Skills stack · 7 skills

Avg quality 94/100·All SAFE
>

typescript

v1.0.0

Sets up and repairs TypeScript projects: picks tsconfig.json settings for a Node.js service, an npm library or a bundled web app, runs type-checking in CI, and replaces `any` and unsafe casts with types the compiler can verify. Use when someone asks to "set up TypeScript", "fix this tsconfig", "fix a TypeScript error", "upgrade to TypeScript 6 or 7", "migrate JavaScript to TypeScript", "publish types for a package", "run .ts files in Node" or "make this type-safe". Covers the changed defaults in TypeScript 6.0 and 7.0, module and moduleResolution, strict mode, project references, declaration output, narrowing, satisfies and common compiler errors.

93/100 quality
7.30× impact
SAFE· stale score
View skill
>

ai-sdk

v1.1.0

The Vercel AI SDK is a TypeScript toolkit for calling LLMs from Node.js, Next.js, Nuxt, SvelteKit and edge runtimes through one API. It covers text generation, streaming, structured output with Zod, tool calling, agents (ToolLoopAgent) and chat UIs with useChat. Use when asked to "add AI to my Next.js app", "stream a chat response", "get typed JSON from an LLM", "switch between OpenAI, Anthropic and Gemini", or "build a tool-calling agent".

77/100 quality
5.47× impact
SAFE· stale score
View skill
>

redis

v1.1.0

Redis is an in-memory data store used as a cache, session store, message broker and counter service. Use when adding a cache layer, storing sessions, rate limiting an API, running pub/sub or Streams with consumer groups, taking a distributed lock, building a leaderboard, or configuring Redis for production (persistence, maxmemory, eviction).

93/100 quality
1.79× impact
SAFE· stale score
View skill
>

postgresql

v1.1.0

Assists with designing schemas, writing performant queries, managing indexes, and operating PostgreSQL databases. Use when working with JSONB, full-text search, window functions, CTEs, row-level security, replication, or performance tuning. Trigger words: postgresql, postgres, sql, database, jsonb, rls, window functions, cte.

100/100 quality
5.15× impact
SAFE· stale score
View skill
>

bull-mq

v1.1.0

Runs background jobs in Node.js with BullMQ, a job queue library backed by Redis (or PostgreSQL since v6): delayed and prioritized jobs, retries with backoff, rate limiting, cron-style job schedulers, parent-child flows and concurrency control. Use when a user asks to add a background worker, queue emails or webhooks, schedule recurring jobs, retry failed jobs, rate limit an API client, or migrate from Bull or from BullMQ 5 repeatable jobs.

100/100 quality
1.19× impact
SAFE· stale score
View skill
>

zod

v1.1.0

Zod is a TypeScript-first schema library that validates data at runtime and infers static types from the same schema. Use when validating API request bodies, form input, environment variables or config files, parsing untrusted JSON, or migrating from Zod 3 to Zod 4. Covers z.object, safeParse, z.infer, coercion, discriminated unions, refinements, JSON Schema output and the v4 API changes.

93/100 quality
3.87× impact
SAFE· stale score
View skill
>

hono

v1.1.0

Hono is a small web framework built on Web Standards (Request/Response) that runs unchanged on Cloudflare Workers, Deno, Bun, Node.js, AWS Lambda and Vercel. Use it when the user asks to build a Hono API, add Zod validation, JWT auth, CORS or middleware, use the type-safe RPC client (hc), render JSX, stream responses, or deploy one codebase to several runtimes.

100/100 quality
6.20× impact
SAFE· stale score
View skill
$

The Problem

A B2B company receives 500 emails/day to support@, sales@, and info@. Emails land in shared inboxes where 5 people manually read, classify, and forward them. Average first-response time: 12 hours. 20% of emails get lost — nobody responds. Sales leads sit in support@ for days because nobody realized it was a $50K opportunity. The CEO manually forwards emails when she notices they're in the wrong inbox. The team tried rules-based filtering but 40% of emails don't match any rule.

Step 1: Email Classifier

typescript
// src/email/classifier.ts
import { generateObject } from 'ai';
import { openai } from '@ai-sdk/openai';
import { z } from 'zod';

const EmailClassification = z.object({
  category: z.enum([
    'sales_inquiry', 'support_bug', 'support_how_to', 'billing',
    'partnership', 'feedback', 'spam', 'legal', 'press', 'job_application',
  ]),
  priority: z.enum(['urgent', 'high', 'normal', 'low']),
  sentiment: z.enum(['positive', 'neutral', 'frustrated', 'angry']),
  routeTo: z.string(),
  summary: z.string().max(200),
  estimatedDealSize: z.number().optional(), // for sales inquiries
  autoRespondable: z.boolean(),
  language: z.string(),
  suggestedTags: z.array(z.string()),
});

export async function classifyEmail(email: {
  from: string;
  subject: string;
  body: string;
  attachments: string[];
  previousThreads: number;
}): Promise<z.infer<typeof EmailClassification>> {
  const { object } = await generateObject({
    model: openai('gpt-4o-mini'),
    schema: EmailClassification,
    prompt: `Classify this inbound email and determine routing.

From: ${email.from}
Subject: ${email.subject}
Body: ${email.body}
Attachments: ${email.attachments.join(', ') || 'none'}
Previous threads from this sender: ${email.previousThreads}

Routing rules:
- sales_inquiry → sales-team (respond within 2h)
- support_bug → engineering-support (respond within 4h)
- support_how_to → customer-success (respond within 8h)
- billing → finance-team (respond within 4h)
- partnership → business-dev (respond within 24h)
- legal → legal-team (respond within 24h)
- spam → archive (no response)
- press → marketing (respond within 24h)

For sales inquiries, estimate deal size based on context clues (company size, use case).
Mark autoRespondable=true for common how-to questions and billing inquiries.`,
  });

  return object;
}

Step 2: Auto-Response Drafter

typescript
// src/email/auto-responder.ts
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { Pool } from 'pg';

const db = new Pool({ connectionString: process.env.DATABASE_URL });

export async function draftResponse(email: {
  from: string;
  subject: string;
  body: string;
  classification: { category: string; summary: string };
}): Promise<{ draft: string; confidence: number; sources: string[] }> {
  // Find relevant knowledge base articles
  const { rows: articles } = await db.query(`
    SELECT title, content, url FROM knowledge_base
    WHERE category = $1
    ORDER BY similarity(content, $2) DESC
    LIMIT 3
  `, [email.classification.category, email.body]);

  const context = articles.map(a => `[${a.title}]: ${a.content.slice(0, 500)}`).join('\n\n');

  const { text } = await generateText({
    model: openai('gpt-4o-mini'),
    prompt: `Draft a professional email response.

Original email:
From: ${email.from}
Subject: ${email.subject}
Body: ${email.body}

Relevant knowledge base articles:
${context}

Rules:
- Professional but warm tone
- Include specific links to docs/articles when relevant
- If unsure about the answer, acknowledge the question and say the team will follow up
- Keep under 200 words
- Sign as "Support Team" (not a specific person)
- Don't promise things you can't guarantee (timelines, features)`,
  });

  return {
    draft: text,
    confidence: articles.length > 0 ? 0.85 : 0.5,
    sources: articles.map(a => a.url),
  };
}

Step 3: SLA Tracker

typescript
// src/email/sla.ts
import { Pool } from 'pg';
import { Redis } from 'ioredis';

const db = new Pool({ connectionString: process.env.DATABASE_URL });
const redis = new Redis(process.env.REDIS_URL!);

const SLA_HOURS: Record<string, number> = {
  sales_inquiry: 2,
  support_bug: 4,
  support_how_to: 8,
  billing: 4,
  partnership: 24,
  legal: 24,
  press: 24,
};

export async function trackSLA(emailId: string, category: string): Promise<void> {
  const slaHours = SLA_HOURS[category] ?? 24;
  const deadline = new Date(Date.now() + slaHours * 3600000);

  await db.query(`
    INSERT INTO email_sla (email_id, category, sla_deadline, status)
    VALUES ($1, $2, $3, 'pending')
  `, [emailId, category, deadline.toISOString()]);

  // Schedule SLA warning at 80% of deadline
  const warningMs = slaHours * 3600000 * 0.8;
  const { Queue } = await import('bullmq');
  const queue = new Queue('sla-alerts', { connection: redis });
  await queue.add('sla-warning', { emailId, category }, { delay: warningMs });
}

export async function getSLADashboard(): Promise<{
  pending: number;
  breached: number;
  respondedInTime: number;
  avgResponseHours: number;
  byCategory: Array<{ category: string; avgHours: number; breachRate: number }>;
}> {
  const { rows: [stats] } = await db.query(`
    SELECT
      COUNT(*) FILTER (WHERE status = 'pending' AND sla_deadline > NOW()) as pending,
      COUNT(*) FILTER (WHERE status = 'pending' AND sla_deadline <= NOW()) as breached,
      COUNT(*) FILTER (WHERE status = 'responded' AND responded_at <= sla_deadline) as in_time,
      AVG(EXTRACT(EPOCH FROM (responded_at - created_at)) / 3600) FILTER (WHERE status = 'responded') as avg_hours
    FROM email_sla
    WHERE created_at > NOW() - INTERVAL '30 days'
  `);

  const { rows: categories } = await db.query(`
    SELECT category,
      AVG(EXTRACT(EPOCH FROM (COALESCE(responded_at, NOW()) - created_at)) / 3600) as avg_hours,
      COUNT(*) FILTER (WHERE status = 'pending' AND sla_deadline <= NOW())::float / NULLIF(COUNT(*), 0) as breach_rate
    FROM email_sla
    WHERE created_at > NOW() - INTERVAL '30 days'
    GROUP BY category
  `);

  return {
    pending: parseInt(stats.pending),
    breached: parseInt(stats.breached),
    respondedInTime: parseInt(stats.in_time),
    avgResponseHours: parseFloat(stats.avg_hours ?? '0'),
    byCategory: categories.map(c => ({
      category: c.category,
      avgHours: parseFloat(c.avg_hours),
      breachRate: parseFloat(c.breach_rate ?? '0'),
    })),
  };
}

Results

  • First response time: 45 minutes average (was 12 hours)
  • Lost emails: zero (was 20%) — every email tracked with SLA
  • Sales leads misrouted: zero — AI detects sales inquiries with 96% accuracy
  • $50K lead: would have been caught immediately, not buried in support@ for 3 days
  • Auto-draft acceptance: 65% of drafts sent with minor edits, saving 3 hours/day
  • SLA compliance: 94% (was unmeasured, estimated ~60%)
  • Email classification accuracy: 93% correct routing on first pass

Related use cases