Skip to content

Commit

Permalink
EVG-355: Email notification automation (#150)
Browse files Browse the repository at this point in the history
* add relations for notifications and notification channels

* fill up notification channels and then create notifications

* use DocumentNode types for GraphQL queries in server-side groups module

* make notification related GraphQL queries use generated typings, split up gql files into folders

* integrate sendinblue API, allow sending, withholding and expiring email notifications

* stub sendinblue API key environment variable where necessary

* update dependencies

* inject SENDINBLUE_API_KEY environment variable from secrets
  • Loading branch information
haveyaseen authored Jul 22, 2021
1 parent 1ffee06 commit f77f0a7
Show file tree
Hide file tree
Showing 65 changed files with 11,112 additions and 3,221 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
echo "POSTGRES_DB=everglot_app_db" >> .env
echo "SESSION_COOKIE_VALIDATION_SECRETS=[\"MySecretCookieValidationSecret123\"]" >> .env
echo "AGORA_APP_CERTIFICATE=whatever" >> .env
echo "SENDINBLUE_API_KEY=whatever" >> .env
- name: "Setup server-side Firebase credentials file"
run: |
echo "${{ secrets.FIREBASE_SERVICE_ACCOUNT_JSON_BASE64 }}" | base64 -d > src/firebaseServiceAccount.json
Expand Down Expand Up @@ -97,6 +98,12 @@ jobs:
- name: Inject Admin Emails from Github Secrets
run: kubectl create secret generic adminemails --from-literal=admin-emails='${{ secrets.ADMIN_EMAILS }}'

- name: Delete Sendinblue API Key from Kubernetes Secrets if existed
run: kubectl delete secret sendinblueapikey --ignore-not-found

- name: Inject Sendinblue API Key from Github Secrets
run: kubectl create secret generic sendinblueapikey --from-literal=sendinblue-api-key='${{ secrets.SENDINBLUE_API_KEY }}'

- name: Deploy Config to DigitalOcean Kubernetes
run: kubectl apply -f $GITHUB_WORKSPACE/k8s-setup/everglot/service-deployment.yml

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mutation MarkNotificationAsSent($id: Int!, $sentAt: Datetime) {
updateNotification(input: {patch: {sentAt: $sentAt}, id: $id}) {
notification {
id
sentAt
__typename
}
__typename
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
query UsersWithoutNativeGroup($lid: Int!, $nativeSize: Int!) {
usersWithoutNativeGroup(lid: $lid, first: $nativeSize) {
nodes {
id
__typename
}
__typename
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
query NotificationChannelByName($name: String!) {
notificationChannelByName(name: $name) {
id
__typename
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
mutation CreateGroupUser($userType: UserType!, $userId: Int!, $groupId: Int!) {
createGroupUser(input: {groupUser: {userType: $userType, userId: $userId, groupId: $groupId}}) {
groupUser {
id
__typename
}
__typename
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
query UsersWithoutLearnerGroup($lid: Int!, $lsklid: Int!, $learnerSize: Int!) {
usersWithoutLearnerGroup(lid: $lid, lsklid: $lsklid, first: $learnerSize) {
nodes {
id
__typename
}
__typename
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
query OutstandingEmailNotifications {
notificationChannelByName(name: "Email") {
notificationsByChannelId(orderBy: CREATED_AT_ASC, filter: {sentAt: {isNull: true}}) {
nodes {
id
user {
email
emailNotificationsEnabled
username
unconfirmedEmail
__typename
}
params
expiresAt
withheldUntil
__typename
}
__typename
}
__typename
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mutation CreateNotification($channelId: Int!, $userId: Int!, $sentAt: Datetime, $params: JSON, $expiresAt: Datetime, $withheldUntil: Datetime) {
createNotification(input: {notification: {userId: $userId, channelId: $channelId, params: $params, sentAt: $sentAt, expiresAt: $expiresAt, withheldUntil: $withheldUntil}}) {
clientMutationId
notification {
createdAt
expiresAt
withheldUntil
id
__typename
}
__typename
}
}
1 change: 1 addition & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ services:
DATABASE_URL: "postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${PGHOST:-everglot-db}:${PGPORT}/${POSTGRES_DB}"
SESSION_COOKIE_VALIDATION_SECRETS: ${SESSION_COOKIE_VALIDATION_SECRETS:?Please set SESSION_COOKIE_VALIDATION_SECRETS}
AGORA_APP_CERTIFICATE: ""
SENDINBLUE_API_KEY: ""
entrypoint: entrypoints/test-after-app.sh
# Avoid building the same image twice.
image: everglot-app-image
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ services:
DATABASE_URL: "postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${PGHOST:-everglot-db}:${PGPORT}/${POSTGRES_DB}"
SESSION_COOKIE_VALIDATION_SECRETS: ${SESSION_COOKIE_VALIDATION_SECRETS:?Please set SESSION_COOKIE_VALIDATION_SECRETS}
AGORA_APP_CERTIFICATE: ${AGORA_APP_CERTIFICATE:?Please set AGORA_APP_CERTIFICATE}
SENDINBLUE_API_KEY: ${SENDINBLUE_API_KEY:?Please set SENDINBLUE_API_KEY}

everglot-db:
image: postgres:13-alpine
Expand Down
Loading

0 comments on commit f77f0a7

Please sign in to comment.