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

Added option to @Everyone in DingTalk notification method #4712

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
新增了钉钉通知消息是否 @ 所有人的 选项
  • Loading branch information
凯观生活 authored Apr 26, 2024
commit 56ffca4ef7846e68dd826c15c76e3139a95479b1
15 changes: 14 additions & 1 deletion server/notification-providers/dingding.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ class DingDing extends NotificationProvider {
*/
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
const okMsg = "Sent Successfully.";

// Convert isAtAll to Boolean
notification.isAtAll = this.convertToBoolean(notification.isAtAll);
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"]}`,
},
"at": {
"isAtAll": notification.isAtAll // Here the isAtAll value in the notification object is used
CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved
}
};
if (await this.sendToDingDing(notification, params)) {
Expand All @@ -29,6 +33,9 @@ class DingDing extends NotificationProvider {
msgtype: "text",
text: {
content: msg
},
"at": {
"isAtAll": notification.isAtAll // Here the isAtAll value in the notification object is used
CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved
}
};
if (await this.sendToDingDing(notification, params)) {
Expand Down Expand Up @@ -82,7 +89,13 @@ class DingDing extends NotificationProvider {
* Convert status constant to string
* @param {const} status The status constant
* @returns {string} Status
* @returns {boolean} isAtAll
*/

convertToBoolean(value) {
return value === "true";
}

statusToString(status) {
// TODO: Move to notification-provider.js to avoid repetition in classes
switch (status) {
Expand Down
5 changes: 4 additions & 1 deletion src/components/notifications/DingDing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
<label for="secretKey" class="form-label">{{ $t("SecretKey") }}<span style="color: red;"><sup>*</sup></span></label>
<input id="secretKey" v-model="$parent.notification.secretKey" type="text" class="form-control" required>

<label for="isAtAll" class="form-label">{{ $t("isAtAll") }}<span style="color: red;"><sup>*</sup></span></label>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change this to a selection box with the options Don't mention people, Notify <code>@everyone</code> (see https://vue-i18n.intlify.dev/guide/advanced/component.html)
With a selection box, implemneting things like @userId is possible (=> "future-proof")

<input id="isAtAll" type="checkbox" v-model="$parent.notification.isAtAll" class="form-check-input">

<div class="form-text">
<p>{{ $t("For safety, must use secret key") }}</p>
<i18n-t tag="p" keypath="Read more:">
<a href="https://developers.dingtalk.com/document/robots/custom-robot-access" target="_blank">https://developers.dingtalk.com/document/robots/custom-robot-access</a> <a href="https://open.dingtalk.com/document/robots/customize-robot-security-settings#title-7fs-kgs-36x" target="_blank">https://open.dingtalk.com/document/robots/customize-robot-security-settings#title-7fs-kgs-36x</a>
</i18n-t>
</div>
</div>
</template>
</template>
1 change: 1 addition & 0 deletions src/lang/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@
"WebHookUrl": "钉钉自定义机器人 Webhook 地址",
"SecretKey": "钉钉自定义机器人加签密钥",
"For safety, must use secret key": "出于安全考虑,必须使用加签密钥",
"isAtAll":"是否@所有人",
CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved
"Device Token": "Apple Device Token",
"Platform": "平台",
"Huawei": "华为",
Expand Down