Skip to content

Commit

Permalink
Update backend to get teams webhook url from ID
Browse files Browse the repository at this point in the history
  • Loading branch information
FancMa01 committed Feb 7, 2024
1 parent 2392c3a commit ba07aa3
Showing 1 changed file with 39 additions and 31 deletions.
70 changes: 39 additions & 31 deletions server/jobs/orbitMegaphone.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const sql = require("mssql");
const models = require("../models");
const integrations = models.integrations;
const orbitBuilds = models.orbitBuilds;
const teamsWebhooks = models.teams_hook;
const monitoring_notifications = models.monitoring_notifications;
const notificationTemplate = require("./messageCards/notificationTemplate");
const { notify } = require("../routes/notifications/email-notification");
Expand Down Expand Up @@ -120,37 +121,44 @@ const dbConfig = {
}

// //build and send Teams notification
if (integration.metaData.notificationWebhooks) {
let facts = [
{ name: newBuild.name },
{ Status: newBuild.metaData.status },
{ "Sub Status": newBuild.metaData.subStatus },
{ "Last Run": newBuild.metaData.lastRun },
{ WorkUnit: newBuild.metaData.workunit },
];
let title = "Orbit Build Detectd With Megaphone Status";
notification_id = uuidv4();
const cardBody = notificationTemplate.orbitBuildMessageCard(
title,
facts,
notification_id
);

await axios.post(
integration.metaData.notificationWebhooks,
JSON.parse(cardBody)
);

sentNotifications.push({
id: notification_id,
status: "notified",
notifiedTo: integration.metaData.notificationWebhooks,
notification_channel: "msTeams",
application_id,
notification_reason: "Megaphone Substatus",
monitoring_id: newBuild.id,
monitoring_type: "orbit",
});
if (integration?.metaData?.notificationWebhooks) {
//get the teams webhooks by the ID's in the webhooks
for (let hook of integration.metaData.notificationWebhooks) {
let teamsHook = await teamsWebhooks.findOne({
where: {
id: hook,
},
raw: true,
});

let facts = [
{ name: newBuild.name },
{ Status: newBuild.metaData.status },
{ "Sub Status": newBuild.metaData.subStatus },
{ "Last Run": newBuild.metaData.lastRun },
{ WorkUnit: newBuild.metaData.workunit },
];
let title = "Orbit Build Detectd With Megaphone Status";
notification_id = uuidv4();
const cardBody = notificationTemplate.orbitBuildMessageCard(
title,
facts,
notification_id
);

await axios.post(teamsHook.url, JSON.parse(cardBody));

sentNotifications.push({
id: notification_id,
status: "notified",
notifiedTo: teamsHook.url,
notification_channel: "msTeams",
application_id,
notification_reason: "Megaphone Substatus",
monitoring_id: newBuild.id,
monitoring_type: "orbit",
});
}
}
} else {
//if it does exist, update the "final status metadata"
Expand Down

0 comments on commit ba07aa3

Please sign in to comment.