Skip to content

Commit 13220e2

Browse files
committed
[Doom - Downgrade] Email ops when subscription cancelation takes effect
1 parent 0cd64ea commit 13220e2

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

front/lib/email.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,20 @@ export async function sendReactivateSubscriptionEmail(
107107
};
108108
return sendEmail(email, reactivateMessage);
109109
}
110+
111+
export async function sendOpsEmail(workspaceSId: string): Promise<void> {
112+
const opsMessage = {
113+
from: {
114+
name: "System",
115+
email: "ops@dust.tt",
116+
},
117+
subject: `[OPS] A subscription has been canceled`,
118+
html: `<p>Hi Dust ops,</p>
119+
<p>The subscription of workspace '${workspaceSId}' was just canceled. Go to the <a href="https://dust.tt/poke/${workspaceSId}">Poke Page</a> and manually delete its connections</p>
120+
<p>Also, for the first cancellations, quickly check that users have been properly revoked and the plan switched back to free</p>
121+
<p>We'll automate this soon. Just doing that to be extra sure for the ~10 first downgrades.</p>
122+
<p>Sincerely,
123+
<p>Ourselves</p>`,
124+
};
125+
return sendEmail("ops@dust.tt", opsMessage);
126+
}

front/pages/api/stripe/webhook.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Authenticator } from "@app/lib/auth";
88
import { front_sequelize } from "@app/lib/databases";
99
import {
1010
sendCancelSubscriptionEmail,
11+
sendOpsEmail,
1112
sendReactivateSubscriptionEmail,
1213
} from "@app/lib/email";
1314
import { ReturnedAPIErrorType } from "@app/lib/error";
@@ -351,6 +352,7 @@ async function handler(
351352
// We can end the subscription in our database.
352353
const activeSubscription = await Subscription.findOne({
353354
where: { stripeSubscriptionId: stripeSubscription.id },
355+
include: [Workspace],
354356
});
355357
if (!activeSubscription) {
356358
return apiError(req, res, {
@@ -366,6 +368,7 @@ async function handler(
366368
status: "ended",
367369
endDate: new Date(),
368370
});
371+
await sendOpsEmail(activeSubscription.workspace.sId);
369372
} else {
370373
logger.warn(
371374
{ event },

0 commit comments

Comments
 (0)