MS Teams integrations
This commit is contained in:
@@ -2,6 +2,7 @@ const { all, audit, now, one, run } = require('../db');
|
||||
const { getConfig, sendMail } = require('./notifications');
|
||||
const { deliverAlerts } = require('./webhooks');
|
||||
const servicenow = require('./servicenow');
|
||||
const teams = require('./teams');
|
||||
const { pmAlertCandidates } = require('./pm');
|
||||
|
||||
function todayStr() {
|
||||
@@ -171,10 +172,12 @@ async function runAlertCycle(userId) {
|
||||
const result = { created: created.length, emailed: false, webhooked: false };
|
||||
|
||||
const snCfg = servicenow.getConfig();
|
||||
const teamsCfg = teams.getConfig();
|
||||
const emailReady = cfg.enabled && cfg.host && cfg.recipients.length;
|
||||
const webhookReady = cfg.webhookEnabled && cfg.webhookUrl;
|
||||
const ticketReady = snCfg.ticketEnabled && snCfg.autoTicket && snCfg.instanceUrl;
|
||||
if (!emailReady && !webhookReady && !ticketReady) return result;
|
||||
const teamsReady = teamsCfg.enabled && teamsCfg.webhookUrl;
|
||||
if (!emailReady && !webhookReady && !ticketReady && !teamsReady) return result;
|
||||
|
||||
const pending = all(
|
||||
`SELECT al.*, a.asset_id AS asset_code
|
||||
@@ -205,6 +208,13 @@ async function runAlertCycle(userId) {
|
||||
result.ticketed = tickets.created;
|
||||
}
|
||||
|
||||
if (teamsReady) {
|
||||
const teamsDelivery = await teams.deliverAlerts(pending);
|
||||
result.teamsPosted = teamsDelivery.attempted;
|
||||
result.teamsDelivered = teamsDelivery.delivered;
|
||||
result.teamsFailed = teamsDelivery.failed;
|
||||
}
|
||||
|
||||
const ts = now();
|
||||
for (const alert of pending) run('UPDATE alerts SET notified_at = ? WHERE id = ?', [ts, alert.id]);
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user