refactor(discord notify): move to utlis so we can use it in other places outside the logger

This commit is contained in:
2025-09-02 17:56:36 -05:00
parent 80c0e1ec30
commit 4a1d95e818
4 changed files with 246 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
import type { Log } from "../db/schema/logs.js";
import { validateEnv } from "../utils/envValidator.js";
const env = validateEnv(process.env);
export async function sendNotify(log: any) {
const webhookUrl = process.env.WEBHOOK_URL!;
let payload = {
embeds: [
{
title: `🚨 ${env.PROD_PLANT_TOKEN}: encounter a critical error `,
description: `Where was the error: ${log.module}${
log.subModule ? `-${log.subModule}` : ""
}`,
color: 0xff0000, // red
fields: [
{
name: "Message",
value: log.message,
inline: false,
},
{
name: "Hostname",
value: log.hostname,
inline: false,
},
{
name: "Stack",
value: "```" + (log.stack ?? "no stack") + "```",
},
],
footer: {
text: "LST Logger 💀",
},
timestamp: new Date().toISOString(),
},
],
};
await fetch(webhookUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
});
}