Skip to content

Commit 732bb90

Browse files
authored
Merge pull request #1833 from Mephistic/move-email-templates
Fix Email Notification Bugs
2 parents d9927fe + ceb940a commit 732bb90

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

functions/src/notifications/deliverNotifications.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import * as handlebars from "handlebars"
33
import * as fs from "fs"
44
import { db, Timestamp } from "../firebase"
55
//import { auth, db, Timestamp } from "../firebase" // Temporarily using email from the profile to test the non-auth issues
6-
import { getNextDigestAt, getNotificationStartDate } from "./helpers"
6+
import {
7+
convertHtmlToText,
8+
getNextDigestAt,
9+
getNotificationStartDate
10+
} from "./helpers"
711
import { startOfDay } from "date-fns"
812
import { TestimonySubmissionNotificationFields, Profile } from "./types"
913
import {
@@ -87,13 +91,16 @@ const deliverEmailNotifications = async () => {
8791
`No new notifications for ${profileDoc.id} - not sending email`
8892
)
8993
} else {
94+
console.log(
95+
`Sending email to user ${profileDoc.id} with data: ${digestData}`
96+
)
9097
const htmlString = renderToHtmlString(digestData)
9198

9299
const email = {
93100
to: [verifiedEmail],
94101
message: {
95102
subject: "Your Notifications Digest",
96-
text: "", // blank because we're sending HTML
103+
text: convertHtmlToText(htmlString), // TODO: Just make a text template for this
97104
html: htmlString
98105
},
99106
createdAt: Timestamp.now()

functions/src/notifications/helpers.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {
99
subMonths
1010
} from "date-fns"
1111

12+
import { JSDOM } from "jsdom"
13+
1214
export const getNextDigestAt = (notificationFrequency: Frequency) => {
1315
const now = startOfDay(new Date())
1416
let nextDigestAt = null
@@ -49,3 +51,8 @@ export const getNotificationStartDate = (
4951
return now
5052
}
5153
}
54+
55+
export const convertHtmlToText = (html: string) => {
56+
const dom = new JSDOM(html)
57+
return dom.window.document.body.textContent || "No content"
58+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"build:dev": "MAPLE_ENV=dev next build",
77
"build:prod": "MAPLE_ENV=prod next build",
8-
"build:functions": "next lint -d functions/src && yarn --cwd functions build",
8+
"build:functions": "next lint -d functions/src && yarn --cwd functions build && yarn copy-handlebars",
99
"check-formatting": "prettier --check .",
1010
"check-types": "tsc --noEmit",
1111
"deploy:backend:dev": "firebase --project=default deploy --only firestore,functions,storage",

0 commit comments

Comments
 (0)