-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathChatbot.java
More file actions
executable file
·155 lines (134 loc) · 5.34 KB
/
Copy pathChatbot.java
File metadata and controls
executable file
·155 lines (134 loc) · 5.34 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package io.rong.methods.chatbot;
import io.rong.RongCloud;
import io.rong.methods.BaseMethod;
import io.rong.models.CheckMethod;
import io.rong.models.bot.ChatbotInfoModel;
import io.rong.models.bot.SetChatbotIntegration;
import io.rong.models.response.PagingQueryChatbotsResult;
import io.rong.models.response.QueryChatbotsResult;
import io.rong.models.response.ResponseResult;
import io.rong.util.GsonUtil;
import org.apache.commons.lang3.StringUtils;
import java.util.HashMap;
import java.util.Map;
/**
* chatbot service
*/
public class Chatbot extends BaseMethod {
private static final String API_JSON_PATH = "chatbot";
public Chatbot(String appKey, String appSecret, RongCloud rongCloud) {
this.appKey = appKey;
this.appSecret = appSecret;
this.rongCloud = rongCloud;
initPath();
}
@Override
protected void initPath() {
super.path = API_JSON_PATH;
}
/**
* create bot
**/
public ResponseResult create(ChatbotInfoModel info) throws Exception {
String method = CheckMethod.BOT_CREATE;
ResponseResult result = checkFiled(info, method, ResponseResult.class);
if (result != null) {
return result;
}
return doRequest("/v3/bot/create.json", info.toString(), method, ResponseResult.class, CONTENT_TYPE_JSON);
}
/**
* list chatbot
*/
public PagingQueryChatbotsResult query(Integer page, Integer pageSize, Boolean includeIntegration) throws Exception {
String method = CheckMethod.BOT_LIST;
Map<String, Object> params = new HashMap<>();
if (page != null) {
params.put("page", page);
}
if (pageSize != null) {
params.put("pageSize", pageSize);
}
if (includeIntegration != null) {
params.put("includeIntegration", includeIntegration);
}
return doRequest("/v3/bot/query.json", GsonUtil.toJson(params, Map.class), method, PagingQueryChatbotsResult.class, CONTENT_TYPE_JSON);
}
/**
* get chatbot
*/
public QueryChatbotsResult get(String... userIds) throws Exception {
String method = CheckMethod.BOT_GET;
if (userIds == null) {
return new QueryChatbotsResult(20005, "The parameter 'userIds' is required");
}
QueryChatbotsResult result = checkParam("userIds", userIds, method, QueryChatbotsResult.class);
if (result != null) {
return result;
}
Map<String, Object> params = new HashMap<>();
params.put("userIds", userIds);
return doRequest("/v3/bot/get.json", GsonUtil.toJson(params, Map.class), method, QueryChatbotsResult.class, CONTENT_TYPE_JSON);
}
/**
* delete chatbot
*/
public ResponseResult delete(String userId) throws Exception {
String method = CheckMethod.BOT_DELETE;
if (StringUtils.isBlank(userId)) {
return new ResponseResult(20005, "The parameter 'userId' is required");
}
ResponseResult result = checkParam("userId", userId, method, ResponseResult.class);
if (result != null) {
return result;
}
Map<String, Object> params = new HashMap<>();
params.put("userId", userId);
return doRequest("/v3/bot/delete.json", GsonUtil.toJson(params, Map.class), method, ResponseResult.class, CONTENT_TYPE_JSON);
}
/**
* update chatbot
*/
public ResponseResult update(ChatbotInfoModel model) throws Exception {
String method = CheckMethod.BOT_UPDATE;
return doRequest("/v3/bot/update.json", model.toString(), method, ResponseResult.class, CONTENT_TYPE_JSON);
}
/**
* create chatbot integration
*/
public ResponseResult createIntegration(SetChatbotIntegration integration) throws Exception {
String method = CheckMethod.BOT_ADD_INTEGRATION;
ResponseResult result = checkFiled(integration, method, ResponseResult.class);
if (result != null) {
return result;
}
return doRequest("/v3/bot/integration/create.json", integration.toString(), method, ResponseResult.class, CONTENT_TYPE_JSON);
}
/**
* delete chatbot integration
*/
public ResponseResult deleteIntegration(String userId, String type) throws Exception {
String method = CheckMethod.BOT_DELETE_INTEGRATION;
if (StringUtils.isBlank(userId)) {
return new ResponseResult(20005, "The parameter 'userId' is required");
}
if (StringUtils.isBlank(type)) {
return new ResponseResult(20005, "The parameter 'type' is required");
}
Map<String, Object> params = new HashMap<>();
params.put("userId", userId);
params.put("type", type);
return doRequest("/v3/bot/integration/delete.json", GsonUtil.toJson(params, Map.class), method, ResponseResult.class, CONTENT_TYPE_JSON);
}
/**
* update chatbot integration
*/
public ResponseResult updateIntegration(SetChatbotIntegration integration) throws Exception {
String method = CheckMethod.BOT_UPDATE_INTEGRATION;
ResponseResult result = checkFiled(integration, method, ResponseResult.class);
if (result != null) {
return result;
}
return doRequest("/v3/bot/integration/update.json", integration.toString(), method, ResponseResult.class, CONTENT_TYPE_JSON);
}
}