Send webhooks when inactivity notice is created

This commit is contained in:
Regalijan 2024-02-18 17:42:53 -05:00
parent 002cc6bb10
commit c50cc97206
Signed by: regalijan
GPG Key ID: 5D4196DA269EF520

View File

@ -48,6 +48,34 @@ export async function onRequestPost(context: RequestContext) {
.bind(Date.now(), inactivityId, context.data.current_user.id)
.run();
const departmentsToNotify = [];
const { env } = context;
for (const department of departments)
departmentsToNotify.push(env[`${department}_INACTIVITY_WEBHOOK`]);
const webhookPromises = [];
for (const departmentWebhook of departmentsToNotify)
webhookPromises.push(
await fetch(departmentWebhook, {
body: JSON.stringify({
embeds: [
{
title: "Inactivity Notice Submitted",
color: 3756250,
description: `View this notice at https://carcrushers.cc/mod-queue?id=${inactivityId}&type=inactivity`,
},
],
}),
headers: {
"content-type": "application/json",
},
method: "POST",
}),
);
await Promise.allSettled(webhookPromises);
return new Response(null, {
status: 204,
});