Skip to content

Commit 21b932c

Browse files
Archithclaude
andcommitted
Fix Slack export to properly fetch activity data from Firebase
- Fetch activity data from Firebase instead of relying on in-memory function - Check both activity_final_summary and activity_summary paths - Added Promise.all to fetch notes and activity data together - Added debug logging to track activity data retrieval - Fixed both preview and actual send functions The issue was that getActivitySummary() only works for candidates actively being monitored, not for interviewers viewing ended sessions. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c75c471 commit 21b932c

File tree

1 file changed

+57
-21
lines changed

1 file changed

+57
-21
lines changed

scripts/slack-integration.js

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -97,31 +97,47 @@
9797

9898
// Get session data from Firebase if needed
9999
if (currentSessionData && window.firebase) {
100-
window.firebase.database()
101-
.ref(`sessions/${currentSessionCode}/interviewerNotes`)
102-
.once('value')
103-
.then(snapshot => {
104-
const notes = snapshot.val();
105-
const message = formatSlackMessage(notes);
106-
previewContent.innerHTML = message.preview;
107-
})
108-
.catch(error => {
109-
console.error('Error loading notes for Slack:', error);
110-
previewContent.innerHTML = '<div style="color: #f44336;">Error loading session data</div>';
111-
});
100+
// Get both notes and activity data
101+
Promise.all([
102+
window.firebase.database()
103+
.ref(`sessions/${currentSessionCode}/interviewerNotes`)
104+
.once('value'),
105+
window.firebase.database()
106+
.ref(`sessions/${currentSessionCode}/activity_final_summary`)
107+
.once('value')
108+
.then(snapshot => {
109+
if (!snapshot.val()) {
110+
// Try regular summary if no final summary
111+
return window.firebase.database()
112+
.ref(`sessions/${currentSessionCode}/activity_summary`)
113+
.once('value');
114+
}
115+
return snapshot;
116+
})
117+
]).then(([notesSnapshot, activitySnapshot]) => {
118+
const notes = notesSnapshot.val();
119+
const activityData = activitySnapshot.val();
120+
const message = formatSlackMessage(notes, activityData);
121+
previewContent.innerHTML = message.preview;
122+
}).catch(error => {
123+
console.error('Error loading data for Slack:', error);
124+
previewContent.innerHTML = '<div style="color: #f44336;">Error loading session data</div>';
125+
});
112126
}
113127
}
114128

115129
// Format message for Slack
116-
function formatSlackMessage(notes) {
130+
function formatSlackMessage(notes, activitySummary) {
117131
const candidateName = getCandidateName();
118132
const recommendation = notes?.recommendation || 'No recommendation';
119133
const rating = notes?.rating?.overall || 0;
120134
const notesContent = notes?.content || 'No notes';
121135
const tags = notes?.tags || [];
122136

123-
// Get activity summary if available
124-
const activitySummary = window.getActivitySummary ? window.getActivitySummary() : null;
137+
// Use passed activity summary or try to get from window
138+
if (!activitySummary && window.getActivitySummary) {
139+
activitySummary = window.getActivitySummary();
140+
}
125141

126142
// Color based on recommendation
127143
const colors = {
@@ -146,6 +162,9 @@
146162
// Format activity analysis if available
147163
let activitySection = '';
148164
let engagementLevel = 'Not tracked';
165+
166+
console.log('Activity summary for Slack:', activitySummary);
167+
149168
if (activitySummary) {
150169
// Calculate engagement level
151170
if (activitySummary.activityScore > 80) {
@@ -333,13 +352,30 @@
333352
}
334353

335354
try {
336-
// Get the latest notes
337-
const snapshot = await window.firebase.database()
338-
.ref(`sessions/${currentSessionCode}/interviewerNotes`)
339-
.once('value');
355+
// Get the latest notes and activity data
356+
const [notesSnapshot, activitySnapshot] = await Promise.all([
357+
window.firebase.database()
358+
.ref(`sessions/${currentSessionCode}/interviewerNotes`)
359+
.once('value'),
360+
window.firebase.database()
361+
.ref(`sessions/${currentSessionCode}/activity_final_summary`)
362+
.once('value')
363+
.then(snapshot => {
364+
if (!snapshot.val()) {
365+
// Try regular summary if no final summary
366+
return window.firebase.database()
367+
.ref(`sessions/${currentSessionCode}/activity_summary`)
368+
.once('value');
369+
}
370+
return snapshot;
371+
})
372+
]);
373+
374+
const notes = notesSnapshot.val();
375+
const activityData = activitySnapshot.val();
376+
console.log('Sending to Slack with activity data:', activityData);
340377

341-
const notes = snapshot.val();
342-
const message = formatSlackMessage(notes);
378+
const message = formatSlackMessage(notes, activityData);
343379

344380
// Send to Slack via our secure API endpoint
345381
// NOTE: Webhook URL is configured server-side as environment variable

0 commit comments

Comments
 (0)