|
97 | 97 |
|
98 | 98 | // Get session data from Firebase if needed |
99 | 99 | 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 | + }); |
112 | 126 | } |
113 | 127 | } |
114 | 128 |
|
115 | 129 | // Format message for Slack |
116 | | - function formatSlackMessage(notes) { |
| 130 | + function formatSlackMessage(notes, activitySummary) { |
117 | 131 | const candidateName = getCandidateName(); |
118 | 132 | const recommendation = notes?.recommendation || 'No recommendation'; |
119 | 133 | const rating = notes?.rating?.overall || 0; |
120 | 134 | const notesContent = notes?.content || 'No notes'; |
121 | 135 | const tags = notes?.tags || []; |
122 | 136 |
|
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 | + } |
125 | 141 |
|
126 | 142 | // Color based on recommendation |
127 | 143 | const colors = { |
|
146 | 162 | // Format activity analysis if available |
147 | 163 | let activitySection = ''; |
148 | 164 | let engagementLevel = 'Not tracked'; |
| 165 | + |
| 166 | + console.log('Activity summary for Slack:', activitySummary); |
| 167 | + |
149 | 168 | if (activitySummary) { |
150 | 169 | // Calculate engagement level |
151 | 170 | if (activitySummary.activityScore > 80) { |
|
333 | 352 | } |
334 | 353 |
|
335 | 354 | 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); |
340 | 377 |
|
341 | | - const notes = snapshot.val(); |
342 | | - const message = formatSlackMessage(notes); |
| 378 | + const message = formatSlackMessage(notes, activityData); |
343 | 379 |
|
344 | 380 | // Send to Slack via our secure API endpoint |
345 | 381 | // NOTE: Webhook URL is configured server-side as environment variable |
|
0 commit comments