FeiShuEventService.java
3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package com.pipihelper.project.feishu.service;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.pipihelper.project.feishu.dto.FeiShuConfig;
import com.pipihelper.project.feishu.dto.FeiShuEventDTO;
import com.pipihelper.project.feishu.dto.FeiShuEventHeaderDTO;
import com.pipihelper.project.feishu.dto.FeiShuEventReceiveMessageDTO;
import com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO;
import com.pipihelper.project.tx.dto.TxConfig;
import com.pipihelper.project.tx.service.TxApiService;
import com.tencentcloudapi.tbp.v20190627.models.Group;
import com.tencentcloudapi.tbp.v20190627.models.TextProcessResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.regex.Pattern;
/**
* @Description: TODO
* @author: charles
* @date: 2022年04月11日 17:01
*/
@Service
public class FeiShuEventService {
@Resource
private FeiShuConfig feiShuConfig;
@Resource
private FeiShuApiService feiShuApiService;
@Autowired
private TxApiService txApiService;
@Autowired
private TxConfig txConfig;
@Async
public void imMessageReceiveV1(FeiShuEventDTO feiShuEventDTO){
FeiShuEventReceiveMessageDTO feiShuEventReceiveMessageDTO = feiShuEventDTO.getEvent().toJavaObject(FeiShuEventReceiveMessageDTO.class);
FeiShuEventReceiveMessageDTO.Sender sender= feiShuEventReceiveMessageDTO.getSender();
FeiShuEventReceiveMessageDTO.Message message= feiShuEventReceiveMessageDTO.getMessage();
if(message.getChat_type().equals("p2p")) {
robotTalk(feiShuEventDTO);
}
}
public void robotTalk(FeiShuEventDTO feiShuEventDTO){
FeiShuEventReceiveMessageDTO feiShuEventReceiveMessageDTO = feiShuEventDTO.getEvent().toJavaObject(FeiShuEventReceiveMessageDTO.class);
FeiShuEventReceiveMessageDTO.Sender sender= feiShuEventReceiveMessageDTO.getSender();
FeiShuEventReceiveMessageDTO.Message message= feiShuEventReceiveMessageDTO.getMessage();
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
feiShuMsgDTO.setReceiveId(sender.getSender_id().getOpen_id());
if(message.getMessage_type().equals("text")){
JSONObject jsonObjectText = JSON.parseObject(message.getContent());
String inputText = jsonObjectText.getString("text");
String uuid = IdUtil.randomUUID();
TextProcessResponse textProcessResponse = txApiService.txTextProcessRequest(uuid, inputText);
for (Group group : textProcessResponse.getResponseMessage().getGroupList()) {
JSONObject content = new JSONObject();
content.put("text", group.getContent());
feiShuMsgDTO.setContent(content.toString());
feiShuMsgDTO.setMsgType("text");
feiShuApiService.sendMsg(feiShuMsgDTO, "open_id");
}
}
}
}