-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathChatbotExample.java
More file actions
134 lines (116 loc) · 4.66 KB
/
Copy pathChatbotExample.java
File metadata and controls
134 lines (116 loc) · 4.66 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
package io.rong.example.chatbot;
import io.rong.CenterEnum;
import io.rong.RongCloud;
import io.rong.methods.chatbot.Chatbot;
import io.rong.models.bot.ChatbotInfoModel;
import io.rong.models.bot.ChatbotIntegration;
import io.rong.models.bot.SetChatbotIntegration;
import io.rong.models.response.*;
import java.util.List;
/**
* Chatbot test example
*
* @author RongCloud
*/
public class ChatbotExample {
/**
* Replace with your App Key
*/
private static final String APP_KEY = "appKey";
/**
* Replace with your App Secret
*/
private static final String APP_SECRET = "secret";
/**
* Initialization
*/
private static Chatbot chatbot = RongCloud.getInstance(APP_KEY, APP_SECRET, CenterEnum.BJ).chatbot;
/**
* Local test call
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// Create chatbot test
createTest();
// Delete chatbot test
deleteTest();
// Query chatbot list test
queryChatbotListTest();
// Get chatbot test
getChatbotTest();
// Update chatbot test
updateTest();
// Add chatbot integration test
createIntegrationTest();
// Delete chatbot integration test
deleteIntegrationTest();
// Update chatbot integration list test
updateIntegrationTest();
}
private static void createTest() throws Exception {
ChatbotInfoModel info = new ChatbotInfoModel();
info.setUserId("bot_uid1");
info.setName("name");
info.setType("type");
info.setProfileUrl("profileUrl");
info.setMetadata(new java.util.HashMap<String, String>());
List<ChatbotIntegration> integrations = new java.util.ArrayList<>();
ChatbotIntegration chatbotIntegration = new ChatbotIntegration();
chatbotIntegration.setType("webhook");
chatbotIntegration.setCallbackUrl("callbackUrl");
integrations.add(chatbotIntegration);
info.setIntegrations(integrations);
ResponseResult result = chatbot.create(info);
System.out.println("create chatbot test: " + result.toString());
}
private static void updateIntegrationTest() throws Exception {
SetChatbotIntegration info = new SetChatbotIntegration();
info.setCallbackUrl("https://ws");
info.setUserId("bot_uid1");
info.setType("webhook");
ResponseResult result = chatbot.updateIntegration(info);
System.out.println("update chat bot integration test: " + result.toString());
}
private static void deleteIntegrationTest() throws Exception {
ResponseResult result = chatbot.deleteIntegration("bot_uid1", "webhook");
System.out.println("delete chat bot integration test: " + result.toString());
}
private static void createIntegrationTest() throws Exception {
SetChatbotIntegration chatbotIntegration = new SetChatbotIntegration();
chatbotIntegration.setType("webhook");
chatbotIntegration.setCallbackUrl("callbackUrl2");
chatbotIntegration.setUserId("bot_uid1");
ResponseResult result = chatbot.createIntegration(chatbotIntegration);
System.out.println("add chat bot integration test: " + result.toString());
}
private static void updateTest() throws Exception {
ChatbotInfoModel info = new ChatbotInfoModel();
info.setUserId("bot_uid1");
info.setName("name");
info.setType("type");
info.setProfileUrl("profileUrl1");
info.setMetadata(new java.util.HashMap<String, String>());
List<ChatbotIntegration> integrations = new java.util.ArrayList<>();
ChatbotIntegration chatbotIntegration = new ChatbotIntegration();
chatbotIntegration.setType("webhook");
chatbotIntegration.setCallbackUrl("callbackUrl1");
integrations.add(chatbotIntegration);
info.setIntegrations(integrations);
ResponseResult result = chatbot.update(info);
System.out.println("update chatbot test: " + result.toString());
}
private static void getChatbotTest() throws Exception {
QueryChatbotsResult result = chatbot.get("bot_uid1");
System.out.println("get chatbot test: " + result.toString());
}
private static void queryChatbotListTest() throws Exception {
PagingQueryChatbotsResult result = chatbot.query(1, 2, true);
System.out.println("query chatbot test: " + result.toString());
}
private static void deleteTest() throws Exception {
ResponseResult result = chatbot.delete("bot_uid1");
System.out.println("delete chatbot test: " + result.toString());
}
}