Add email notification on new lesson comment

Notify admins/curators (or configured notificationEmails) when a student
leaves a comment under a lesson. New setting notifyOnComment (default on) +
toggle in admin settings. Fires only for student comments, not admin/curator
replies; comment text is HTML-escaped in the email.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-01 10:02:07 +05:00
parent d20e277535
commit 7c8e72cd94
4 changed files with 53 additions and 2 deletions
+25
View File
@@ -137,6 +137,31 @@ export async function sendHomeworkSubmittedEmail(
}).catch((e) => console.error("[email] sendHomeworkSubmittedEmail:", e));
}
export async function sendCommentNotificationEmail(
to: string,
recipientName: string,
studentName: string,
lessonTitle: string,
commentText: string,
lessonUrl: string
) {
const school = await getSchoolName();
const esc = (t: string) => t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
const preview = commentText.length > 400 ? commentText.slice(0, 400) + "…" : commentText;
await getResend().emails.send({
from: FROM,
to,
subject: `Новый комментарий под уроком — ${lessonTitle}`,
html: base(`
<p ${p}>Привет${recipientName ? `, ${esc(recipientName)}` : ""}!</p>
<p ${p}><strong>${esc(studentName)}</strong> оставил комментарий под уроком <strong>«${lessonTitle}»</strong>:</p>
${quote(esc(preview))}
<p ${pLast}>Открыть урок и ответить:</p>
${btn(lessonUrl, "Открыть урок")}
`, school),
}).catch((e) => console.error("[email] sendCommentNotificationEmail:", e));
}
export async function sendFeedbackReceivedEmail(
to: string,
studentName: string,