generated from nhcarrigan/template
feat: send discord logs
This commit is contained in:
1
prod.env
1
prod.env
@ -2,3 +2,4 @@ MATRIX_ACCESS_TOKEN="op://Environment Variables - Naomi/Alert Server/matrix_acce
|
||||
MATRIX_ROOM_ID="op://Environment Variables - Naomi/Alert Server/matrix_room_id"
|
||||
API_AUTH="op://Environment Variables - Naomi/Alert Server/api_auth"
|
||||
EMAIL_PASSWORD="op://Environment Variables - Naomi/Alert Server/email_pass"
|
||||
DISCORD_WEBHOOK_URL="op://Environment Variables - Naomi/Alert Server/discord_hook"
|
47
src/modules/discord.ts
Normal file
47
src/modules/discord.ts
Normal file
@ -0,0 +1,47 @@
|
||||
/**
|
||||
* @copyright nhcarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sends a Discord webhook notification.
|
||||
* @param subject - The subject of the email.
|
||||
* @param body - The text content of the email.
|
||||
*/
|
||||
export const sendDiscord = async(
|
||||
subject: string,
|
||||
body: string,
|
||||
): Promise<void> => {
|
||||
await fetch(`${process.env.DISCORD_WEBHOOK_URL ?? ""}?with_components=true`, {
|
||||
body: JSON.stringify({
|
||||
components: [
|
||||
{
|
||||
accent_color: 15_418_782,
|
||||
components: [
|
||||
{
|
||||
content: `# ${subject}`,
|
||||
type: 10,
|
||||
},
|
||||
{
|
||||
divider: true,
|
||||
spacing: 1,
|
||||
type: 14,
|
||||
},
|
||||
{
|
||||
content: body,
|
||||
type: 10,
|
||||
},
|
||||
],
|
||||
spoiler: false,
|
||||
type: 17,
|
||||
},
|
||||
],
|
||||
flags: 32_768,
|
||||
}),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
method: "POST",
|
||||
});
|
||||
};
|
@ -6,6 +6,7 @@
|
||||
|
||||
import fastify from "fastify";
|
||||
import { auth } from "../modules/auth.js";
|
||||
import { sendDiscord } from "../modules/discord.js";
|
||||
import { sendMail } from "../modules/sendMail.js";
|
||||
import { errorSchema } from "../schemas/errorSchema.js";
|
||||
import { logSchema } from "../schemas/logSchema.js";
|
||||
@ -89,6 +90,10 @@ export const instantiateServer = (): void => {
|
||||
}
|
||||
const { application, context, stack, message } = request.body;
|
||||
await sendMail(`[ERROR]: ${context} - ${application}`, `${message}\n\n${stack}`);
|
||||
await sendDiscord(
|
||||
`[ERROR]: ${context} - ${application}`,
|
||||
`${message}\n\n\`\`\`\n${stack}\n\`\`\``,
|
||||
);
|
||||
await response.status(200).send({ success: true });
|
||||
},
|
||||
);
|
||||
|
Reference in New Issue
Block a user