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
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 @@
*/
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
const okMsg = "Sent Successfully.";

// Convert isAtAll to Boolean

Check failure on line 14 in server/notification-providers/dingding.js

View workflow job for this annotation

GitHub Actions / check-linters

Expected indentation of 8 spaces but found 12
notification.isAtAll = this.convertToBoolean(notification.isAtAll);

Check failure on line 15 in server/notification-providers/dingding.js

View workflow job for this annotation

GitHub Actions / check-linters

Expected indentation of 8 spaces but found 12
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 @@
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,8 +89,14 @@
* Convert status constant to string
* @param {const} status The status constant
* @returns {string} Status
* @returns {boolean} isAtAll
*/

convertToBoolean(value) {

Check failure on line 95 in server/notification-providers/dingding.js

View workflow job for this annotation

GitHub Actions / check-linters

Missing JSDoc comment
return value === "true";
}

statusToString(status) {

Check failure on line 99 in server/notification-providers/dingding.js

View workflow job for this annotation

GitHub Actions / check-linters

Missing JSDoc comment
// TODO: Move to notification-provider.js to avoid repetition in classes
switch (status) {
case DOWN:
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" v-model="$parent.notification.isAtAll" type="checkbox" class="form-check-input">

Check warning on line 10 in src/components/notifications/DingDing.vue

View workflow job for this annotation

GitHub Actions / check-linters

Multiple spaces found before 'v-model'

<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>

Check failure on line 19 in src/components/notifications/DingDing.vue

View workflow job for this annotation

GitHub Actions / check-linters

Newline required at end of file but not found
1 change: 1 addition & 0 deletions src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@
"WebHookUrl": "WebHookUrl",
"SecretKey": "SecretKey",
"For safety, must use secret key": "For safety, must use secret key",
"isAtAll":"Whether @everyone",
"Device Token": "Device Token",
"Platform": "Platform",
"Huawei": "Huawei",
Expand Down
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
Loading