Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

update EMAIL_TEMPLATES_MAP

Steven Tey2e3640836f32
diff --git a/apps/web/lib/email/email-templates-map.ts b/apps/web/lib/email/email-templates-map.ts
index 91b8f892de..30c315c0fc 100644
--- a/apps/web/lib/email/email-templates-map.ts
+++ b/apps/web/lib/email/email-templates-map.ts
@@ -1,6 +1,6 @@
import BountyApproved from "@dub/email/templates/bounty-approved";
-import IdentityVerificationAnnouncement from "@dub/email/templates/broadcasts/identity-verification-announcement";
-import DubLaunchWeekDay5 from "@dub/email/templates/broadcasts/launch-week-day-5";
+import DubProductUpdateSummer26 from "@dub/email/templates/broadcasts/dub-product-update-summer26";
+import DubStartupProgramAnnouncement from "@dub/email/templates/broadcasts/dub-startup-program-announcement";
import ConnectPayoutReminder from "@dub/email/templates/connect-payout-reminder";
import ConnectPlatformsReminder from "@dub/email/templates/connect-platforms-reminder";
import PartnerBanned from "@dub/email/templates/partner-banned";
@@ -27,11 +27,6 @@ export const EMAIL_TEMPLATES_MAP = {
PartnerRewardUpdated,
WorkspaceDisabled,
// special broadcast emails
- // DubPartnerRewind,
- // DubProductUpdateMar26,
- IdentityVerificationAnnouncement,
- // PayoutAutoWithdrawals,
- // ProgramMarketplaceAnnouncement,
- // StablecoinPayoutsAnnouncement,
- DubLaunchWeekDay5,
+ DubStartupProgramAnnouncement,
+ DubProductUpdateSummer26,
} as const;
diff --git a/apps/web/scripts/reset-sent-mail.ts b/apps/web/scripts/reset-sent-mail.ts
index 3fa89da3be..57980c484f 100644
--- a/apps/web/scripts/reset-sent-mail.ts
+++ b/apps/web/scripts/reset-sent-mail.ts
@@ -7,6 +7,7 @@ async function main() {
where: {
sentMail: true,
},
+ take: 1000,
});
if (usersToReset.length === 0) {
console.log("No more users to reset");
diff --git a/apps/web/scripts/send-batch-emails.ts b/apps/web/scripts/send-batch-emails.ts
index 87ecc84859..8640257364 100644
--- a/apps/web/scripts/send-batch-emails.ts
+++ b/apps/web/scripts/send-batch-emails.ts
@@ -1,113 +1,75 @@
-import { PARTNER_NETWORK_EXCLUDED_PROGRAM_IDS } from "@/lib/constants/partner-profile";
import { prisma } from "@/lib/prisma";
-import DubLaunchWeekDay5 from "@dub/email/templates/broadcasts/launch-week-day-5";
+import DubStartupProgramAnnouncement from "@dub/email/templates/broadcasts/dub-startup-program-announcement";
import { chunk } from "@dub/utils";
import "dotenv-flow/config";
import { queueBatchEmail } from "../lib/email/queue-batch-email";
import { generateUnsubscribeToken } from "../lib/email/unsubscribe-token";
async function main() {
- while (true) {
- const usersWithPartners = await prisma.user.findMany({
- where: {
- sentMail: false,
- defaultPartnerId: {
- not: null,
- },
- partners: {
- some: {},
- },
- notificationPreferences: {
- partnerAccount: true,
- },
+ const workspaces = await prisma.project.findMany({
+ where: {
+ defaultProgramId: {
+ not: null,
+ },
+ plan: {
+ notIn: ["advanced", "enterprise"],
},
- take: 5000,
- include: {
- partners: {
- select: {
- partner: {
- select: {
- id: true,
- programs: {
- where: {
- programId: {
- in: PARTNER_NETWORK_EXCLUDED_PROGRAM_IDS,
- },
- },
- },
- },
+ },
+ include: {
+ programs: true,
+ users: {
+ where: {
+ user: {
+ email: {
+ not: null,
+ },
+ sentMail: false,
+ notificationPreferences: {
+ dubPartners: true,
},
},
},
- },
- });
- if (usersWithPartners.length === 0) {
- console.log("No more users to notify");
- break;
- }
-
- const programEnrollmentsByPartner = await prisma.programEnrollment.groupBy({
- by: ["partnerId"],
- where: {
- partnerId: {
- in: usersWithPartners.map((user) => user.defaultPartnerId!),
+ include: {
+ user: true,
},
},
- _count: {
- programId: true,
- },
- });
-
- const programEnrollmentCountsByPartnerId =
- programEnrollmentsByPartner.reduce(
- (acc, { partnerId, _count }) => {
- acc[partnerId] = _count.programId;
- return acc;
- },
- {} as Record<string, number>,
- );
+ },
+ });
- const usersToNotify = usersWithPartners.filter((user) =>
- user.partners.every(
- ({ partner }) =>
- !(
- partner.programs.length > 0 &&
- programEnrollmentCountsByPartnerId[partner.id] === 1
- ),
- ),
- );
+ const usersToNotify = workspaces.flatMap((workspace) =>
+ workspace.users.map((user) => user.user),
+ );
- console.log(`Found ${usersToNotify.length} users to notify`);
+ console.log(`Found ${usersToNotify.length} users to notify`);
- const res = await queueBatchEmail<typeof DubLaunchWeekDay5>(
- usersToNotify.map((user) => ({
- to: user.email!,
- variant: "marketing",
- subject: "Introducing the Dub Network Referral Bonus",
- templateName: "DubLaunchWeekDay5",
- templateProps: {
- email: user.email!,
- unsubscribeUrl: `https://app.dub.co/unsubscribe/${generateUnsubscribeToken(user.email!)}`,
- },
- })),
- );
+ const res = await queueBatchEmail<typeof DubStartupProgramAnnouncement>(
+ usersToNotify.map((user) => ({
+ to: user.email!,
+ variant: "marketing",
+ subject: "Introducing the Dub Startup Program 🚀",
+ templateName: "DubStartupProgramAnnouncement",
+ templateProps: {
+ email: user.email!,
+ unsubscribeUrl: `https://app.dub.co/unsubscribe/${generateUnsubscribeToken(user.email!)}`,
+ },
+ })),
+ );
- console.log(res);
+ console.log(res);
- const chunkedUsersWithPartners = chunk(usersWithPartners, 1000);
- for (const cu of chunkedUsersWithPartners) {
- const res = await prisma.user.updateMany({
- where: {
- id: {
- in: cu.map((u) => u.id),
- },
- },
- data: {
- sentMail: true,
+ const chunkedUsersToNotify = chunk(usersToNotify, 1000);
+ for (const cu of chunkedUsersToNotify) {
+ const res = await prisma.user.updateMany({
+ where: {
+ id: {
+ in: cu.map((u) => u.id),
},
- });
- console.log(`Updated ${res.count} users to sentMail: true`);
- }
+ },
+ data: {
+ sentMail: true,
+ },
+ });
+ console.log(`Updated ${res.count} users to sentMail: true`);
}
}