Skip to content
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f1bce72
Update notifications to use new notification package
thiessenp-cds Jan 6, 2026
266ea22
Merge branch 'main' into feat/notification-v3
thiessenp-cds Jan 6, 2026
b58647c
Update import
thiessenp-cds Jan 6, 2026
4678663
Merge branch 'main' into feat/notification-v3
thiessenp-cds Jan 6, 2026
c33ad2f
Update log message
thiessenp-cds Jan 6, 2026
8ddf21b
Merge branch 'feat/notification-v3' of https://github.com/cds-snc/pla…
thiessenp-cds Jan 6, 2026
7b626b8
Merge branch 'main' into feat/notification-v3
thiessenp-cds Jan 12, 2026
3b6f94b
Merge branch 'main' into feat/notification-v3
thiessenp-cds Jan 12, 2026
caf0780
Merge branch 'main' into feat/notification-v3
thiessenp-cds Jan 13, 2026
455d08f
Merge branch 'main' into feat/notification-v3
thiessenp-cds Jan 13, 2026
804e1d6
Merge branch 'main' into feat/notification-v3
thiessenp-cds Jan 14, 2026
cb3c5ce
Merge branch 'main' into feat/notification-v3
thiessenp-cds Jan 15, 2026
07ed6be
Merge branch 'main' into feat/notification-v3
thiessenp-cds Jan 19, 2026
51eccd6
Merge branch 'main' into feat/notification-v3
thiessenp-cds Jan 19, 2026
27eafdc
Merge branch 'main' into feat/notification-v3
thiessenp-cds Jan 20, 2026
b6365ce
Merge branch 'main' into feat/notification-v3
thiessenp-cds Jan 22, 2026
3e266d2
Merge branch 'main' into feat/notification-v3
thiessenp-cds Jan 23, 2026
b7f09e7
Merge branch 'main' into feat/notification-v3
thiessenp-cds Jan 27, 2026
aa0174f
Merge branch 'main' into feat/notification-v3
thiessenp-cds Jan 28, 2026
2d9e557
Merge branch 'main' into feat/notification-v3
thiessenp-cds Feb 4, 2026
b7117a2
Merge branch 'main' into feat/notification-v3
thiessenp-cds Feb 4, 2026
20714a1
Merge branch 'main' into feat/notification-v3
thiessenp-cds Feb 9, 2026
24c251e
Merge branch 'main' into feat/notification-v3
thiessenp-cds Feb 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 22 additions & 38 deletions lib/notifications.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { sendEmail } from "@lib/integration/notifyConnector";
import { notification } from "@gcforms/connectors";
import { logMessage } from "@lib/logger";
import { getRedisInstance } from "@lib/integration/redisConnector";
import { getOrigin } from "@lib/origin";
Expand Down Expand Up @@ -41,7 +41,7 @@ export const sendNotifications = async (formId: string, titleEn: string, titleFr
case Status.SINGLE_EMAIL_SENT:
// Single submissions email sent but not multiple submissions email, send multiple email
Promise.all([
sendEmailNotificationsToAllUsers(users, formId, titleEn, titleFr, true),
sendEmailAfterSubmissionProcessed(users, formId, titleEn, titleFr, true),
setMarker(formId, Status.MULTIPLE_EMAIL_SENT),
]);
break;
Expand All @@ -51,7 +51,7 @@ export const sendNotifications = async (formId: string, titleEn: string, titleFr
default:
// No email has been sent, send single submission email
Promise.all([
sendEmailNotificationsToAllUsers(users, formId, titleEn, titleFr, false),
sendEmailAfterSubmissionProcessed(users, formId, titleEn, titleFr, false),
setMarker(formId),
]);
}
Expand Down Expand Up @@ -171,7 +171,7 @@ const getMarker = async (formId: string) => {
.catch((err) => logMessage.error(`getMarker: ${err}`));
};

const sendEmailNotificationsToAllUsers = async (
const sendEmailAfterSubmissionProcessed = async (
users: {
email: string;
enabled: boolean;
Expand All @@ -181,47 +181,31 @@ const sendEmailNotificationsToAllUsers = async (
formTitleFr: string,
multipleSubmissions: boolean = false
) => {
if (!Array.isArray(users) || users.length === 0) {
logMessage.debug("sendEmailNotificationsToAllUsers missing users");
return;
}
users.forEach(
({ email, enabled }) =>
enabled && sendEmailNotification(email, formId, formTitleEn, formTitleFr, multipleSubmissions)
);
};
try {
const { t } = await serverTranslation("form-builder");
const HOST = await getOrigin();

const sendEmailNotification = async (
email: string,
formId: string,
formTitleEn: string,
formTitleFr: string,
multipleSubmissions: boolean = false
) => {
const { t } = await serverTranslation("form-builder");
const HOST = await getOrigin();
await sendEmail(
email,
{
if (!Array.isArray(users) || users.length === 0) {
logMessage.debug("Deferred notification skipped since missing users");
return;
}
const emails = users.filter(({ enabled }) => enabled).map(({ email }) => email);

await notification.sendDeferred({
notificationId: formId,
emails,
subject: multipleSubmissions
? t("settings.notifications.email.multipleSubmissions.subject")
: t("settings.notifications.email.singleSubmission.subject"),
formResponse: multipleSubmissions
body: multipleSubmissions
? await multipleSubmissionsEmailTemplate(HOST, formTitleEn, formTitleFr)
: await singleSubmissionEmailTemplate(HOST, formTitleEn, formTitleFr),
},
"notification"
)
.then(() =>
logMessage.debug(
`sendEmailNotification sent email to ${email} with formId ${formId} for type ${
multipleSubmissions ? "multiple email" : "single email"
}`
)
)
.catch(() =>
logMessage.error(`sendEmailNotification failed to send email ${email} with formId ${formId}`)
});
} catch (error) {
logMessage.warn(
`Deferred notification failed for formId ${formId} with error: ${(error as Error).message}`
);
}
};

const singleSubmissionEmailTemplate = async (
Expand Down
Loading