mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-27 16:54:04 +00:00
some more tweaking of the card content and notification summary
This commit is contained in:
parent
cc09147b4b
commit
8bd69d78a8
1 changed files with 36 additions and 25 deletions
|
@ -10,13 +10,14 @@ class Teams extends NotificationProvider {
|
||||||
* Generate the message to send
|
* Generate the message to send
|
||||||
* @param {const} status The status constant
|
* @param {const} status The status constant
|
||||||
* @param {string} monitorName Name of monitor
|
* @param {string} monitorName Name of monitor
|
||||||
|
* @param {boolean} withStatusSymbol If the status should be prepended as symbol
|
||||||
* @returns {string} Status message
|
* @returns {string} Status message
|
||||||
*/
|
*/
|
||||||
_statusMessageFactory = (status, monitorName) => {
|
_statusMessageFactory = (status, monitorName, withStatusSymbol) => {
|
||||||
if (status === DOWN) {
|
if (status === DOWN) {
|
||||||
return `[${monitorName}] went down`;
|
return (withStatusSymbol ? "🔴 " : "") + `[${monitorName}] went down`;
|
||||||
} else if (status === UP) {
|
} else if (status === UP) {
|
||||||
return `[${monitorName}] is back online`;
|
return (withStatusSymbol ? "✅ " : "") + `[${monitorName}] is back online`;
|
||||||
}
|
}
|
||||||
return "Notification";
|
return "Notification";
|
||||||
};
|
};
|
||||||
|
@ -39,31 +40,34 @@ class Teams extends NotificationProvider {
|
||||||
/**
|
/**
|
||||||
* Generate payload for notification
|
* Generate payload for notification
|
||||||
* @param {object} args Method arguments
|
* @param {object} args Method arguments
|
||||||
* @param {const} args.status The status of the monitor
|
* @param {object} args.heartbeatJSON Heartbeat details
|
||||||
* @param {string} args.monitorMessage Message to send
|
|
||||||
* @param {string} args.monitorName Name of the monitor affected
|
* @param {string} args.monitorName Name of the monitor affected
|
||||||
* @param {string} args.monitorUrl URL of the monitor affected
|
* @param {string} args.monitorUrl URL of the monitor affected
|
||||||
* @param {string} args.dashboardUrl URL of the dashboard affected
|
* @param {string} args.dashboardUrl URL of the dashboard affected
|
||||||
* @returns {object} Notification payload
|
* @returns {object} Notification payload
|
||||||
*/
|
*/
|
||||||
_notificationPayloadFactory = ({
|
_notificationPayloadFactory = ({
|
||||||
status,
|
heartbeatJSON,
|
||||||
monitorMessage,
|
|
||||||
monitorName,
|
monitorName,
|
||||||
monitorUrl,
|
monitorUrl,
|
||||||
dashboardUrl,
|
dashboardUrl,
|
||||||
}) => {
|
}) => {
|
||||||
const notificationMessage = this._statusMessageFactory(
|
const status = heartbeatJSON.status;
|
||||||
status,
|
|
||||||
monitorName
|
|
||||||
);
|
|
||||||
|
|
||||||
const facts = [];
|
const facts = [];
|
||||||
|
const actions = [];
|
||||||
|
|
||||||
if (monitorMessage) {
|
if (dashboardUrl) {
|
||||||
|
actions.push({
|
||||||
|
"type": "Action.OpenUrl",
|
||||||
|
"title": "Visit Uptime Kuma",
|
||||||
|
"url": dashboardUrl
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (heartbeatJSON?.msg) {
|
||||||
facts.push({
|
facts.push({
|
||||||
title: "Description",
|
title: "Description",
|
||||||
value: monitorMessage,
|
value: heartbeatJSON.msg,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,10 +84,24 @@ class Teams extends NotificationProvider {
|
||||||
// format URL as markdown syntax, to be clickable
|
// format URL as markdown syntax, to be clickable
|
||||||
value: `[${monitorUrl}](${monitorUrl})`,
|
value: `[${monitorUrl}](${monitorUrl})`,
|
||||||
});
|
});
|
||||||
|
actions.push({
|
||||||
|
"type": "Action.OpenUrl",
|
||||||
|
"title": "Visit Monitor URL",
|
||||||
|
"url": monitorUrl
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (heartbeatJSON?.localDateTime) {
|
||||||
|
facts.push({
|
||||||
|
title: "Time",
|
||||||
|
value: heartbeatJSON.localDateTime + (heartbeatJSON.timezone ? ` (${heartbeatJSON.timezone})` : ""),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const payload = {
|
const payload = {
|
||||||
"type": "message",
|
"type": "message",
|
||||||
|
// message with status prefix as notification text
|
||||||
|
"summary": this._statusMessageFactory(status, monitorName, true),
|
||||||
"attachments": [
|
"attachments": [
|
||||||
{
|
{
|
||||||
"contentType": "application/vnd.microsoft.card.adaptive",
|
"contentType": "application/vnd.microsoft.card.adaptive",
|
||||||
|
@ -121,7 +139,7 @@ class Teams extends NotificationProvider {
|
||||||
"type": "TextBlock",
|
"type": "TextBlock",
|
||||||
"size": "Medium",
|
"size": "Medium",
|
||||||
"weight": "Bolder",
|
"weight": "Bolder",
|
||||||
"text": `**${notificationMessage}**`,
|
"text": `**${this._statusMessageFactory(status, monitorName, false)}**`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "TextBlock",
|
"type": "TextBlock",
|
||||||
|
@ -150,16 +168,10 @@ class Teams extends NotificationProvider {
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
if (dashboardUrl) {
|
if (actions) {
|
||||||
payload.attachments[0].content.body.push({
|
payload.attachments[0].content.body.push({
|
||||||
"type": "ActionSet",
|
"type": "ActionSet",
|
||||||
"actions": [
|
"actions": actions,
|
||||||
{
|
|
||||||
"type": "Action.OpenUrl",
|
|
||||||
"title": "Visit Uptime Kuma",
|
|
||||||
"url": dashboardUrl
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,10 +236,9 @@ class Teams extends NotificationProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
const payload = this._notificationPayloadFactory({
|
const payload = this._notificationPayloadFactory({
|
||||||
monitorMessage: heartbeatJSON.msg,
|
heartbeatJSON: heartbeatJSON,
|
||||||
monitorName: monitorJSON.name,
|
monitorName: monitorJSON.name,
|
||||||
monitorUrl: monitorUrl,
|
monitorUrl: monitorUrl,
|
||||||
status: heartbeatJSON.status,
|
|
||||||
dashboardUrl: dashboardUrl,
|
dashboardUrl: dashboardUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue