👷 Surround email alerts sending with try catch
This commit is contained in:
@ -137,18 +137,20 @@ const sendAlertIfLimitReached = async (
|
|||||||
console.log(
|
console.log(
|
||||||
`Send almost reached chats limit email to ${to.join(', ')}...`
|
`Send almost reached chats limit email to ${to.join(', ')}...`
|
||||||
)
|
)
|
||||||
await sendAlmostReachedChatsLimitEmail({
|
try {
|
||||||
to: workspace.members
|
await sendAlmostReachedChatsLimitEmail({
|
||||||
.map((member) => member.user.email)
|
to,
|
||||||
.filter(isDefined),
|
usagePercent: Math.round((totalChatsUsed / chatsLimit) * 100),
|
||||||
usagePercent: Math.round((totalChatsUsed / chatsLimit) * 100),
|
chatsLimit,
|
||||||
chatsLimit,
|
url: `https://app.typebot.io/typebots?workspaceId=${workspace.id}`,
|
||||||
url: `https://app.typebot.io/typebots?workspaceId=${workspace.id}`,
|
})
|
||||||
})
|
await prisma.workspace.update({
|
||||||
await prisma.workspace.update({
|
where: { id: workspace.id },
|
||||||
where: { id: workspace.id },
|
data: { chatsLimitFirstEmailSentAt: new Date() },
|
||||||
data: { chatsLimitFirstEmailSentAt: new Date() },
|
})
|
||||||
})
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -159,16 +161,20 @@ const sendAlertIfLimitReached = async (
|
|||||||
const to = workspace.members
|
const to = workspace.members
|
||||||
.map((member) => member.user.email)
|
.map((member) => member.user.email)
|
||||||
.filter(isDefined)
|
.filter(isDefined)
|
||||||
console.log(`Send reached chats limit email to ${to.join(', ')}...`)
|
try {
|
||||||
await sendReachedChatsLimitEmail({
|
console.log(`Send reached chats limit email to ${to.join(', ')}...`)
|
||||||
to,
|
await sendReachedChatsLimitEmail({
|
||||||
chatsLimit,
|
to,
|
||||||
url: `https://app.typebot.io/typebots?workspaceId=${workspace.id}`,
|
chatsLimit,
|
||||||
})
|
url: `https://app.typebot.io/typebots?workspaceId=${workspace.id}`,
|
||||||
await prisma.workspace.update({
|
})
|
||||||
where: { id: workspace.id },
|
await prisma.workspace.update({
|
||||||
data: { chatsLimitSecondEmailSentAt: new Date() },
|
where: { id: workspace.id },
|
||||||
})
|
data: { chatsLimitSecondEmailSentAt: new Date() },
|
||||||
|
})
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (totalChatsUsed > chatsLimit * 3 && workspace.plan === Plan.FREE) {
|
if (totalChatsUsed > chatsLimit * 3 && workspace.plan === Plan.FREE) {
|
||||||
|
Reference in New Issue
Block a user