Skip to content

Commit

Permalink
👷 Surround email alerts sending with try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Jun 26, 2023
1 parent 0582ca7 commit 6430d57
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions packages/scripts/sendAlertEmails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,20 @@ const sendAlertIfLimitReached = async (
console.log(
`Send almost reached chats limit email to ${to.join(', ')}...`
)
await sendAlmostReachedChatsLimitEmail({
to: workspace.members
.map((member) => member.user.email)
.filter(isDefined),
usagePercent: Math.round((totalChatsUsed / chatsLimit) * 100),
chatsLimit,
url: `https://app.typebot.io/typebots?workspaceId=${workspace.id}`,
})
await prisma.workspace.update({
where: { id: workspace.id },
data: { chatsLimitFirstEmailSentAt: new Date() },
})
try {
await sendAlmostReachedChatsLimitEmail({
to,
usagePercent: Math.round((totalChatsUsed / chatsLimit) * 100),
chatsLimit,
url: `https://app.typebot.io/typebots?workspaceId=${workspace.id}`,
})
await prisma.workspace.update({
where: { id: workspace.id },
data: { chatsLimitFirstEmailSentAt: new Date() },
})
} catch (err) {
console.error(err)
}
}

if (
Expand All @@ -159,16 +161,20 @@ const sendAlertIfLimitReached = async (
const to = workspace.members
.map((member) => member.user.email)
.filter(isDefined)
console.log(`Send reached chats limit email to ${to.join(', ')}...`)
await sendReachedChatsLimitEmail({
to,
chatsLimit,
url: `https://app.typebot.io/typebots?workspaceId=${workspace.id}`,
})
await prisma.workspace.update({
where: { id: workspace.id },
data: { chatsLimitSecondEmailSentAt: new Date() },
})
try {
console.log(`Send reached chats limit email to ${to.join(', ')}...`)
await sendReachedChatsLimitEmail({
to,
chatsLimit,
url: `https://app.typebot.io/typebots?workspaceId=${workspace.id}`,
})
await prisma.workspace.update({
where: { id: workspace.id },
data: { chatsLimitSecondEmailSentAt: new Date() },
})
} catch (err) {
console.error(err)
}
}

if (totalChatsUsed > chatsLimit * 3 && workspace.plan === Plan.FREE) {
Expand Down

0 comments on commit 6430d57

Please sign in to comment.