Merge pull request #1 from tpai/fix/Teams-Workflow-Webhook

Fix and remove legacy code
This commit is contained in:
Tobias Thiemann 2024-09-04 16:15:42 +02:00 committed by GitHub
commit 939d8c7ffb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -94,17 +94,10 @@ class Teams extends NotificationProvider {
});
}
// if (heartbeatJSON?.localDateTime) {
// facts.push({
// title: "Time",
// value: heartbeatJSON.localDateTime + (heartbeatJSON.timezone ? ` (${heartbeatJSON.timezone})` : ""),
// });
// }
const payload = {
"type": "message",
// message with status prefix as notification text
"summary": this._statusMessageFactory(status, monitorName, true),
"summary": this._statusMessageFactory(status, monitorName),
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
@ -181,64 +174,6 @@ class Teams extends NotificationProvider {
return payload;
};
/**
* Generate payload for notification
* @param {const} status The status of the monitor
* @param {string} monitorMessage Message to send
* @param {string} monitorName Name of monitor affected
* @param {string} monitorUrl URL of monitor affected
* @returns {Object}
*/
_notificationPayloadFactoryLegacy = ({
status,
monitorMessage,
monitorName,
monitorUrl,
}) => {
const notificationMessage = this._statusMessageFactory(
status,
monitorName
);
const facts = [];
if (monitorName) {
facts.push({
name: "Monitor",
value: monitorName,
});
}
if (monitorUrl && monitorUrl !== "https://") {
facts.push({
name: "URL",
value: monitorUrl,
});
}
return {
"@context": "https://schema.org/extensions",
"@type": "MessageCard",
themeColor: this._getThemeColor(status),
summary: notificationMessage,
sections: [
{
activityImage:
"https://raw.githubusercontent.com/louislam/uptime-kuma/master/public/icon.png",
activityTitle: "**Uptime Kuma**",
},
{
activityTitle: notificationMessage,
},
{
activityTitle: "**Description**",
text: monitorMessage,
facts,
},
],
};
};
/**
* Send the notification
* @param {string} webhookUrl URL to send the request to
@ -286,25 +221,14 @@ class Teams extends NotificationProvider {
break;
}
if (notification.webhookUrl.includes("azure.com")) {
const payload = this._notificationPayloadFactory({
monitorMessage: heartbeatJSON.msg,
monitorName: monitorJSON.name,
monitorUrl: url,
status: heartbeatJSON.status,
});
const payload = this._notificationPayloadFactory({
monitorMessage: heartbeatJSON.msg,
monitorName: monitorJSON.name,
monitorUrl: url,
status: heartbeatJSON.status,
});
await this._sendNotification(notification.webhookUrl, payload);
} else {
const payload = this._notificationPayloadFactoryLegacy({
monitorMessage: heartbeatJSON.msg,
monitorName: monitorJSON.name,
monitorUrl: url,
status: heartbeatJSON.status,
});
await this._sendNotification(notification.webhookUrl, payload);
}
await this._sendNotification(notification.webhookUrl, payload);
return okMsg;
} catch (error) {