Skip to content

Commit a99bf9f

Browse files
Adding slip day tracking
1 parent ab4e93d commit a99bf9f

File tree

6 files changed

+144
-62
lines changed

6 files changed

+144
-62
lines changed

.env.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=
1313
# For Firebase Admin SDK env variables, see https://github.com/firebase/firebase-admin-node/discussions/2043
1414
FIREBASE_ADMIN_CLIENT_EMAIL=
1515
FIREBASE_ADMIN_PRIVATE_KEY=
16+
NOTION_TOKEN=
17+
NOTION_ATTENDANCE_DATABASE_ID=
1618

1719
AUTH_COOKIE_NAME=
1820
AUTH_COOKIE_SIGNATURE_KEY_CURRENT=

package-lock.json

Lines changed: 58 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"lint": "next lint"
1313
},
1414
"dependencies": {
15+
"@notionhq/client": "^2.3.0",
1516
"@prisma/client": "^6.1.0",
1617
"firebase": "^11.0.2",
1718
"firebase-admin": "^13.0.2",

src/app/utils/notionUtils.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { notion } from '../../notion';
2+
3+
export async function notionDispatch(message: string): Promise<string> {
4+
const wordSet = new Set<string>(message.trim().toLowerCase().split(' '));
5+
if (wordSet.has('slip') && (wordSet.has('day') || wordSet.has('days'))) {
6+
message = await appendSlipDays(message);
7+
}
8+
return message;
9+
}
10+
11+
async function appendSlipDays(message: string): Promise<string> {
12+
const databaseId = process.env.SP25_NOTION_ATTENDANCE_DATABASE_ID!;
13+
try {
14+
const response = await notion.databases.query({
15+
database_id: databaseId,
16+
filter: {
17+
property: 'Status',
18+
select: {
19+
equals: 'Active',
20+
},
21+
},
22+
});
23+
24+
message += '\nAttendance and Slip Day Information:\n';
25+
message += `Name | Absence Dates | Late Dates | IWS Makeups | Slip Days Remaining\n`;
26+
27+
message += response.results
28+
.map((row: any) => {
29+
const props = row.properties || {};
30+
const firstName = props['First Name']?.title?.[0]?.text?.content ?? 'Unknown';
31+
const lastName = props['Last Name']?.rich_text?.[0]?.plain_text ?? '';
32+
const absences = props['Absence Dates']?.rich_text?.[0]?.plain_text ?? '';
33+
const lates = props['Late Dates']?.rich_text?.[0]?.plain_text ?? '';
34+
const iws = props['IWS Makeups']?.rich_text?.[0]?.plain_text ?? '';
35+
const slipDays = props['Slip Days Remaining']?.formula?.number ?? 0;
36+
37+
return `${firstName} ${lastName} | ${absences} | ${lates} | ${iws} | ${slipDays}`;
38+
})
39+
.join('\n');
40+
return message;
41+
} catch (err) {
42+
console.error('Notion query failed:', err);
43+
message += '\n[Error fetching slip day info from Notion]\n';
44+
return message;
45+
}
46+
}

0 commit comments

Comments
 (0)