feat(系统设置): 飞书机器人
This commit is contained in:
parent
2a5e13bfce
commit
80fa6cd4b6
|
@ -18,6 +18,7 @@ public interface NoticeConstants {
|
|||
String EMAIL = "EMAIL";
|
||||
String NAIL_ROBOT = "NAIL_ROBOT";
|
||||
String WECHAT_ROBOT = "WECHAT_ROBOT";
|
||||
String LARK = "LARK";
|
||||
}
|
||||
|
||||
interface Event {
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package io.metersphere.notice.sender.impl;
|
||||
|
||||
import io.metersphere.notice.domain.MessageDetail;
|
||||
import io.metersphere.notice.message.TextMessage;
|
||||
import io.metersphere.notice.sender.AbstractNoticeSender;
|
||||
import io.metersphere.notice.sender.NoticeModel;
|
||||
import io.metersphere.notice.util.LarkClient;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class LarkNoticeSender extends AbstractNoticeSender {
|
||||
|
||||
public void sendLark(MessageDetail messageDetail, String context) {
|
||||
//TextMessage message = new TextMessage(context);
|
||||
LarkClient.send(messageDetail.getWebhook(), context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(MessageDetail messageDetail, NoticeModel noticeModel) {
|
||||
String context = super.getContext(messageDetail, noticeModel);
|
||||
sendLark(messageDetail, context);
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import io.metersphere.notice.domain.MessageDetail;
|
|||
import io.metersphere.notice.sender.NoticeModel;
|
||||
import io.metersphere.notice.sender.NoticeSender;
|
||||
import io.metersphere.notice.sender.impl.DingNoticeSender;
|
||||
import io.metersphere.notice.sender.impl.LarkNoticeSender;
|
||||
import io.metersphere.notice.sender.impl.MailNoticeSender;
|
||||
import io.metersphere.notice.sender.impl.WeComNoticeSender;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -23,6 +24,8 @@ public class NoticeSendService {
|
|||
@Resource
|
||||
private DingNoticeSender dingNoticeSender;
|
||||
@Resource
|
||||
private LarkNoticeSender larkNoticeSender;
|
||||
@Resource
|
||||
private NoticeService noticeService;
|
||||
|
||||
private NoticeSender getNoticeSender(MessageDetail messageDetail) {
|
||||
|
@ -37,6 +40,8 @@ public class NoticeSendService {
|
|||
case NoticeConstants.Type.NAIL_ROBOT:
|
||||
noticeSender = dingNoticeSender;
|
||||
break;
|
||||
case NoticeConstants.Type.LARK:
|
||||
noticeSender = larkNoticeSender;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
package io.metersphere.notice.util;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.metersphere.notice.message.Message;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class LarkClient {
|
||||
public static SendResult send(String webhook, String context) {
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
CloseableHttpResponse response = null;
|
||||
Map<String, Object> mp = new LinkedHashMap<>();
|
||||
JSONObject js = new JSONObject();
|
||||
js.put("text", context);
|
||||
mp.put("msg_type", "text");
|
||||
mp.put("content", js);
|
||||
SendResult sendResult = new SendResult();
|
||||
try {
|
||||
// 创建Http Post请求
|
||||
HttpPost httpPost = new HttpPost(webhook);
|
||||
// 创建请求内容
|
||||
StringEntity entity = new StringEntity(JSON.toJSONString(mp), ContentType.APPLICATION_JSON);
|
||||
httpPost.setEntity(entity);
|
||||
// 执行http请求
|
||||
response = httpClient.execute(httpPost);
|
||||
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
||||
String result = EntityUtils.toString(response.getEntity());
|
||||
JSONObject obj = JSONObject.parseObject(result);
|
||||
Integer errcode = obj.getInteger("errcode");
|
||||
sendResult.setErrorCode(errcode);
|
||||
sendResult.setErrorMsg(obj.getString("errmsg"));
|
||||
sendResult.setIsSuccess(errcode.equals(0));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
response.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return sendResult;
|
||||
}
|
||||
}
|
|
@ -182,7 +182,9 @@ export default {
|
|||
receiveTypeOptions: [
|
||||
{value: 'EMAIL', label: this.$t('organization.message.mail')},
|
||||
{value: 'NAIL_ROBOT', label: this.$t('organization.message.nail_robot')},
|
||||
{value: 'WECHAT_ROBOT', label: this.$t('organization.message.enterprise_wechat_robot')}
|
||||
{value: 'WECHAT_ROBOT', label: this.$t('organization.message.enterprise_wechat_robot')},
|
||||
{value: 'LARK', label: this.$t('organization.message.lark')}
|
||||
|
||||
],
|
||||
};
|
||||
},
|
||||
|
|
|
@ -203,7 +203,8 @@ export default {
|
|||
receiveTypeOptions: [
|
||||
{value: 'EMAIL', label: this.$t('organization.message.mail')},
|
||||
{value: 'NAIL_ROBOT', label: this.$t('organization.message.nail_robot')},
|
||||
{value: 'WECHAT_ROBOT', label: this.$t('organization.message.enterprise_wechat_robot')}
|
||||
{value: 'WECHAT_ROBOT', label: this.$t('organization.message.enterprise_wechat_robot')},
|
||||
{value: 'LARK', label: this.$t('organization.message.lark')}
|
||||
],
|
||||
}
|
||||
},
|
||||
|
|
|
@ -192,7 +192,8 @@ export default {
|
|||
receiveTypeOptions: [
|
||||
{value: 'EMAIL', label: this.$t('organization.message.mail')},
|
||||
{value: 'NAIL_ROBOT', label: this.$t('organization.message.nail_robot')},
|
||||
{value: 'WECHAT_ROBOT', label: this.$t('organization.message.enterprise_wechat_robot')}
|
||||
{value: 'WECHAT_ROBOT', label: this.$t('organization.message.enterprise_wechat_robot')},
|
||||
{value: 'LARK', label: this.$t('organization.message.lark')}
|
||||
],
|
||||
};
|
||||
},
|
||||
|
|
|
@ -192,7 +192,9 @@ export default {
|
|||
receiveTypeOptions: [
|
||||
{value: 'EMAIL', label: this.$t('organization.message.mail')},
|
||||
{value: 'NAIL_ROBOT', label: this.$t('organization.message.nail_robot')},
|
||||
{value: 'WECHAT_ROBOT', label: this.$t('organization.message.enterprise_wechat_robot')}
|
||||
{value: 'WECHAT_ROBOT', label: this.$t('organization.message.enterprise_wechat_robot')},
|
||||
{value: 'LARK', label: this.$t('organization.message.lark')}
|
||||
|
||||
],
|
||||
};
|
||||
},
|
||||
|
|
|
@ -298,6 +298,7 @@ export default {
|
|||
mail: 'mail',
|
||||
nail_robot: 'Nail robot',
|
||||
enterprise_wechat_robot: 'Enterprise wechat robot',
|
||||
lark: "Flying Book Robot",
|
||||
notes: '1. Nail and create a custom robot in the enterprise group, and then copy the webhook address on our platform;\n' +
|
||||
'\n' +
|
||||
'2. Robots are selected as swarm robots, and "custom keyword" is selected for security verification: "task notification";\n' +
|
||||
|
|
|
@ -299,6 +299,7 @@ export default {
|
|||
mail: '邮件',
|
||||
nail_robot: '钉钉机器人',
|
||||
enterprise_wechat_robot: '企业微信机器人',
|
||||
lark: '飞书机器人',
|
||||
notes: '1.钉钉和企业群里新建一个自定义机器人,然后复制 webhook 地址在我们平台上;\n' +
|
||||
' 2.机器人选择为群机器人,安全验证选择“自定义关键词” :"任务通知";\n' +
|
||||
' 3.选择接收人时必须是你所建的群里包含的人,接收人手机号为必填项且为钉钉企业所使用的手机号,',
|
||||
|
|
|
@ -299,6 +299,7 @@ export default {
|
|||
mail: '郵件',
|
||||
nail_robot: '釘釘機器人',
|
||||
enterprise_wechat_robot: '企業微信機器人',
|
||||
lark: '飛書機器人',
|
||||
notes: '1.釘釘和企業群裏新建壹個自定義機器人,然後復制 webhook 地址在我們平臺上;\n' +
|
||||
' 2.機器人選擇為群機器人,安全驗證選擇“自定義關鍵詞” :"任務通知";\n' +
|
||||
' 3.選擇接收人時必須是妳所建的群裏包含的人,接收人手機號為必填項且為釘釘企業所使用的手機號,',
|
||||
|
|
Loading…
Reference in New Issue