Skip to content

Commit

Permalink
Merge pull request #688 from pennlabs/alert-2.0-push
Browse files Browse the repository at this point in the history
Add push alerts to PCA v2
  • Loading branch information
esinx authored Nov 19, 2024
2 parents 2951e1d + af35fd1 commit 01dd582
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ pcr-backup*
./Pipfile
./Pipfile.lock
./package.json
./yarn.lock
./yarn.lock
*.pem
1 change: 1 addition & 0 deletions services/alert/webhook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"dependencies": {
"@aws-sdk/client-sesv2": "^3.672.0",
"@aws-sdk/client-sns": "^3.693.0",
"cross-fetch": "^4.0.0",
"dotenv": "^16.4.5",
"drizzle-orm": "^0.36.0",
"pg": "^8.13.1",
Expand Down
2 changes: 2 additions & 0 deletions services/alert/webhook/src/core/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { z } from "zod"
const schema = {
DATABASE_URL: z.string().url(),
CURRENT_SEMESTER: z.string(),
PUSH_ENDPOINT: z.string(),
PUSH_TOKEN: z.string(),
}

const $schema = z.object(schema)
Expand Down
24 changes: 24 additions & 0 deletions services/alert/webhook/src/core/push.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { fetch } from "cross-fetch"
import { ENV } from "./env";

export const sendCourseAlertPush = async (args: {
section_id: string
recipient: string[]
}) => {
const { section_id, recipient } = args

const res = await fetch(ENV.PUSH_ENDPOINT, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${ENV.PUSH_TOKEN}`
},
body: JSON.stringify({
usernames: recipient,
service: "COURSES",
title: `${section_id} is now open!`,
body: `${section_id} just opened up!`
})
})
return res.json()
}
32 changes: 32 additions & 0 deletions services/alert/webhook/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2205,6 +2205,13 @@ commander@^3.0.2:
resolved "https://registry.yarnpkg.com/commander/-/commander-3.0.2.tgz#6837c3fb677ad9933d1cfba42dd14d5117d6b39e"
integrity sha512-Gar0ASD4BDyKC4hl4DwHqDrmvjoxWKZigVnAbn5H1owvm4CxCPdb0HQDehwNYMJpla5+M2tPmPARzhtYuwpHow==

cross-fetch@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-4.0.0.tgz#f037aef1580bb3a1a35164ea2a848ba81b445983"
integrity sha512-e4a5N8lVvuLgAWgnCrLr2PP0YyDOTHa9H/Rj54dirp61qXnNq46m82bRhNqIA5VccJtWBvPTFRV3TtvHUKPB1g==
dependencies:
node-fetch "^2.6.12"

debug@^4.1.1, debug@^4.3.7:
version "4.3.7"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.7.tgz#87945b4151a011d76d95a198d7111c865c360a52"
Expand Down Expand Up @@ -2546,6 +2553,13 @@ nanoid@^3.3.7:
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.7.tgz#d0c301a691bc8d54efa0a2226ccf3fe2fd656bd8"
integrity sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==

node-fetch@^2.6.12:
version "2.7.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==
dependencies:
whatwg-url "^5.0.0"

obuf@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/obuf/-/obuf-1.1.2.tgz#09bea3343d41859ebd446292d11c9d4db619084e"
Expand Down Expand Up @@ -2832,6 +2846,11 @@ tinyspy@^3.0.2:
resolved "https://registry.yarnpkg.com/tinyspy/-/tinyspy-3.0.2.tgz#86dd3cf3d737b15adcf17d7887c84a75201df20a"
integrity sha512-n1cw8k1k0x4pgA2+9XrOkFydTerNcJ1zWCO5Nn9scWHTD+5tp8dghT2x1uduQePZTZgd3Tupf+x9BxJjeJi77Q==

tr46@~0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==

tsconfck@^3.0.3:
version "3.1.4"
resolved "https://registry.yarnpkg.com/tsconfck/-/tsconfck-3.1.4.tgz#de01a15334962e2feb526824339b51be26712229"
Expand Down Expand Up @@ -2964,6 +2983,19 @@ watchpack@^2.0.0-beta.10:
glob-to-regexp "^0.4.1"
graceful-fs "^4.1.2"

webidl-conversions@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
integrity sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==

whatwg-url@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
integrity sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==
dependencies:
tr46 "~0.0.3"
webidl-conversions "^3.0.0"

which-typed-array@^1.1.14, which-typed-array@^1.1.2:
version "1.1.15"
resolved "https://registry.yarnpkg.com/which-typed-array/-/which-typed-array-1.1.15.tgz#264859e9b11a649b388bfaaf4f767df1f779b38d"
Expand Down

0 comments on commit 01dd582

Please sign in to comment.