diff --git a/docs/session-processing.md b/docs/session-processing.md
index 676ca59..18c424d 100644
--- a/docs/session-processing.md
+++ b/docs/session-processing.md
@@ -62,7 +62,8 @@ OPENAI_API_KEY=your_api_key_here
To run the application with schedulers enabled:
-- Development: `npm run dev:with-schedulers`
+- Development: `npm run dev`
+- Development (with schedulers disabled): `npm run dev:no-schedulers`
- Production: `npm run start`
Note: These commands will start a custom Next.js server with the schedulers enabled. You'll need to have an OpenAI API key set in your `.env.local` file for the session processing to work.
diff --git a/lib/csvFetcher.js b/lib/csvFetcher.js
index 675aa82..356de4b 100644
--- a/lib/csvFetcher.js
+++ b/lib/csvFetcher.js
@@ -561,15 +561,8 @@ export async function fetchAndStoreSessionsForAllCompanies() {
? session.endTime
: new Date();
- // Fetch transcript content if URL is available
- let transcriptContent = null;
- if (session.fullTranscriptUrl) {
- transcriptContent = await fetchTranscriptContent(
- session.fullTranscriptUrl,
- company.csvUsername,
- company.csvPassword
- );
- }
+ // Note: transcriptContent field was removed from schema
+ // Transcript content can be fetched on-demand from fullTranscriptUrl
// Check if the session already exists
const existingSession = await prisma.session.findUnique({
@@ -608,7 +601,6 @@ export async function fetchAndStoreSessionsForAllCompanies() {
? session.forwardedHr
: null,
fullTranscriptUrl: session.fullTranscriptUrl || null,
- transcriptContent: transcriptContent, // Add the transcript content
avgResponseTime:
typeof session.avgResponseTime === "number"
? session.avgResponseTime
diff --git a/lib/metrics.ts b/lib/metrics.ts
index 1d03f73..bdb4826 100644
--- a/lib/metrics.ts
+++ b/lib/metrics.ts
@@ -349,7 +349,7 @@ export function sessionMetrics(
let totalTokensEur = 0;
const wordCounts: { [key: string]: number } = {};
let alerts = 0;
-
+
// New metrics variables
const hourlySessionCounts: { [hour: string]: number } = {};
let resolvedChatsCount = 0;
@@ -530,7 +530,7 @@ export function sessionMetrics(
.forEach(msg => {
const content = msg.content.trim();
// Simple heuristic: if message ends with ? or contains question words, treat as question
- if (content.endsWith('?') ||
+ if (content.endsWith('?') ||
/\b(what|when|where|why|how|who|which|can|could|would|will|is|are|do|does|did)\b/i.test(content)) {
questionCounts[content] = (questionCounts[content] || 0) + 1;
}
@@ -540,7 +540,7 @@ export function sessionMetrics(
// 3. Extract questions from initial message as fallback
if (session.initialMsg) {
const content = session.initialMsg.trim();
- if (content.endsWith('?') ||
+ if (content.endsWith('?') ||
/\b(what|when|where|why|how|who|which|can|could|would|will|is|are|do|does|did)\b/i.test(content)) {
questionCounts[content] = (questionCounts[content] || 0) + 1;
}
@@ -611,10 +611,10 @@ export function sessionMetrics(
);
// Calculate new metrics
-
+
// 1. Average Daily Costs (euros)
const avgDailyCosts = numDaysWithSessions > 0 ? totalTokensEur / numDaysWithSessions : 0;
-
+
// 2. Peak Usage Time
let peakUsageTime = "N/A";
if (Object.keys(hourlySessionCounts).length > 0) {
@@ -624,7 +624,7 @@ export function sessionMetrics(
const endHour = (peakHourNum + 1) % 24;
peakUsageTime = `${peakHour}-${endHour.toString().padStart(2, '0')}:00`;
}
-
+
// 3. Resolved Chats Percentage
const resolvedChatsPercentage = totalSessions > 0 ? (resolvedChatsCount / totalSessions) * 100 : 0;
@@ -672,7 +672,7 @@ export function sessionMetrics(
lastUpdated: Date.now(),
totalSessionDuration,
validSessionsForDuration,
-
+
// New metrics
avgDailyCosts,
peakUsageTime,
diff --git a/lib/processingScheduler.js b/lib/processingScheduler.js
index e1d84de..0af48a4 100644
--- a/lib/processingScheduler.js
+++ b/lib/processingScheduler.js
@@ -14,7 +14,7 @@ const envPath = join(__dirname, '..', '.env.local');
try {
const envFile = readFileSync(envPath, 'utf8');
const envVars = envFile.split('\n').filter(line => line.trim() && !line.startsWith('#'));
-
+
envVars.forEach(line => {
const [key, ...valueParts] = line.split('=');
if (key && valueParts.length > 0) {
@@ -216,24 +216,130 @@ function validateOpenAIResponse(data) {
}
/**
- * Process unprocessed sessions
+ * Process a single session
+ * @param {Object} session The session to process
+ * @returns {Promise