Compare commits

...

4 commits

Author SHA1 Message Date
DC
d27f0349e5
Merge fafa1a78ee into 778363a948 2024-11-11 10:08:57 +00:00
Dorence Deng
778363a948
fix(notification): #5323 fix EditMonitor.vue useToast error (#5333)
Some checks failed
Auto Test / e2e-test (push) Has been cancelled
Auto Test / armv7-simple-test (18, ARMv7) (push) Has been cancelled
Auto Test / armv7-simple-test (20, ARMv7) (push) Has been cancelled
Auto Test / check-linters (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
Merge Conflict Labeler / Labeling (push) Has been cancelled
validate / json-yaml-validate (push) Has been cancelled
validate / validate (push) Has been cancelled
Auto Test / auto-test (18, ARM64) (push) Has been cancelled
Auto Test / auto-test (18, macos-latest) (push) Has been cancelled
Auto Test / auto-test (18, ubuntu-latest) (push) Has been cancelled
Auto Test / auto-test (18, windows-latest) (push) Has been cancelled
Auto Test / auto-test (20, ARM64) (push) Has been cancelled
Auto Test / auto-test (20, macos-latest) (push) Has been cancelled
Auto Test / auto-test (20, ubuntu-latest) (push) Has been cancelled
Auto Test / auto-test (20, windows-latest) (push) Has been cancelled
2024-11-11 11:08:43 +01:00
darkclip
fafa1a78ee use extractAddress() instead of monitorJSON["url"] for better url handling 2024-11-01 14:58:06 +08:00
darkclip
c70ec1ea50 Use template_card instead of text messages for the WeCom notification provider 2024-10-31 01:26:46 +08:00
2 changed files with 70 additions and 14 deletions

View file

@ -12,13 +12,16 @@ class WeCom extends NotificationProvider {
const okMsg = "Sent Successfully.";
try {
let WeComUrl =
"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=" +
notification.weComBotKey;
let config = {
headers: {
"Content-Type": "application/json"
}
"Content-Type": "application/json",
},
};
let body = this.composeMessage(heartbeatJSON, msg);
await axios.post(`https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${notification.weComBotKey}`, body, config);
let body = this.composeMessage(heartbeatJSON, monitorJSON, msg);
await axios.post(WeComUrl, body, config);
return okMsg;
} catch (error) {
this.throwGeneralAxiosError(error);
@ -28,24 +31,77 @@ class WeCom extends NotificationProvider {
/**
* Generate the message to send
* @param {object} heartbeatJSON Heartbeat details (For Up/Down only)
* @param {object} monitorJSON Monitor details
* @param {string} msg General message
* @returns {object} Message
*/
composeMessage(heartbeatJSON, msg) {
let title = "UptimeKuma Message";
if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === UP) {
title = "UptimeKuma Monitor Up";
}
if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === DOWN) {
title = "UptimeKuma Monitor Down";
composeMessage(heartbeatJSON, monitorJSON, msg) {
const address = this.extractAddress(monitorJSON);
if (heartbeatJSON != null) {
const templateCard = {
card_type: "text_notice",
main_title: {
title: this.statusToString(
heartbeatJSON["status"],
monitorJSON["name"]
),
},
sub_title_text: heartbeatJSON["msg"],
horizontal_content_list: [
{
keyname: "Timezone",
value: heartbeatJSON["timezone"],
},
{
keyname: "Time",
value: heartbeatJSON["localDateTime"],
},
],
card_action: {
type: 1,
url: address
? address
: "https://github.com/louislam/uptime-kuma", // both card_action and card_action.url are mandatory
},
};
if (address) {
templateCard["jump_list"] = [
{
type: 1,
url: address,
title: "Monitor URL",
},
];
}
return {
msgtype: "template_card",
template_card: templateCard,
};
}
return {
msgtype: "text",
text: {
content: title + "\n" + msg
}
content: msg,
},
};
}
/**
* Convert status constant to string
* @param {const} status The status constant
* @param {string} monitorName Name of monitor
* @returns {string} Status
*/
statusToString(status, monitorName) {
switch (status) {
case DOWN:
return `🔴 [${monitorName}] DOWN`;
case UP:
return `✅ [${monitorName}] UP`;
default:
return "Notification";
}
}
}
module.exports = WeCom;

View file

@ -1065,7 +1065,7 @@ import { hostNameRegexPattern } from "../util-frontend";
import HiddenInput from "../components/HiddenInput.vue";
import EditMonitorConditions from "../components/EditMonitorConditions.vue";
const toast = useToast;
const toast = useToast();
const pushTokenLength = 32;