From 7add28ebd98e9fac584c0c131f6c0dd07d73a55b Mon Sep 17 00:00:00 2001 From: xx Date: Sat, 21 Dec 2024 14:42:34 +0800 Subject: [PATCH] feat: improve dingtalk webhook mention add mention specify --- server/notification-providers/dingding.js | 24 ++++++++++++++++++----- src/components/notifications/DingDing.vue | 10 ++++++++++ src/lang/en.json | 4 ++++ src/lang/zh-CN.json | 4 ++++ src/lang/zh-HK.json | 8 +++++++- src/lang/zh-TW.json | 4 ++++ 6 files changed, 48 insertions(+), 6 deletions(-) diff --git a/server/notification-providers/dingding.js b/server/notification-providers/dingding.js index c66f270a7..795018700 100644 --- a/server/notification-providers/dingding.js +++ b/server/notification-providers/dingding.js @@ -11,17 +11,26 @@ 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(" ") + console.log('mobileList: ',mobileList) + console.log('userList: ',userList) + console.log('mentionStr: ',mentionStr) try { if (heartbeatJSON != null) { + notification.mobileList 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}`, }, - "at": { - "isAtAll": notification.mentioning === "everyone" + at: { + isAtAll: mentionAll, + atUserIds: userList, + atMobiles: mobileList } }; if (await this.sendToDingDing(notification, params)) { @@ -31,7 +40,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)) { diff --git a/src/components/notifications/DingDing.vue b/src/components/notifications/DingDing.vue index 710677fd7..3ed974d6e 100644 --- a/src/components/notifications/DingDing.vue +++ b/src/components/notifications/DingDing.vue @@ -19,8 +19,18 @@ +
+ + +
+
+ + +