Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrapped emailing #913

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Wrapped emailing #913

wants to merge 11 commits into from

Conversation

NIDHI2023
Copy link
Contributor

@NIDHI2023 NIDHI2023 commented Dec 4, 2024

Summary

Credit to CoursePlan's email system for instructions to set up the system.

This PR creates a script that uses the Resend API to send automated emails to users that can see Wrapped. At most, it can send 100 emails each as a batch with 49 recipients in a day.

If it's the first time running the script, you should run: node <script path> 0
This will start the script from the first email (0th index). If the 100 email limit has been hit, there will be a console statement that tells you the next input number to run the next day.

  • ran npm install dotenv
  • ran yarn add resend

Test Plan

  • Throws error and stops control before calling the API if the emails exceed limit
  • BCC recipients cannot see each other, but they can see the main "TO" email - this should be a dummy email or the general DTI email
  • Images across different screens:
    Laptop:
    image

Mobile:
image
image

Notes

  • In the prod database would need to also update indexes for user like below:
    image
    Firebase auto-generates this when you run the script and get an initial error message with a link:
    image
    Should look like this at the end and script should be working
    image

  • Created online references to images with ImgBB

  • Fonts like Roboto don't seem to be rendering properly across all email providers - might just not be easily feasible

Breaking Changes

None

  • I have updated the documentation accordingly.
  • My PR adds a @ts-ignore

@dti-github-bot
Copy link
Member

dti-github-bot commented Dec 4, 2024

[diff-counting] Significant lines: 305.

src/scripts/wrapped-email.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@rgu0114 rgu0114 left a comment

Choose a reason for hiding this comment

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

Nice job testing this thoroughly and documenting your process well

Copy link
Contributor

@rgu0114 rgu0114 left a comment

Choose a reason for hiding this comment

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

Great work with this and figuring out the Resend API! No glaring issues I can see with this – only thing to watch out for when we run it is if we hit a limit, what's the best way to continue where we left off (if manually doing it is the best option, that's ok too).

if (batchSize > 49) {
throw new Error("Batch size is too large. Must be no more than 49");
}
while (i < totalEmails.length && emailObjs.length <= 100) {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe add an extra check totalEmails.length > 4900 in case

}
if (emailObjs.length === 100) {
// eslint-disable-next-line no-console
console.log("Reached email limit of 100 emails per day, stopped at i=" + i + ", user " + totalEmails[i] + ". \n Continue from this user the next day.");
Copy link
Contributor

Choose a reason for hiding this comment

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

how would we continue from this user the next day? are we manually keeping track of the last index?

// using orderBy for email field to filter out users that don't have an email
const usersSnapshot = await usersRef
.where('wrapped', '==',true)
.orderBy('email')
Copy link
Contributor

Choose a reason for hiding this comment

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

add a .where('email', '!=', null) condition to ensure we only fetch users with a valid email address (i think it's not always the case that a user's email exists)

@NIDHI2023 NIDHI2023 changed the title Wrapped emailing [Draft] Wrapped emailing Dec 20, 2024
@NIDHI2023 NIDHI2023 marked this pull request as ready for review December 20, 2024 17:29
@NIDHI2023 NIDHI2023 requested a review from a team as a code owner December 20, 2024 17:29
@NIDHI2023 NIDHI2023 force-pushed the nidhi/wrapped-email branch from 3de7139 to b3674b2 Compare January 19, 2025 23:33
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.

3 participants