2
0

👷 Surround email alerts sending with try catch

This commit is contained in:
Baptiste Arnaud
2023-06-26 09:40:26 +02:00
parent 0582ca74ac
commit 6430d576ad

View File

@ -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 (
@ -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) {