mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-02-25 21:15:55 +00:00
Merge ce8f2bffa1
into e9935d7b3b
This commit is contained in:
commit
fb675ba6a7
3 changed files with 132 additions and 7 deletions
|
@ -11,17 +11,23 @@ class DingDing extends NotificationProvider {
|
||||||
*/
|
*/
|
||||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
const okMsg = "Sent Successfully.";
|
const okMsg = "Sent Successfully.";
|
||||||
|
const mentionAll = notification.mentioning === "everyone";
|
||||||
|
const mobileList = notification.mentioning === "specify-mobiles" ? notification.mobileList : [];
|
||||||
|
const userList = notification.mentioning === "specify-users" ? notification.userList : [];
|
||||||
|
const finalList = [ ...mobileList || [], ...userList || [] ];
|
||||||
|
const mentionStr = finalList.length > 0 ? "\n" : "" + finalList.map(item => `@${item}`).join(" ");
|
||||||
try {
|
try {
|
||||||
if (heartbeatJSON != null) {
|
if (heartbeatJSON != null) {
|
||||||
let params = {
|
let params = {
|
||||||
msgtype: "markdown",
|
msgtype: "markdown",
|
||||||
markdown: {
|
markdown: {
|
||||||
title: `[${this.statusToString(heartbeatJSON["status"])}] ${monitorJSON["name"]}`,
|
title: `[${this.statusToString(heartbeatJSON["status"])}] ${monitorJSON["name"]}`,
|
||||||
text: `## [${this.statusToString(heartbeatJSON["status"])}] ${monitorJSON["name"]} \n> ${heartbeatJSON["msg"]}\n> Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`,
|
text: `## [${this.statusToString(heartbeatJSON["status"])}] ${monitorJSON["name"]} \n> ${heartbeatJSON["msg"]}\n> Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}${mentionStr}`,
|
||||||
},
|
},
|
||||||
"at": {
|
at: {
|
||||||
"isAtAll": notification.mentioning === "everyone"
|
isAtAll: mentionAll,
|
||||||
|
atUserIds: userList,
|
||||||
|
atMobiles: mobileList
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (await this.sendToDingDing(notification, params)) {
|
if (await this.sendToDingDing(notification, params)) {
|
||||||
|
@ -31,7 +37,12 @@ class DingDing extends NotificationProvider {
|
||||||
let params = {
|
let params = {
|
||||||
msgtype: "text",
|
msgtype: "text",
|
||||||
text: {
|
text: {
|
||||||
content: msg
|
content: `${msg}${mentionStr}`
|
||||||
|
},
|
||||||
|
at: {
|
||||||
|
isAtAll: mentionAll,
|
||||||
|
atUserIds: userList,
|
||||||
|
atMobiles: mobileList
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (await this.sendToDingDing(notification, params)) {
|
if (await this.sendToDingDing(notification, params)) {
|
||||||
|
|
|
@ -16,22 +16,128 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="mentioning" class="form-label">{{ $t("Mentioning") }}<span style="color: red;"><sup>*</sup></span></label>
|
<label for="mentioning" class="form-label">{{ $t("Mentioning") }}<span style="color: red;"><sup>*</sup></span></label>
|
||||||
<select id="mentioning" v-model="$parent.notification.mentioning" class="form-select" required>
|
<select id="mentioning" v-model="$parent.notification.mentioning" class="form-select" required @change="onMentioningChange">
|
||||||
<option value="nobody">{{ $t("Don't mention people") }}</option>
|
<option value="nobody">{{ $t("Don't mention people") }}</option>
|
||||||
<option value="everyone">{{ $t("Mention group", { group: "@everyone" }) }}</option>
|
<option value="everyone">{{ $t("Mention group", { group: "@everyone" }) }}</option>
|
||||||
|
<option value="specify-mobiles">{{ $t("Mention Mobile List") }}</option>
|
||||||
|
<option value="specify-users">{{ $t("Mention User List") }}</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
<div v-if="$parent.notification.mentioning === 'specify-mobiles'" class="mb-3">
|
||||||
|
<label for="mobileList" class="form-label">{{ $t("Dingtalk Mobile List") }}<span style="color: red;"><sup>*</sup></span></label>
|
||||||
|
<VueMultiselect
|
||||||
|
id="mobileList-select"
|
||||||
|
v-model="$parent.notification.mobileList"
|
||||||
|
:required="$parent.notification.mentioning === 'specify-mobiles'"
|
||||||
|
:placeholder="$t('Enter a list of mobile')"
|
||||||
|
:multiple="true"
|
||||||
|
:options="mobileOpts"
|
||||||
|
:max-height="500"
|
||||||
|
:taggable="true"
|
||||||
|
:show-no-options="false"
|
||||||
|
:close-on-select="false"
|
||||||
|
:clear-on-select="false"
|
||||||
|
:preserve-search="false"
|
||||||
|
:preselect-first="false"
|
||||||
|
@remove="removeMobile"
|
||||||
|
@tag="addMobile"
|
||||||
|
></VueMultiselect>
|
||||||
|
</div>
|
||||||
|
<div v-if="$parent.notification.mentioning === 'specify-users'" class="mb-3">
|
||||||
|
<label for="userList" class="form-label">{{ $t("Dingtalk User List") }}<span style="color: red;"><sup>*</sup></span></label>
|
||||||
|
<VueMultiselect
|
||||||
|
id="userList-select"
|
||||||
|
v-model="$parent.notification.userList"
|
||||||
|
:required="$parent.notification.mentioning === 'specify-users'"
|
||||||
|
:placeholder="$t('Enter a list of userId')"
|
||||||
|
:multiple="true"
|
||||||
|
:options="userIdOpts"
|
||||||
|
:max-height="500"
|
||||||
|
:taggable="true"
|
||||||
|
:show-no-options="false"
|
||||||
|
:close-on-select="false"
|
||||||
|
:clear-on-select="true"
|
||||||
|
:preserve-search="false"
|
||||||
|
:preselect-first="false"
|
||||||
|
@remove="removeUser"
|
||||||
|
@tag="addUser"
|
||||||
|
></VueMultiselect>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import HiddenInput from "../HiddenInput.vue";
|
import HiddenInput from "../HiddenInput.vue";
|
||||||
|
import VueMultiselect from "vue-multiselect";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: { HiddenInput },
|
components: {
|
||||||
|
HiddenInput,
|
||||||
|
VueMultiselect
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
mobileOpts: [],
|
||||||
|
userIdOpts: [],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
if (typeof this.$parent.notification.mentioning === "undefined") {
|
if (typeof this.$parent.notification.mentioning === "undefined") {
|
||||||
this.$parent.notification.mentioning = "nobody";
|
this.$parent.notification.mentioning = "nobody";
|
||||||
}
|
}
|
||||||
|
if (typeof this.$parent.notification.mobileList === "undefined") {
|
||||||
|
this.$parent.notification.mobileList = [];
|
||||||
|
} else {
|
||||||
|
this.mobileOpts = this.$parent.notification.mobileList;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof this.$parent.notification.userList === "undefined") {
|
||||||
|
this.$parent.notification.userList = [];
|
||||||
|
} else {
|
||||||
|
this.userIdOpts = this.$parent.notification.userList;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onMentioningChange(e) {
|
||||||
|
if (e.target.value === "specify-mobiles") {
|
||||||
|
this.$parent.notification.userList = [];
|
||||||
|
} else if (e.target.value === "specify-users") {
|
||||||
|
this.$parent.notification.mobileList = [];
|
||||||
|
} else {
|
||||||
|
this.$parent.notification.userList = [];
|
||||||
|
this.$parent.notification.mobileList = [];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
addMobile(mobile) {
|
||||||
|
const trimmedMobile = mobile.trim();
|
||||||
|
const chinaMobileRegex = /^1[3-9]\d{9}$/;
|
||||||
|
if (!chinaMobileRegex.test(trimmedMobile)) {
|
||||||
|
this.$root.toastError(this.$t("Invalid mobile", { "mobile": trimmedMobile }));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.mobileOpts.push(mobile);
|
||||||
|
},
|
||||||
|
removeMobile(mobile) {
|
||||||
|
const idx = this.mobileOpts.indexOf(mobile);
|
||||||
|
if (idx > -1) {
|
||||||
|
this.mobileOpts.splice(idx, 1);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
addUser(userId) {
|
||||||
|
const trimmedUserId = userId.trim();
|
||||||
|
const userIdRegex = /^[a-zA-Z0-9]+$/;
|
||||||
|
if (!userIdRegex.test(trimmedUserId)) {
|
||||||
|
this.$root.toastError(this.$t("Invalid userId", { "userId": trimmedUserId }));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.userIdOpts.push(trimmedUserId);
|
||||||
|
},
|
||||||
|
removeUser(userId) {
|
||||||
|
const idx = this.userIdOpts.indexOf(userId);
|
||||||
|
if (idx > -1) {
|
||||||
|
this.userIdOpts.splice(idx, 1);
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -690,6 +690,14 @@
|
||||||
"Mentioning": "Mentioning",
|
"Mentioning": "Mentioning",
|
||||||
"Don't mention people": "Don't mention people",
|
"Don't mention people": "Don't mention people",
|
||||||
"Mention group": "Mention {group}",
|
"Mention group": "Mention {group}",
|
||||||
|
"Mention Mobile List": "Mention mobile list",
|
||||||
|
"Mention User List": "Mention user id list",
|
||||||
|
"Dingtalk Mobile List": "Mobile list",
|
||||||
|
"Dingtalk User List": "User ID list",
|
||||||
|
"Enter a list of userId": "Enter a list of userId",
|
||||||
|
"Enter a list of mobile": "Enter a list of mobile",
|
||||||
|
"Invalid mobile": "Invalid mobile [{mobile}]",
|
||||||
|
"Invalid userId": "Invalid userId [{userId}]",
|
||||||
"Device Token": "Device Token",
|
"Device Token": "Device Token",
|
||||||
"Platform": "Platform",
|
"Platform": "Platform",
|
||||||
"Huawei": "Huawei",
|
"Huawei": "Huawei",
|
||||||
|
|
Loading…
Add table
Reference in a new issue