1
0
mirror of https://github.com/chatopera/cosin.git synced 2025-08-01 16:38:02 +08:00

#153 支持配置机器人URL地址

This commit is contained in:
Hai Liang Wang 2018-11-15 18:32:27 +08:00
parent bddaaa8f50
commit 8e5e44ab3f
3 changed files with 16 additions and 4 deletions

View File

@ -337,7 +337,7 @@
<dependency>
<groupId>com.chatopera.bot</groupId>
<artifactId>sdk</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
</dependency>
</dependencies>
<build>

View File

@ -40,6 +40,7 @@ public class ChatbotEventHandler implements EventHandler<UserDataEvent> {
private ChatbotRepository chatbotRes;
private AgentUserRepository agentUserRes;
private String botServiceUrl;
/**
* 根据聊天机器人返回数据更新agentUser
@ -62,9 +63,9 @@ public class ChatbotEventHandler implements EventHandler<UserDataEvent> {
Chatbot c = getChatbotRes()
.findOne(request.getAiid());
logger.info("[chatbot disruptor] chat request baseUrl {}, chatbot {}, fromUserId {}, textMessage {}", c.getBaseUrl(), c.getName(), request.getUserid(), request.getMessage());
logger.info("[chatbot disruptor] chat request baseUrl {}, chatbot {}, fromUserId {}, textMessage {}", getChatbotServiceUrl(), c.getName(), request.getUserid(), request.getMessage());
// Get response from Conversational Engine.
com.chatopera.bot.sdk.Chatbot bot = new com.chatopera.bot.sdk.Chatbot(c.getClientId(), c.getSecret());
com.chatopera.bot.sdk.Chatbot bot = new com.chatopera.bot.sdk.Chatbot(c.getClientId(), c.getSecret(), getChatbotServiceUrl());
JSONObject result = bot.conversation(request.getUserid(), request.getMessage());
// parse response
@ -85,7 +86,7 @@ public class ChatbotEventHandler implements EventHandler<UserDataEvent> {
resp.setUserid(request.getUserid());
resp.setType(request.getType());
resp.setChannel(request.getChannel());
if(data.has("params")){
if (data.has("params")) {
resp.setExpmsg(data.get("params").toString());
}
resp.setContextid(request.getContextid());
@ -138,4 +139,12 @@ public class ChatbotEventHandler implements EventHandler<UserDataEvent> {
return chatbotRes;
}
private String getChatbotServiceUrl() {
if (botServiceUrl == null) {
botServiceUrl = MainContext.getContext().getEnvironment().getProperty("chatopera.bot.url");
}
return botServiceUrl;
}
}

View File

@ -157,3 +157,6 @@ spring.servlet.multipart.max-request-size=15MB
# MySQL Blob
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
# Chatopera Bot
chatopera.bot.url=https://bot.chatopera.com