Skip to content

Mail when new Feedback Submitted#153

Open
PaulGoldschmidt wants to merge 8 commits into
mainfrom
feature/new-feedback-info
Open

Mail when new Feedback Submitted#153
PaulGoldschmidt wants to merge 8 commits into
mainfrom
feature/new-feedback-info

Conversation

@PaulGoldschmidt

@PaulGoldschmidt PaulGoldschmidt commented Mar 24, 2026

Copy link
Copy Markdown
Collaborator

Mail when new Feedback Submitted

♻️ Current situation & Problem

@AJohn155 requested that he gets notified upon new feedback submitted. This PR aims to solve this by sending a mail to a given address upon

⚙️ Release Notes

I decided to use Nodemailer instead of the firebase provided firestore send email function which would need additional setup by garrick and offers no real benefit as we still need our own SMTP sender anyways.

📚 Documentation

N/A

✅ Testing

For testing I need SMTP credentials, @PSchmiedmayer could you provide me with some? Also need to add these before merging into GCP IAM as a secret.

Code of Conduct & Contributing Guidelines

By creating and submitting this pull request, you agree to follow our Code of Conduct and Contributing Guidelines:

@coderabbitai

coderabbitai Bot commented Mar 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d798bd62-1c54-4247-adac-0c20ff12ab26

📥 Commits

Reviewing files that changed from the base of the PR and between 9e7c45f and 30e4bd6.

📒 Files selected for processing (2)
  • functions/src/env.ts
  • functions/src/functions/onFeedbackCreated.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • functions/src/env.ts
  • functions/src/functions/onFeedbackCreated.ts

📝 Walkthrough

Walkthrough

The changes add a Firestore trigger that formats newly created feedback documents and sends notification emails through Nodemailer and SMTP. SMTP credentials and feedback addresses are defined as secrets with exported getters. Nodemailer dependencies are added, and the trigger is re-exported from the functions entry point.

Sequence Diagram(s)

sequenceDiagram
    participant Firestore
    participant onFeedbackCreated
    participant EnvSecrets
    participant Nodemailer
    participant SMTPService

    Firestore->>onFeedbackCreated: feedback document created
    onFeedbackCreated->>onFeedbackCreated: format subject and body
    onFeedbackCreated->>EnvSecrets: read SMTP and email secrets
    EnvSecrets-->>onFeedbackCreated: return configuration
    onFeedbackCreated->>Nodemailer: create transporter and send mail
    Nodemailer->>SMTPService: relay email
    SMTPService-->>onFeedbackCreated: return send result
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: sending email when new feedback is submitted.
Description check ✅ Passed The description is clearly related to the feedback-email feature and the Nodemailer implementation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@functions/src/functions/onFeedbackCreated.ts`:
- Line 63: Guard against invalid SMTP port by validating the value returned from
getSmtpPort(): replace the direct Number(getSmtpPort()) usage (the const port
variable) with parsing and a sanity check (e.g., parseInt or Number, then
isFinite and >0 && <=65535); if invalid, either throw a clear configuration
error or fall back to a safe default port (e.g., 587) before passing it to
nodemailer createTransport/send logic so transporter always receives a valid
numeric port.
- Around line 84-88: The catch block in onFeedbackCreated currently only logs
errors for send failures (`logger.error(...)` referencing feedbackId) which
prevents Firebase from retrying; decide whether notifications are critical and
either rethrow the error (throw error) so Firebase will retry the function, or
if you want best-effort keep the swallow but add actionable monitoring (e.g.,
emit a metric/event or call an alerting helper) and document the choice in
onFeedbackCreated’s comments; implement the chosen approach by modifying the
catch block around the email send call to either rethrow the caught error or
invoke the monitoring/alerting helper and leave a comment explaining the
decision.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1b7052d5-57b8-4d53-8855-f9400c2cdf6b

📥 Commits

Reviewing files that changed from the base of the PR and between 3571f93 and 5fa640d.

⛔ Files ignored due to path filters (1)
  • functions/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • functions/package.json
  • functions/src/env.ts
  • functions/src/functions/onFeedbackCreated.ts
  • functions/src/index.ts

Comment thread functions/src/functions/onFeedbackCreated.ts
Comment on lines +84 to +88
} catch (error) {
logger.error(
`Failed to send feedback notification for ${feedbackId}: ${String(error)}`,
);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Silent failure may cause lost notifications.

When email sending fails, the error is logged but not rethrown. This means Firebase considers the function successful and will not retry. Feedback notifications could be silently lost with only a log entry.

Consider whether this is intentional:

  • If notifications are critical: Rethrow the error so Firebase retries the function (with exponential backoff).
  • If best-effort is acceptable: Add alerting/monitoring on these error logs so failures are actionable.
Option A: Rethrow to enable retries
     } catch (error) {
       logger.error(
         `Failed to send feedback notification for ${feedbackId}: ${String(error)}`,
       );
+      throw error; // Allow Firebase to retry
     }
Option B: Keep silent failure but document the decision
     } catch (error) {
+      // Intentionally not rethrowing: avoid duplicate emails on transient SMTP failures.
+      // Monitor these logs for persistent failures.
       logger.error(
         `Failed to send feedback notification for ${feedbackId}: ${String(error)}`,
       );
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} catch (error) {
logger.error(
`Failed to send feedback notification for ${feedbackId}: ${String(error)}`,
);
}
} catch (error) {
logger.error(
`Failed to send feedback notification for ${feedbackId}: ${String(error)}`,
);
throw error; // Allow Firebase to retry
}
Suggested change
} catch (error) {
logger.error(
`Failed to send feedback notification for ${feedbackId}: ${String(error)}`,
);
}
} catch (error) {
// Intentionally not rethrowing: avoid duplicate emails on transient SMTP failures.
// Monitor these logs for persistent failures.
logger.error(
`Failed to send feedback notification for ${feedbackId}: ${String(error)}`,
);
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@functions/src/functions/onFeedbackCreated.ts` around lines 84 - 88, The catch
block in onFeedbackCreated currently only logs errors for send failures
(`logger.error(...)` referencing feedbackId) which prevents Firebase from
retrying; decide whether notifications are critical and either rethrow the error
(throw error) so Firebase will retry the function, or if you want best-effort
keep the swallow but add actionable monitoring (e.g., emit a metric/event or
call an alerting helper) and document the choice in onFeedbackCreated’s
comments; implement the chosen approach by modifying the catch block around the
email send call to either rethrow the caught error or invoke the
monitoring/alerting helper and leave a comment explaining the decision.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a critcial component.

@PSchmiedmayer PSchmiedmayer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PaulGoldschmidt Looks solid; to be followed up once we have the SMPT credentials in place.

@PaulGoldschmidt

Copy link
Copy Markdown
Collaborator Author

thanks; will include this if possible in release 4.0.2.

@PaulGoldschmidt

Copy link
Copy Markdown
Collaborator Author

because we can't send transactional emails currently with stanford's mail servers, we might have to postpone this feature for now.

@PaulGoldschmidt

Copy link
Copy Markdown
Collaborator Author

closing this for now, maybe adding this in the future if we have proper mail sending infra.

@PaulGoldschmidt

Copy link
Copy Markdown
Collaborator Author

sending infra is now available! 🎉

@PSchmiedmayer PSchmiedmayer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine with merging this once tested, nice work @PaulGoldschmidt 🚀

@PaulGoldschmidt

Copy link
Copy Markdown
Collaborator Author

will merge this now, test in Staging and then pack a new release after checking that everything works soon @PSchmiedmayer 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants