This document outlines the API structure and service integrations used in SynapSolve. The application uses a combination of Firebase services, third-party APIs, and custom service layers.
const { signInWithEmail } = useAuth();
await signInWithEmail(email, password);const { signInWithGoogle } = useAuth();
await signInWithGoogle();const { signUpWithEmail } = useAuth();
await signUpWithEmail(email, password, displayName);const { resetPassword } = useAuth();
await resetPassword(email);interface Ticket {
id: string;
title: string;
description: string;
category: string;
priority: 'low' | 'medium' | 'high' | 'urgent';
status: 'open' | 'in-progress' | 'resolved' | 'closed';
submittedBy: string;
submittedByName: string;
assignedTo?: string;
assignedToName?: string;
createdAt: Date;
updatedAt: Date;
aiSummary?: string;
sentiment?: 'positive' | 'neutral' | 'negative';
suggestedReply?: string;
}import { collection, addDoc } from 'firebase/firestore';
import { db } from '../config/firebase';
const docRef = await addDoc(collection(db, 'tickets'), ticketData);interface User {
uid: string;
email: string;
displayName: string;
role: 'user' | 'agent' | 'admin';
photoURL?: string;
createdAt: Date;
}import { generateAISummary } from '../services/openaiService';
const analysis = await generateAISummary(title, description);
// Returns: { summary, sentiment, suggestedReply }const completion = await openai.chat.completions.create({
model: "gpt-3.5-turbo",
messages: [
{
role: "system",
content: "You are an AI assistant specialized in customer support ticket analysis."
},
{
role: "user",
content: `Analyze this support ticket: ${title} - ${description}`
}
],
max_tokens: 500,
temperature: 0.3
});interface AIAnalysis {
summary: string; // 2-line ticket summary
sentiment: 'positive' | 'neutral' | 'negative';
suggestedReply: string; // Professional response suggestion
category?: string; // Recommended category
priority?: 'low' | 'medium' | 'high' | 'urgent';
}import { findBestAgent } from '../services/neo4jService';
const agent = await findBestAgent(ticket, availableAgents);// Find best agent based on skills and workload
MATCH (a:Agent)-[:HAS_SKILL]->(s:Skill)
WHERE s.name IN $requiredSkills
AND a.isAvailable = true
AND a.currentLoad < a.maxLoad
WITH a, count(s) as skillMatches
ORDER BY a.seniorLevel DESC, skillMatches DESC, a.currentLoad ASC
LIMIT 1
RETURN ainterface Agent {
uid: string;
email: string;
displayName: string;
skills: string[];
currentLoad: number;
maxLoad: number;
isAvailable: boolean;
seniorLevel: boolean;
}import { calendarService } from '../services/calendarService';
const eventId = await calendarService.createTicketReminder(
ticketId,
ticketTitle,
agentEmail,
reminderDate
);const meetingId = await calendarService.scheduleAgentMeeting(
agentEmails,
subject,
description,
startTime,
durationMinutes
);const busyTimes = await calendarService.getAgentAvailability(
agentEmail,
startDate,
endDate
);export const generateAISummary = async (title: string, description: string) => {
// Fallback logic when OpenAI is unavailable
const sentiment = description.toLowerCase().includes('angry') ? 'negative' : 'neutral';
return {
summary: `${title.substring(0, 50)}... - ${sentiment.toUpperCase()} priority issue`,
sentiment,
suggestedReply: "Thank you for contacting us. I'll help resolve this issue."
};
};export const findBestAgent = async (ticket: Ticket, agents: Agent[]) => {
// Priority routing for negative sentiment
if (ticket.sentiment === 'negative') {
const seniorAgents = agents.filter(a => a.seniorLevel && a.isAvailable);
if (seniorAgents.length > 0) return seniorAgents[0];
}
// Skill-based matching
const skillMatched = agents.filter(agent =>
agent.skills.some(skill =>
ticket.category.toLowerCase().includes(skill.toLowerCase())
)
);
return skillMatched.length > 0 ? skillMatched[0] : agents[0];
};const validateEnv = (): void => {
const requiredVars = [
'VITE_FIREBASE_API_KEY',
'VITE_FIREBASE_AUTH_DOMAIN',
'VITE_FIREBASE_PROJECT_ID',
'VITE_OPENAI_API_KEY'
];
const missingVars = requiredVars.filter(varName => !import.meta.env[varName]);
if (missingVars.length > 0) {
throw new Error(`Missing required environment variables: ${missingVars.join(', ')}`);
}
};try {
const result = await openaiGenerateAISummary(title, description);
return result;
} catch (error) {
console.warn('⚠️ OpenAI service unavailable, using fallback analysis');
return fallbackAnalysis(title, description);
}interface ApiResponse<T> {
success: true;
data: T;
timestamp: string;
}interface ApiError {
success: false;
error: {
code: string;
message: string;
details?: any;
};
timestamp: string;
}- Requests per minute: 3,500 (GPT-3.5-turbo)
- Tokens per minute: 90,000
- Requests per day: 10,000
- Firestore reads: 50,000/day (free tier)
- Firestore writes: 20,000/day (free tier)
- Authentication: Unlimited (free tier)
- Implement request caching for repeated queries
- Use batch operations for multiple Firestore writes
- Implement exponential backoff for failed requests
- Cache AI analysis results to reduce API calls
This API documentation provides a comprehensive guide for developers working with SynapSolve's service integrations and data structures.