Add notify-on-answer email and save-as-image for Q&A; v1.0.10
- Contact form: notifyOnAnswer checkbox (shown for Bible Questions only) - Contact route: stores notifyOnAnswer flag on question record - Email: buildQuestionAnsweredEmailTemplate for branded notification - Questions route: sends notification email on approve when notifyOnAnswer + email + answer are set - Q&A section: Canvas API "Save as image" button generates 1080x1080 PNG quote card Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,9 @@ import { requireAdminAuth } from '../auth.js'
|
||||
import { MAX_QUESTIONS } from '../config.js'
|
||||
import { state } from '../state.js'
|
||||
import { queueQuestionsWrite, queueDraftQuestionsWrite } from '../data.js'
|
||||
import { buildQuestionAnsweredEmailTemplate, getResendFromAddress, getResendReplyToAddress, sendResendEmailWithRetry, getCanonicalBaseUrl } from '../email.js'
|
||||
import { buildAbsoluteUrl } from '../helpers.js'
|
||||
import { Resend } from 'resend'
|
||||
|
||||
function ensureDraftQuestions() {
|
||||
if (state.draftQuestions !== null) return
|
||||
@@ -103,6 +106,29 @@ export function register(app) {
|
||||
question.approvedAt = approved === true ? new Date().toISOString() : null
|
||||
queueDraftQuestionsWrite()
|
||||
|
||||
if (approved === true && question.notifyOnAnswer && question.email && question.answer) {
|
||||
try {
|
||||
const resend = new Resend(process.env.RESEND_API_KEY)
|
||||
const from = getResendFromAddress()
|
||||
const replyTo = getResendReplyToAddress()
|
||||
const baseUrl = getCanonicalBaseUrl()
|
||||
const questionUrl = buildAbsoluteUrl(baseUrl, `/questions#qa-${question.id}`)
|
||||
const template = buildQuestionAnsweredEmailTemplate({
|
||||
firstName: question.firstName,
|
||||
question: question.question,
|
||||
answer: question.answer,
|
||||
questionUrl,
|
||||
})
|
||||
await sendResendEmailWithRetry({
|
||||
resend,
|
||||
payload: { from, replyTo, to: question.email, subject: template.subject, text: template.text, html: template.html },
|
||||
context: `notify-on-answer:${question.id}`,
|
||||
})
|
||||
} catch (err) {
|
||||
console.error('[notify-on-answer] Failed to send notification email:', err?.message ?? err)
|
||||
}
|
||||
}
|
||||
|
||||
res.json({ ok: true, question })
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user