diff --git a/front/lib/email.ts b/front/lib/email.ts index cdb862f8e882..609a622ef145 100644 --- a/front/lib/email.ts +++ b/front/lib/email.ts @@ -107,3 +107,20 @@ export async function sendReactivateSubscriptionEmail( }; return sendEmail(email, reactivateMessage); } + +export async function sendOpsEmail(workspaceSId: string): Promise { + const opsMessage = { + from: { + name: "System", + email: "ops@dust.tt", + }, + subject: `[OPS] A subscription has been canceled`, + html: `

Hi Dust ops,

+

The subscription of workspace '${workspaceSId}' was just canceled. Go to the Poke Page and manually delete its connections

+

Also, for the first cancellations, quickly check that users have been properly revoked and the plan switched back to free

+

We'll automate this soon. Just doing that to be extra sure for the ~10 first downgrades.

+

Sincerely, +

Ourselves

`, + }; + return sendEmail("ops@dust.tt", opsMessage); +} diff --git a/front/pages/api/stripe/webhook.ts b/front/pages/api/stripe/webhook.ts index f8b06eb2910d..f60821cde855 100644 --- a/front/pages/api/stripe/webhook.ts +++ b/front/pages/api/stripe/webhook.ts @@ -8,6 +8,7 @@ import { Authenticator } from "@app/lib/auth"; import { front_sequelize } from "@app/lib/databases"; import { sendCancelSubscriptionEmail, + sendOpsEmail, sendReactivateSubscriptionEmail, } from "@app/lib/email"; import { ReturnedAPIErrorType } from "@app/lib/error"; @@ -351,6 +352,7 @@ async function handler( // We can end the subscription in our database. const activeSubscription = await Subscription.findOne({ where: { stripeSubscriptionId: stripeSubscription.id }, + include: [Workspace], }); if (!activeSubscription) { return apiError(req, res, { @@ -366,6 +368,7 @@ async function handler( status: "ended", endDate: new Date(), }); + await sendOpsEmail(activeSubscription.workspace.sId); } else { logger.warn( { event },