Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Send webhooks when inactivity notice is created
  • Loading branch information
regalijan committed Feb 18, 2024
1 parent 002cc6b commit c50cc97
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions functions/api/inactivity/new.ts
Expand Up @@ -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,
});
Expand Down

0 comments on commit c50cc97

Please sign in to comment.