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

[improve]WeCom app supports sending to specific users, departments, tags #2220

Merged
merged 24 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4a96c02
[remove]Remove optional comments.
zqr10159 Apr 23, 2024
1f6614d
[remove]Remove optional comments.
zqr10159 Apr 23, 2024
f4943e9
Merge branch 'master' of github.com:dromara/hertzbeat
zqr10159 Apr 23, 2024
47dbe2f
Merge branch 'master' of github.com:dromara/hertzbeat
zqr10159 Apr 24, 2024
26c3a80
Merge branch 'master' of github.com:dromara/hertzbeat
zqr10159 Apr 25, 2024
7351a03
Merge branch 'master' of github.com:dromara/hertzbeat
zqr10159 Apr 28, 2024
1cb919a
Merge branch 'master' of github.com:dromara/hertzbeat
zqr10159 Apr 29, 2024
ccbc215
Merge branch 'master' of github.com:dromara/hertzbeat
zqr10159 May 7, 2024
641ba47
Merge branch 'master' of github.com:dromara/hertzbeat
zqr10159 May 9, 2024
2defaec
Merge branch 'master' of github.com:dromara/hertzbeat
zqr10159 May 10, 2024
918073d
Merge branch 'master' of github.com:dromara/hertzbeat
zqr10159 May 11, 2024
55d8dfd
Merge branch 'master' of github.com:dromara/hertzbeat
zqr10159 May 14, 2024
ec1c041
Merge branch 'master' of github.com:dromara/hertzbeat
zqr10159 May 18, 2024
ee32a89
Merge branch 'master' of github.com:dromara/hertzbeat
zqr10159 Jun 1, 2024
7a74f80
Merge branch 'master' of github.com:apache/hertzbeat
zqr10159 Jun 11, 2024
9c5ea20
[doc]HertzBeat 1.6.0 Upgrade Guide.
zqr10159 Jun 11, 2024
b0fdd5e
Merge branch 'master' of github.com:apache/hertzbeat
zqr10159 Jun 18, 2024
dbbbc04
Merge branch 'master' of github.com:apache/hertzbeat
zqr10159 Jul 2, 2024
86f40e5
Merge branch 'master' of github.com:apache/hertzbeat
zqr10159 Jul 3, 2024
0d4ff33
Merge branch 'master' of github.com:apache/hertzbeat
zqr10159 Jul 5, 2024
d0cb9f8
Merge branch 'master' of github.com:apache/hertzbeat
zqr10159 Jul 5, 2024
a2af194
[refactor] Rename WeChatApp to WeComApp and update related configurat…
zqr10159 Jul 5, 2024
d13c486
Merge branch 'master' into Enterprise-WeChat-application
zqr10159 Jul 5, 2024
3658f4c
Merge branch 'master' into Enterprise-WeChat-application
tomsun28 Jul 5, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ public class NoticeReceiver {
example = "oUydwn92ey0lnuY02MixNa57eNK-20dJn5NEOG-u2uE", accessMode = READ_WRITE)
private String appSecret;

@Schema(title = "Enterprise weChat party id: The notification method is valid for Enterprise WeChat app message",
description = "Enterprise weChat party id: The notification method is valid for Enterprise WeChat app message",
example = "779294123", accessMode = READ_WRITE)
private String partyId;

@Schema(title = "Enterprise weChat tag id: The notification method is valid for Enterprise WeChat app message",
description = "Enterprise weChat tag id: The notification method is valid for Enterprise WeChat app message",
example = "779294123", accessMode = READ_WRITE)
private String tagId;

@Schema(title = "Discord channel id: The notification method is valid for Discord",
description = "Discord channel id: The notification method is valid for Discord",
example = "1065303416030642266", accessMode = READ_WRITE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
@Component
@RequiredArgsConstructor
@Slf4j
public class WeWorkAppAlertNotifyHandlerImpl extends AbstractAlertNotifyHandlerImpl {
public class WeComAppAlertNotifyHandlerImpl extends AbstractAlertNotifyHandlerImpl {

/**
* send weChat app message url
Expand All @@ -66,19 +66,41 @@ public void send(NoticeReceiver receiver, NoticeTemplate noticeTemplate, Alert a
String corpId = receiver.getCorpId();
Integer agentId = receiver.getAgentId();
String appSecret = receiver.getAppSecret();
String userId = receiver.getUserId();
String partyId = receiver.getPartyId();
String tagId = receiver.getTagId();


try {
ResponseEntity<WeChatAppReq> entityResponse = restTemplate.getForEntity(String.format(SECRET_URL, corpId, appSecret), WeChatAppReq.class);
if (Objects.nonNull(entityResponse.getBody())) {
String accessToken = entityResponse.getBody().getAccessToken();
WeChatAppDTO.MarkdownDTO markdown = new WeChatAppDTO.MarkdownDTO();
markdown.setContent(renderContent(noticeTemplate, alert));
WeChatAppDTO weChatAppDTO = WeChatAppDTO.builder()
.toUser(DEFAULT_ALL)
WeChatAppDTO.WeChatAppDTOBuilder weChatAppDTOBuilder = WeChatAppDTO.builder()
.msgType(WeChatAppDTO.MARKDOWN)
.markdown(markdown)
.agentId(agentId)
.build();
.agentId(agentId);
boolean hasUserId = receiver.getUserId() != null;
boolean hasPartyId = receiver.getPartyId() != null;
boolean hasTagId = receiver.getTagId() != null;

if (hasUserId) {
weChatAppDTOBuilder.toUser(userId);
}
if (hasPartyId) {
weChatAppDTOBuilder.toParty(partyId);
}
if (hasTagId) {
weChatAppDTOBuilder.toTag(tagId);
}

if (!hasUserId && !hasPartyId && !hasTagId) {
weChatAppDTOBuilder.toUser(DEFAULT_ALL);
}

WeChatAppDTO weChatAppDTO = weChatAppDTOBuilder.build();

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<WeChatAppDTO> weChatAppEntity = new HttpEntity<>(weChatAppDTO, headers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
@Component
@RequiredArgsConstructor
@Slf4j
final class WeWorkRobotAlertNotifyHandlerImpl extends AbstractAlertNotifyHandlerImpl {
final class WeComRobotAlertNotifyHandlerImpl extends AbstractAlertNotifyHandlerImpl {

@Override
public void send(NoticeReceiver receiver, NoticeTemplate noticeTemplate, Alert alert) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
public class WeChatAppAlertNotifyHandlerImplTest extends AbstractSpringIntegrationTest {

@Resource
private WeWorkAppAlertNotifyHandlerImpl weChatAppAlertNotifyHandler;
private WeComAppAlertNotifyHandlerImpl weChatAppAlertNotifyHandler;

@Test
public void send() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
import org.springframework.util.StringUtils;

/**
* Test case for {@link WeWorkRobotAlertNotifyHandlerImpl}
* Test case for {@link WeComRobotAlertNotifyHandlerImpl}
*/
@Slf4j
class WeWorkRobotAlertNotifyHandlerImplTest extends AbstractSpringIntegrationTest {
class WeComRobotAlertNotifyHandlerImplTest extends AbstractSpringIntegrationTest {

@Resource
private WeWorkRobotAlertNotifyHandlerImpl weWorkRobotAlertNotifyHandler;
private WeComRobotAlertNotifyHandlerImpl weWorkRobotAlertNotifyHandler;

@Test
void send() {
Expand Down
2 changes: 2 additions & 0 deletions web-app/src/app/pojo/NoticeReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export class NoticeReceiver {
corpId!: string;
agentId!: number;
appSecret!: string;
partyId!: string;
tagId!: string;
smnAk!: string;
smnSk!: string;
smnProjectId!: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
</nz-tag>
<nz-tag *ngIf="data.type == 4" nzColor="orange">
<i nz-icon nzTheme="outline" nzType="notification"></i>
<span>{{ 'alert.notice.type.wework' | i18n }}</span>
<span>{{ 'alert.notice.type.WeCom-robot' | i18n }}</span>
</nz-tag>
<nz-tag *ngIf="data.type == 5" nzColor="orange">
<i nz-icon nzTheme="outline" nzType="notification"></i>
Expand All @@ -99,7 +99,7 @@
</nz-tag>
<nz-tag *ngIf="data.type == 10" nzColor="orange">
<i nz-icon nzTheme="outline" nzType="notification"></i>
<span>{{ 'alert.notice.type.weChatApp' | i18n }}</span>
<span>{{ 'alert.notice.type.WeComApp' | i18n }}</span>
</nz-tag>
<nz-tag *ngIf="data.type == 11" nzColor="orange">
<i nz-icon nzTheme="outline" nzType="notification"></i>
Expand Down Expand Up @@ -282,7 +282,7 @@
<span>{{ 'alert.notice.type.wechat' | i18n }}</span>
</nz-tag>
<nz-tag *ngIf="data.type == 4" nzColor="orange">
<span>{{ 'alert.notice.type.wework' | i18n }}</span>
<span>{{ 'alert.notice.type.WeCom-robot' | i18n }}</span>
</nz-tag>
<nz-tag *ngIf="data.type == 5" nzColor="orange">
<span>{{ 'alert.notice.type.ding' | i18n }}</span>
Expand All @@ -300,7 +300,7 @@
<span>{{ 'alert.notice.type.discord' | i18n }}</span>
</nz-tag>
<nz-tag *ngIf="data.type == 10" nzColor="orange">
<span>{{ 'alert.notice.type.weChatApp' | i18n }}</span>
<span>{{ 'alert.notice.type.WeComApp' | i18n }}</span>
</nz-tag>
<nz-tag *ngIf="data.type == 11" nzColor="orange">
<span>{{ 'alert.notice.type.smn' | i18n }}</span>
Expand Down Expand Up @@ -539,11 +539,11 @@
<nz-option [nzValue]="2" nzLabel="WebHook"></nz-option>
<nz-option [nzLabel]="'alert.notice.type.discord' | i18n" [nzValue]="9"></nz-option>
<nz-option [nzLabel]="'alert.notice.type.slack' | i18n" [nzValue]="8"></nz-option>
<nz-option [nzLabel]="'alert.notice.type.wework' | i18n" [nzValue]="4"></nz-option>
<nz-option [nzLabel]="'alert.notice.type.WeCom-robot' | i18n" [nzValue]="4"></nz-option>
<nz-option [nzLabel]="'alert.notice.type.ding' | i18n" [nzValue]="5"></nz-option>
<nz-option [nzLabel]="'alert.notice.type.fei-shu' | i18n" [nzValue]="6"></nz-option>
<nz-option [nzLabel]="'alert.notice.type.telegram-bot' | i18n" [nzValue]="7"></nz-option>
<nz-option [nzLabel]="'alert.notice.type.weChatApp' | i18n" [nzValue]="10"></nz-option>
<nz-option [nzLabel]="'alert.notice.type.WeComApp' | i18n" [nzValue]="10"></nz-option>
<nz-option [nzLabel]="'alert.notice.type.smn' | i18n" [nzValue]="11"></nz-option>
<nz-option [nzLabel]="'alert.notice.type.serverchan' | i18n" [nzValue]="12"></nz-option>
<nz-option [nzLabel]="'alert.notice.type.gotify' | i18n" [nzValue]="13"></nz-option>
Expand Down Expand Up @@ -578,7 +578,7 @@
</nz-form-item>
<nz-form-item *ngIf="receiver.type === 4">
<nz-form-label [nzSpan]="7" nzFor="wechatId" [nzRequired]="receiver.type === 4">{{
'alert.notice.type.wework-key' | i18n
'alert.notice.type.WeCom-robot-key' | i18n
}}</nz-form-label>
<nz-form-control [nzSpan]="12" [nzErrorTip]="'validation.required' | i18n">
<input
Expand Down Expand Up @@ -693,28 +693,55 @@
</nz-form-item>
<nz-form-item *ngIf="receiver.type === 10">
<nz-form-label [nzRequired]="receiver.type === 10" [nzSpan]="7" nzFor="corpId">
{{ 'alert.notice.type.weChatApp-corpId' | i18n }}
{{ 'alert.notice.type.WeComApp-corpId' | i18n }}
</nz-form-label>
<nz-form-control [nzErrorTip]="'validation.required' | i18n" [nzSpan]="12">
<input [(ngModel)]="receiver.corpId" [required]="receiver.type === 10" name="corpId" nz-input type="text" />
</nz-form-control>
</nz-form-item>
<nz-form-item *ngIf="receiver.type === 10">
<nz-form-label [nzRequired]="receiver.type === 10" [nzSpan]="7" nzFor="agentId">
{{ 'alert.notice.type.weChatApp-agentId' | i18n }}
{{ 'alert.notice.type.WeComApp-agentId' | i18n }}
</nz-form-label>
<nz-form-control [nzErrorTip]="'validation.required' | i18n" [nzSpan]="12">
<input [(ngModel)]="receiver.agentId" [required]="receiver.type === 10" name="agentId" nz-input type="text" />
</nz-form-control>
</nz-form-item>
<nz-form-item *ngIf="receiver.type === 10">
<nz-form-label [nzRequired]="receiver.type === 10" [nzSpan]="7" nzFor="appSecret">
{{ 'alert.notice.type.weChatApp-appSecret' | i18n }}
{{ 'alert.notice.type.WeComApp-appSecret' | i18n }}
</nz-form-label>
<nz-form-control [nzErrorTip]="'validation.required' | i18n" [nzSpan]="12">
<input [(ngModel)]="receiver.appSecret" [required]="receiver.type === 10" name="appSecret" nz-input type="text" />
</nz-form-control>
</nz-form-item>
<nz-form-item *ngIf="receiver.type === 10">
<nz-form-label [nzSpan]="7" nzFor="userId">
{{ 'alert.notice.type.WeComApp-userId' | i18n }}
</nz-form-label>
<nz-form-control [nzSpan]="12">
<input [(ngModel)]="receiver.userId" name="userId" nz-input type="text" />
</nz-form-control>
</nz-form-item>

<nz-form-item *ngIf="receiver.type === 10">
<nz-form-label [nzSpan]="7" nzFor="partyId">
{{ 'alert.notice.type.WeComApp-partyId' | i18n }}
</nz-form-label>
<nz-form-control [nzSpan]="12">
<input [(ngModel)]="receiver.partyId" name="partyId" nz-input type="text" />
</nz-form-control>
</nz-form-item>

<nz-form-item *ngIf="receiver.type === 10">
<nz-form-label [nzSpan]="7" nzFor="tagId">
{{ 'alert.notice.type.WeComApp-tagId' | i18n }}
</nz-form-label>
<nz-form-control [nzSpan]="12">
<input [(ngModel)]="receiver.tagId" name="tagId" nz-input type="text" />
</nz-form-control>
</nz-form-item>

<nz-form-item *ngIf="receiver.type === 11">
<nz-form-label [nzRequired]="receiver.type === 11" [nzSpan]="7" nzFor="smnAk">
{{ 'alert.notice.type.smn-ak' | i18n }}
Expand Down Expand Up @@ -817,11 +844,11 @@
<nz-option [nzValue]="2" nzLabel="WebHook"></nz-option>
<nz-option [nzLabel]="'alert.notice.type.discord' | i18n" [nzValue]="9"></nz-option>
<nz-option [nzLabel]="'alert.notice.type.slack' | i18n" [nzValue]="8"></nz-option>
<nz-option [nzLabel]="'alert.notice.type.wework' | i18n" [nzValue]="4"></nz-option>
<nz-option [nzLabel]="'alert.notice.type.WeCom-robot' | i18n" [nzValue]="4"></nz-option>
<nz-option [nzLabel]="'alert.notice.type.ding' | i18n" [nzValue]="5"></nz-option>
<nz-option [nzLabel]="'alert.notice.type.fei-shu' | i18n" [nzValue]="6"></nz-option>
<nz-option [nzLabel]="'alert.notice.type.telegram' | i18n" [nzValue]="7"></nz-option>
<nz-option [nzLabel]="'alert.notice.type.weChatApp' | i18n" [nzValue]="10"></nz-option>
<nz-option [nzLabel]="'alert.notice.type.WeComApp' | i18n" [nzValue]="10"></nz-option>
<nz-option [nzLabel]="'alert.notice.type.smn' | i18n" [nzValue]="11"></nz-option>
<nz-option [nzLabel]="'alert.notice.type.serverchan' | i18n" [nzValue]="12"></nz-option>
<nz-option [nzLabel]="'alert.notice.type.gotify' | i18n" [nzValue]="13"></nz-option>
Expand Down
15 changes: 9 additions & 6 deletions web-app/src/assets/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@
"alert.notice.type.url": "URL",
"alert.notice.type.wechat": "Open WeChat",
"alert.notice.type.wechat-id": "WeChat OPENID",
"alert.notice.type.wework": "WeWork Robot",
"alert.notice.type.wework-key": "WeWork Robot KEY",
"alert.notice.type.WeCom-robot": "WeCom Robot",
"alert.notice.type.WeCom-robot-key": "WeCom Robot KEY",
"alert.notice.type.access-token": "Robot ACCESS_TOKEN",
"alert.notice.type.ding": "DingDing Robot",
"alert.notice.type.fei-shu": "FeiShu Robot",
Expand All @@ -289,10 +289,13 @@
"alert.notice.type.discord": "Discord Bot",
"alert.notice.type.discord-bot-token": "Discord Bot Token",
"alert.notice.type.discord-channel-id": "Discord Channel ID",
"alert.notice.type.weChatApp": "Enterprise WeChat app",
"alert.notice.type.weChatApp-corpId": "Enterprise WeChat ID",
"alert.notice.type.weChatApp-agentId": "Enterprise App ID",
"alert.notice.type.weChatApp-appSecret": "Enterprise App Secret",
"alert.notice.type.WeComApp": "WeCom app",
"alert.notice.type.WeComApp-corpId": "WeCom app corp ID",
"alert.notice.type.WeComApp-agentId": "WeCom App ID",
"alert.notice.type.WeComApp-appSecret": "WeCom App Secret",
"alert.notice.type.WeComApp-userId": "User ID(separated by | symbol)",
"alert.notice.type.WeComApp-partyId": "Party ID(separated by | symbol)",
"alert.notice.type.WeComApp-tagId": "Tag ID(separated by | symbol)",
"alert.notice.type.smn": "Huawei Cloud SMN",
"alert.notice.type.smn-ak": "AK",
"alert.notice.type.smn-sk": "SK",
Expand Down
15 changes: 9 additions & 6 deletions web-app/src/assets/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@
"alert.notice.type.url": "URL地址",
"alert.notice.type.wechat": "微信公众号",
"alert.notice.type.wechat-id": "微信OPENID",
"alert.notice.type.wework": "企业微信机器人",
"alert.notice.type.wework-key": "企业微信机器人KEY",
"alert.notice.type.WeCom-robot": "企业微信机器人",
"alert.notice.type.WeCom-robot-key": "企业微信机器人KEY",
"alert.notice.type.access-token": "机器人ACCESS_TOKEN",
"alert.notice.type.ding": "钉钉机器人",
"alert.notice.type.fei-shu": "飞书机器人",
Expand All @@ -290,10 +290,13 @@
"alert.notice.type.discord": "Discord机器人",
"alert.notice.type.discord-bot-token": "Discord Bot Token",
"alert.notice.type.discord-channel-id": "Discord频道ID",
"alert.notice.type.weChatApp": "企业微信应用",
"alert.notice.type.weChatApp-corpId": "企业id",
"alert.notice.type.weChatApp-agentId": "企业应用id",
"alert.notice.type.weChatApp-appSecret": "企业应用secret",
"alert.notice.type.WeComApp": "企业微信应用",
"alert.notice.type.WeComApp-corpId": "企业id",
"alert.notice.type.WeComApp-agentId": "企业应用id",
"alert.notice.type.WeComApp-appSecret": "企业应用secret",
"alert.notice.type.WeComApp-userId": "用户id(多个使用|符号分隔)",
"alert.notice.type.WeComApp-partyId": "部门id(多个使用|符号分隔)",
"alert.notice.type.WeComApp-tagId": "标签id(多个使用|符号分隔)",
"alert.notice.type.smn": "华为云SMN",
"alert.notice.type.smn-ak": "AK",
"alert.notice.type.smn-sk": "SK",
Expand Down
15 changes: 9 additions & 6 deletions web-app/src/assets/i18n/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@
"alert.notice.type.url": "URL地址",
"alert.notice.type.wechat": "微信公衆號",
"alert.notice.type.wechat-id": "微信OPENID",
"alert.notice.type.wework": "企業微信機器人",
"alert.notice.type.wework-key": "企業微信機器人KEY",
"alert.notice.type.WeCom-robot": "企業微信機器人",
"alert.notice.type.WeCom-robot-key": "企業微信機器人KEY",
"alert.notice.type.access-token": "機器人ACCESS_TOKEN",
"alert.notice.type.ding": "釘釘機器人",
"alert.notice.type.fei-shu": "飛書機器人",
Expand All @@ -288,10 +288,13 @@
"alert.notice.type.discord": "Discord機器人",
"alert.notice.type.discord-bot-token": "Discord Bot Token",
"alert.notice.type.discord-channel-id": "Discord頻道ID",
"alert.notice.type.weChatApp": "企業微信應用",
"alert.notice.type.weChatApp-corpId": "企業id",
"alert.notice.type.weChatApp-agentId": "企業應用id",
"alert.notice.type.weChatApp-appSecret": "企業應用secret",
"alert.notice.type.WeComApp": "企業微信應用",
"alert.notice.type.WeComApp-corpId": "企業id",
"alert.notice.type.WeComApp-agentId": "企業應用id",
"alert.notice.type.WeComApp-appSecret": "企業應用secret",
"alert.notice.type.WeComApp-userId": "使用者id(多個使用|符號分隔)",
"alert.notice.type.WeComApp-partyId": "部門id(多個使用|符號分隔)",
"alert.notice.type.WeComApp-tagId": "標簽id(多個使用|符號分隔)",
"alert.notice.type.smn": "華為雲SMN",
"alert.notice.type.smn-ak": "AK",
"alert.notice.type.smn-sk": "SK",
Expand Down
Loading