Compare commits

...

7 Commits

Author SHA1 Message Date
Tobias Thiemann
8e968d160e
Merge 939d8c7ffb into 243726b03c 2024-09-29 14:08:20 +00:00
Louis Lam
243726b03c Update to 1.23.14 2024-09-29 21:46:19 +08:00
Tobias Thiemann
939d8c7ffb
Merge pull request #1 from tpai/fix/Teams-Workflow-Webhook
Fix and remove legacy code
2024-09-04 16:15:42 +02:00
tonypai
7ca064f24d Fix and remove legacy code 2024-09-03 03:43:46 +00:00
Tobias Thiemann
5332b3fc9b fix lint issues 2024-07-23 10:56:55 +02:00
Tobias Thiemann
27266f60ba downgrade adaptive-card version to 1.4
downgrade version, otherwise the error "We're sorry, this card couldn't be displayed" will be displayed when using flowbot, which is default
2024-07-23 10:21:54 +02:00
Tobias Thiemann
4daa1ef5ac Backport Teams Adaptive-Templeate
This commit backports the Adaptive-Templeate.
The version of the template uses is from commit 2c31f3a2ff.
2024-07-23 09:09:16 +02:00
2 changed files with 111 additions and 29 deletions

View File

@ -1,6 +1,6 @@
{
"name": "uptime-kuma",
"version": "1.23.13",
"version": "1.23.14",
"license": "MIT",
"repository": {
"type": "git",
@ -42,7 +42,7 @@
"build-docker-nightly-amd64": "docker buildx build -f docker/dockerfile --platform linux/amd64 -t louislam/uptime-kuma:nightly-amd64 --target nightly . --push --progress plain",
"build-docker-pr-test": "docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64 -t louislam/uptime-kuma:pr-test --target pr-test . --push",
"upload-artifacts": "docker buildx build -f docker/dockerfile --platform linux/amd64 -t louislam/uptime-kuma:upload-artifact --build-arg VERSION --build-arg GITHUB_TOKEN --target upload-artifact . --progress plain",
"setup": "git checkout 1.23.13 && npm ci --production && npm run download-dist",
"setup": "git checkout 1.23.14 && npm ci --production && npm run download-dist",
"download-dist": "node extra/download-dist.js",
"mark-as-nightly": "node extra/mark-as-nightly.js",
"reset-password": "node extra/reset-password.js",

View File

@ -35,6 +35,21 @@ class Teams extends NotificationProvider {
return "008cff";
};
/**
* Select the style to use based on status
* @param {const} status The status constant
* @returns {string} Selected style for adaptive cards
*/
_getStyle = (status) => {
if (status === DOWN) {
return "attention";
}
if (status === UP) {
return "good";
}
return "emphasis";
};
/**
* Generate payload for notification
* @param {const} status The status of the monitor
@ -49,48 +64,114 @@ class Teams extends NotificationProvider {
monitorName,
monitorUrl,
}) => {
const notificationMessage = this._statusMessageFactory(
status,
monitorName
);
const facts = [];
const actions = [];
if (monitorMessage) {
facts.push({
title: "Description",
value: monitorMessage,
});
}
if (monitorName) {
facts.push({
name: "Monitor",
title: "Monitor",
value: monitorName,
});
}
if (monitorUrl && monitorUrl !== "https://") {
facts.push({
name: "URL",
value: monitorUrl,
title: "URL",
// format URL as markdown syntax, to be clickable
value: `[${monitorUrl}](${monitorUrl})`,
});
actions.push({
"type": "Action.OpenUrl",
"title": "Visit Monitor URL",
"url": monitorUrl
});
}
return {
"@context": "https://schema.org/extensions",
"@type": "MessageCard",
themeColor: this._getThemeColor(status),
summary: notificationMessage,
sections: [
const payload = {
"type": "message",
// message with status prefix as notification text
"summary": this._statusMessageFactory(status, monitorName),
"attachments": [
{
activityImage:
"https://raw.githubusercontent.com/louislam/uptime-kuma/master/public/icon.png",
activityTitle: "**Uptime Kuma**",
},
{
activityTitle: notificationMessage,
},
{
activityTitle: "**Description**",
text: monitorMessage,
facts,
},
],
"contentType": "application/vnd.microsoft.card.adaptive",
"contentUrl": "",
"content": {
"type": "AdaptiveCard",
"body": [
{
"type": "Container",
"verticalContentAlignment": "Center",
"items": [
{
"type": "ColumnSet",
"style": this._getStyle(status),
"columns": [
{
"type": "Column",
"width": "auto",
"verticalContentAlignment": "Center",
"items": [
{
"type": "Image",
"width": "32px",
"style": "Person",
"url": "https://raw.githubusercontent.com/louislam/uptime-kuma/master/public/icon.png",
"altText": "Uptime Kuma Logo"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"size": "Medium",
"weight": "Bolder",
"text": `**${this._statusMessageFactory(status, monitorName, false)}**`,
},
{
"type": "TextBlock",
"size": "Small",
"weight": "Default",
"text": "Uptime Kuma Alert",
"isSubtle": true,
"spacing": "None"
}
]
}
]
}
]
},
{
"type": "FactSet",
"separator": false,
"facts": facts
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.4"
}
}
]
};
if (actions) {
payload.attachments[0].content.body.push({
"type": "ActionSet",
"actions": actions,
});
}
return payload;
};
/**
@ -148,6 +229,7 @@ class Teams extends NotificationProvider {
});
await this._sendNotification(notification.webhookUrl, payload);
return okMsg;
} catch (error) {
this.throwGeneralAxiosError(error);