飞书交互-判断用户给飞书机器人发送负责人,给机器人推送分类责任人信息。
This commit is contained in:
+5
@@ -67,6 +67,11 @@ public class LarkController {
|
||||
log.info("给"+employeeId+"用户推送知识库一级分类菜单:==========================================================");
|
||||
feishuService.sendKnowledgeBaseTypeCard(employeeId.split(","));
|
||||
}
|
||||
//判断用户发送的消息内容,如果包含"负责人" 那么给用户推送知识库分类负责人信息
|
||||
if(StringUtils.contains(text,"负责人")){
|
||||
log.info("给"+employeeId+"用户推送知识库负责人:==========================================================");
|
||||
feishuService.sendKnowledgeBaseTypeChargePersonCard(employeeId.split(","));
|
||||
}
|
||||
}
|
||||
}
|
||||
return decrypt;
|
||||
|
||||
+6
@@ -56,4 +56,10 @@ public interface IFeishuService {
|
||||
* @param jsonObject
|
||||
*/
|
||||
void sendKnowledgeBaseInfoCard(JSONObject jsonObject);
|
||||
|
||||
/**
|
||||
* 发送知识库分类负责人卡片消息 (用户输入负责人的时候)
|
||||
* @param split
|
||||
*/
|
||||
void sendKnowledgeBaseTypeChargePersonCard(String[] split);
|
||||
}
|
||||
|
||||
+79
@@ -542,4 +542,83 @@ public class FeishuServiceImpl implements IFeishuService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendKnowledgeBaseTypeChargePersonCard(String[] userIds) {
|
||||
String token = null;
|
||||
try {
|
||||
token = getTenantAccessToken();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 设置请求头
|
||||
Map<String, String> headerMap = new HashMap<>();
|
||||
headerMap.put("Authorization", "Bearer " + token);
|
||||
headerMap.put("Content-Type", "application/json; charset=utf-8");
|
||||
|
||||
String sendJson = " {\n" +
|
||||
" \"config\": {\n" +
|
||||
" \"wide_screen_mode\": true\n" +
|
||||
" },\n" +
|
||||
" \"header\": {\n" +
|
||||
" \"title\": {\n" +
|
||||
" \"tag\": \"plain_text\",\n" +
|
||||
" \"content\": \"点击下方的分类查看常见问题\"\n" +
|
||||
" },\n" +
|
||||
" \"template\": \"green\"\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
JSONObject jsonObject = JSONObject.parseObject(sendJson);
|
||||
JSONArray elements = new JSONArray();
|
||||
JSONObject element = new JSONObject();
|
||||
element.put("tag","action");
|
||||
element.put("layout","bisected");
|
||||
|
||||
//获取分类
|
||||
List<ProblemKnowledgeBaseClassifyEO> problemKnowledgeBaseClassifyEOList = this.problemKnowledgeBaseClassifyEOService.list();
|
||||
this.problemKnowledgeBaseClassifyEOService.disposeData(problemKnowledgeBaseClassifyEOList);
|
||||
|
||||
JSONArray actions = new JSONArray();
|
||||
|
||||
//组装推送过去的点击按钮
|
||||
for (ProblemKnowledgeBaseClassifyEO problemKnowledgeBaseClassifyEO : problemKnowledgeBaseClassifyEOList) {
|
||||
JSONObject buttonObject = new JSONObject();
|
||||
JSONObject text = new JSONObject();
|
||||
JSONObject value = new JSONObject();
|
||||
buttonObject.put("tag","button");
|
||||
|
||||
text.put("tag","plain_text");
|
||||
text.put("content",problemKnowledgeBaseClassifyEO.getProblemLabel() + " [" + problemKnowledgeBaseClassifyEO.getChargePersonIdName() + "]");
|
||||
value.put("chosen",problemKnowledgeBaseClassifyEO.getChargePersonId());
|
||||
|
||||
buttonObject.put("text",text);
|
||||
buttonObject.put("type","primary");
|
||||
buttonObject.put("value",value);
|
||||
actions.add(buttonObject);
|
||||
}
|
||||
|
||||
element.put("actions",actions);
|
||||
|
||||
|
||||
elements.add(element);
|
||||
jsonObject.put("elements",elements);
|
||||
// 设置请求参数
|
||||
JSONObject paramsMap = new JSONObject();
|
||||
paramsMap.put("user_ids", userIds);
|
||||
paramsMap.put("msg_type", "interactive");
|
||||
paramsMap.put("card", jsonObject);
|
||||
|
||||
// 发送请求给飞书
|
||||
String response = null;
|
||||
try {
|
||||
response = HttpRequestUtil.getResponseOfPOST(batchSendMessageUrl, headerMap, paramsMap.toJSONString());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 获取返回结果
|
||||
JSONObject tokenJson = JSONObject.parseObject(response);
|
||||
if(!tokenJson.get("code").toString().equals("0")) {
|
||||
log.error("请求出现异常:" + tokenJson.get("msg") + " " + tokenJson);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user