Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @People feature in DingTalk notifications #5464

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions server/notification-providers/dingding.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@ class DingDing extends NotificationProvider {
*/
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
const okMsg = "Sent Successfully.";

const mentionAll = notification.mentioning === "everyone";
const mobileList = notification.mentioning === "specify-mobiles" ? notification.mobileList.split(",") : [];
const userList = notification.mentioning === "specify-users" ? notification.userList.split(",") : [];
const mentionStr = [ ...mobileList || [], ...userList || [] ].map(item => `@${item}`).join(" ");
boomboomxx marked this conversation as resolved.
Show resolved Hide resolved
try {
if (heartbeatJSON != null) {
let params = {
msgtype: "markdown",
markdown: {
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"]}${"\n\n" + mentionStr}`,
CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved
},
"at": {
"isAtAll": notification.mentioning === "everyone"
at: {
isAtAll: mentionAll,
atUserIds: userList,
atMobiles: mobileList
}
};
if (await this.sendToDingDing(notification, params)) {
Expand All @@ -31,7 +36,12 @@ class DingDing extends NotificationProvider {
let params = {
msgtype: "text",
text: {
content: msg
content: `${msg}${"\n" + mentionStr}`
},
at: {
isAtAll: mentionAll,
atUserIds: userList,
atMobiles: mobileList
}
};
if (await this.sendToDingDing(notification, params)) {
Expand Down
10 changes: 10 additions & 0 deletions src/components/notifications/DingDing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,18 @@
<select id="mentioning" v-model="$parent.notification.mentioning" class="form-select" required>
<option value="nobody">{{ $t("Don't mention people") }}</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>
</div>
<div v-if="$parent.notification.mentioning === 'specify-mobiles'" class="mb-3">
boomboomxx marked this conversation as resolved.
Show resolved Hide resolved
<label for="mobileList" class="form-label">{{ $t("Dingtalk Mobile List") }}<span style="color: red;"><sup>*</sup></span></label>
<input id="mobileList" v-model="$parent.notification.mobileList" type="list" class="form-control" required>
</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>
<input id="userList" v-model="$parent.notification.userList" type="list" class="form-control" required>
</div>
</template>

<script lang="ts">
Expand Down
4 changes: 4 additions & 0 deletions src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,10 @@
"Mentioning": "Mentioning",
"Don't mention people": "Don't mention people",
"Mention group": "Mention {group}",
"Mention Mobile List": "Mention mobile list",
"Mention User List": "Mention user ID List",
"Dingtalk Mobile List": "Mobile List (use comma separator)",
"Dingtalk User List": "User List (use comma separator)",
"Device Token": "Device Token",
"Platform": "Platform",
"Huawei": "Huawei",
Expand Down
Loading