Compare commits

...

4 commits

Author SHA1 Message Date
DC
103da39cb5
Merge fafa1a78ee into 6899603eb7 2024-11-09 15:30:21 +00:00
Abhigyan Mohanta
6899603eb7
fix #5314 Email Address Friendly Name Error (#5318)
Some checks failed
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 / 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
Auto Test / e2e-test (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-09 23:30:08 +08: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 73 additions and 17 deletions

View file

@ -12,13 +12,16 @@ class WeCom extends NotificationProvider {
const okMsg = "Sent Successfully."; const okMsg = "Sent Successfully.";
try { try {
let WeComUrl =
"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=" +
notification.weComBotKey;
let config = { let config = {
headers: { headers: {
"Content-Type": "application/json" "Content-Type": "application/json",
} },
}; };
let body = this.composeMessage(heartbeatJSON, msg); let body = this.composeMessage(heartbeatJSON, monitorJSON, msg);
await axios.post(`https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${notification.weComBotKey}`, body, config); await axios.post(WeComUrl, body, config);
return okMsg; return okMsg;
} catch (error) { } catch (error) {
this.throwGeneralAxiosError(error); this.throwGeneralAxiosError(error);
@ -28,24 +31,77 @@ class WeCom extends NotificationProvider {
/** /**
* Generate the message to send * Generate the message to send
* @param {object} heartbeatJSON Heartbeat details (For Up/Down only) * @param {object} heartbeatJSON Heartbeat details (For Up/Down only)
* @param {object} monitorJSON Monitor details
* @param {string} msg General message * @param {string} msg General message
* @returns {object} Message * @returns {object} Message
*/ */
composeMessage(heartbeatJSON, msg) { composeMessage(heartbeatJSON, monitorJSON, msg) {
let title = "UptimeKuma Message"; const address = this.extractAddress(monitorJSON);
if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === UP) { if (heartbeatJSON != null) {
title = "UptimeKuma Monitor Up"; const templateCard = {
} card_type: "text_notice",
if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === DOWN) { main_title: {
title = "UptimeKuma Monitor Down"; 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 { return {
msgtype: "text", msgtype: "text",
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; module.exports = WeCom;

View file

@ -5,20 +5,20 @@
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="sendgrid-from-email" class="form-label">{{ $t("From Email") }}</label> <label for="sendgrid-from-email" class="form-label">{{ $t("From Email") }}</label>
<input id="sendgrid-from-email" v-model="$parent.notification.sendgridFromEmail" type="email" class="form-control" required> <input id="sendgrid-from-email" v-model="$parent.notification.sendgridFromEmail" type="text" class="form-control" required>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="sendgrid-to-email" class="form-label">{{ $t("To Email") }}</label> <label for="sendgrid-to-email" class="form-label">{{ $t("To Email") }}</label>
<input id="sendgrid-to-email" v-model="$parent.notification.sendgridToEmail" type="email" class="form-control" required> <input id="sendgrid-to-email" v-model="$parent.notification.sendgridToEmail" type="text" class="form-control" required>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="sendgrid-cc-email" class="form-label">{{ $t("smtpCC") }}</label> <label for="sendgrid-cc-email" class="form-label">{{ $t("smtpCC") }}</label>
<input id="sendgrid-cc-email" v-model="$parent.notification.sendgridCcEmail" type="email" class="form-control"> <input id="sendgrid-cc-email" v-model="$parent.notification.sendgridCcEmail" type="text" class="form-control">
<div class="form-text">{{ $t("Separate multiple email addresses with commas") }}</div> <div class="form-text">{{ $t("Separate multiple email addresses with commas") }}</div>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="sendgrid-bcc-email" class="form-label">{{ $t("smtpBCC") }}</label> <label for="sendgrid-bcc-email" class="form-label">{{ $t("smtpBCC") }}</label>
<input id="sendgrid-bcc-email" v-model="$parent.notification.sendgridBccEmail" type="email" class="form-control"> <input id="sendgrid-bcc-email" v-model="$parent.notification.sendgridBccEmail" type="text" class="form-control">
<small class="form-text text-muted">{{ $t("Separate multiple email addresses with commas") }}</small> <small class="form-text text-muted">{{ $t("Separate multiple email addresses with commas") }}</small>
</div> </div>
<div class="mb-3"> <div class="mb-3">