提交 625ba344 编写于 作者: Chatopera 研发团队's avatar Chatopera 研发团队

https://github.com/chatopera/cskefu/issues/455 Fix session time period, upgrade chatopera sdk

上级 46aff0c3
...@@ -131,6 +131,9 @@ public class Constants { ...@@ -131,6 +131,9 @@ public class Constants {
public static final String AUDIT_AGENT_MESSAGE = "cskefu.agent.audit"; public static final String AUDIT_AGENT_MESSAGE = "cskefu.agent.audit";
// 机器人返回的结果数据来源为faq // 机器人返回的结果数据来源为faq
public final static String PROVIDER_FAQ = "faq"; public final static String PROVIDER_FAQ = "faq";
public final static String PROVIDER_FEEDBACK = "feedback";
public final static String PROVIDER_FEEDBACK_EVAL_POSITIVE = "positive";
public final static String PROVIDER_FEEDBACK_EVAL_NEGATIVE = "negative";
// Facebook OTN 发送 // Facebook OTN 发送
public final static String INSTANT_MESSAGING_MQ_QUEUE_FACEBOOK_OTN = "cskefu.outbound.faceboot.otn"; public final static String INSTANT_MESSAGING_MQ_QUEUE_FACEBOOK_OTN = "cskefu.outbound.faceboot.otn";
......
...@@ -16,11 +16,14 @@ ...@@ -16,11 +16,14 @@
package com.chatopera.cc.model; package com.chatopera.cc.model;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*; import javax.persistence.*;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.Map;
@Entity @Entity
@Table(name = "cs_fb_messenger") @Table(name = "cs_fb_messenger")
...@@ -151,7 +154,23 @@ public class FbMessenger implements Serializable { ...@@ -151,7 +154,23 @@ public class FbMessenger implements Serializable {
return config; return config;
} }
/**
* Get config as map object
*
* @return
*/
public Map<String, String> parseConfigMap() {
Map<String, String> configMap = (Map<String, String>) JSONObject.parse(StringUtils.isNotBlank(getConfig()) ? getConfig() : "{}");
return configMap;
}
public void setConfig(String config) { public void setConfig(String config) {
this.config = config; this.config = config;
} }
public <K, V> void setConfigMap(Map<K, V> config) {
String data = JSONObject.toJSONString(config);
this.config = data;
}
} }
...@@ -529,7 +529,7 @@ CREATE TABLE `uk_agentservice` ( ...@@ -529,7 +529,7 @@ CREATE TABLE `uk_agentservice` (
`ipaddr` varchar(50) DEFAULT NULL COMMENT 'IP地址', `ipaddr` varchar(50) DEFAULT NULL COMMENT 'IP地址',
`osname` varchar(100) DEFAULT NULL COMMENT '操作系统名称', `osname` varchar(100) DEFAULT NULL COMMENT '操作系统名称',
`browser` varchar(100) DEFAULT NULL COMMENT '浏览器', `browser` varchar(100) DEFAULT NULL COMMENT '浏览器',
`sessiontimes` int(20) DEFAULT NULL COMMENT '会话时长', `sessiontimes` bigint(64) DEFAULT NULL COMMENT '会话时长',
`servicetime` datetime DEFAULT NULL COMMENT '服务时长', `servicetime` datetime DEFAULT NULL COMMENT '服务时长',
`region` varchar(255) DEFAULT NULL COMMENT '区域', `region` varchar(255) DEFAULT NULL COMMENT '区域',
`agentusername` varchar(50) DEFAULT NULL COMMENT '坐席用户名', `agentusername` varchar(50) DEFAULT NULL COMMENT '坐席用户名',
...@@ -666,7 +666,7 @@ CREATE TABLE `uk_agentuser` ( ...@@ -666,7 +666,7 @@ CREATE TABLE `uk_agentuser` (
`ipaddr` varchar(50) DEFAULT NULL COMMENT 'IP地址', `ipaddr` varchar(50) DEFAULT NULL COMMENT 'IP地址',
`osname` varchar(100) DEFAULT NULL COMMENT '操作系统名称', `osname` varchar(100) DEFAULT NULL COMMENT '操作系统名称',
`browser` varchar(100) DEFAULT NULL COMMENT '浏览器', `browser` varchar(100) DEFAULT NULL COMMENT '浏览器',
`sessiontimes` int(20) DEFAULT NULL COMMENT '会话时长', `sessiontimes` bigint(64) DEFAULT NULL COMMENT '会话时长',
`servicetime` datetime DEFAULT NULL COMMENT '服务次数', `servicetime` datetime DEFAULT NULL COMMENT '服务次数',
`region` varchar(255) DEFAULT NULL COMMENT '地区', `region` varchar(255) DEFAULT NULL COMMENT '地区',
`agentservice` varchar(32) DEFAULT NULL COMMENT '服务ID', `agentservice` varchar(32) DEFAULT NULL COMMENT '服务ID',
USE `cosinee`;
-- -----------------
-- prepare variables
-- -----------------
ALTER TABLE `uk_agentservice` MODIFY COLUMN `sessiontimes` BIGINT(64) NULL DEFAULT NULL COMMENT '会话时长';
USE `cosinee`;
-- -----------------
-- prepare variables
-- -----------------
ALTER TABLE `uk_agentuser` MODIFY COLUMN `sessiontimes` BIGINT(64) NULL DEFAULT NULL COMMENT '会话时长';
...@@ -375,7 +375,7 @@ ...@@ -375,7 +375,7 @@
<dependency> <dependency>
<groupId>com.chatopera.bot</groupId> <groupId>com.chatopera.bot</groupId>
<artifactId>sdk</artifactId> <artifactId>sdk</artifactId>
<version>3.3.2</version> <version>3.5.0</version>
</dependency> </dependency>
</dependencies> </dependencies>
<repositories> <repositories>
......
...@@ -20,4 +20,6 @@ public class ChatbotConstants { ...@@ -20,4 +20,6 @@ public class ChatbotConstants {
public static final String THRESHOLD_FAQ_BEST_REPLY = "BOT_THRESHOLD_FAQ_BEST_REPLY"; public static final String THRESHOLD_FAQ_BEST_REPLY = "BOT_THRESHOLD_FAQ_BEST_REPLY";
public static final String THRESHOLD_FAQ_SUGG_REPLY = "BOT_THRESHOLD_FAQ_SUGG_REPLY"; public static final String THRESHOLD_FAQ_SUGG_REPLY = "BOT_THRESHOLD_FAQ_SUGG_REPLY";
public static final String DEFAULT_BOT_PROVIDER = "https://bot.chatopera.com"; public static final String DEFAULT_BOT_PROVIDER = "https://bot.chatopera.com";
public static final String PROVIDER_FEEDBACK_EVAL_POSITIVE_REPLY_PLACEHOLDER = "${evaluationYesReply}";
public static final String PROVIDER_FEEDBACK_EVAL_NEGATIVE_REPLY_PLACEHOLDER = "${evaluationNoReply}";
} }
...@@ -17,10 +17,10 @@ ...@@ -17,10 +17,10 @@
package com.chatopera.cc.plugins.chatbot; package com.chatopera.cc.plugins.chatbot;
import com.chatopera.bot.exception.ChatbotException; import com.chatopera.bot.exception.ChatbotException;
import com.chatopera.bot.sdk.Response;
import com.chatopera.cc.basic.Constants; import com.chatopera.cc.basic.Constants;
import com.chatopera.cc.basic.MainContext; import com.chatopera.cc.basic.MainContext;
import com.chatopera.cc.cache.Cache; import com.chatopera.cc.cache.Cache;
import com.chatopera.cc.controller.api.request.RestUtils;
import com.chatopera.cc.model.Chatbot; import com.chatopera.cc.model.Chatbot;
import com.chatopera.cc.persistence.repository.AgentUserRepository; import com.chatopera.cc.persistence.repository.AgentUserRepository;
import com.chatopera.cc.persistence.repository.ChatMessageRepository; import com.chatopera.cc.persistence.repository.ChatMessageRepository;
...@@ -105,21 +105,29 @@ public class ChatbotEventSubscription { ...@@ -105,21 +105,29 @@ public class ChatbotEventSubscription {
// Get response from Conversational Engine. // Get response from Conversational Engine.
com.chatopera.bot.sdk.Chatbot bot = new com.chatopera.bot.sdk.Chatbot( com.chatopera.bot.sdk.Chatbot bot = new com.chatopera.bot.sdk.Chatbot(
c.getClientId(), c.getSecret(), botServiceProvider); c.getClientId(), c.getSecret(), botServiceProvider);
JSONObject result = bot.conversation(
request.getUserid(), request.getMessage(), faqBestReplyThreshold, faqSuggReplyThreshold);
JSONObject body = new JSONObject();
body.put("fromUserId", request.getUserid());
body.put("textMessage", request.getMessage());
body.put("faqBestReplyThreshold", faqBestReplyThreshold);
body.put("faqSuggReplyThreshold", faqSuggReplyThreshold);
Response result = bot.command("POST", "/conversation/query", body);
// parse response // parse response
if (result != null) { if (result != null) {
logger.info("[chat] chat response {}", result.toString()); logger.info("[chat] chat response {}", result.toString());
if (result.getInt(RestUtils.RESP_KEY_RC) == 0) { if (result.getRc() == 0) {
// reply // reply
JSONObject data = result.getJSONObject("data"); JSONObject data = (JSONObject) result.getData();
if (data.has("logic_is_fallback")) { if (data.has("logic_is_fallback")) {
ChatMessage resp = creatChatMessage(request, c); ChatMessage resp = creatChatMessage(request, c);
resp.setMessage(data.getString("string")); resp.setMessage(data.getString("string"));
ChatMessage respHelp = new ChatMessage(); ChatMessage respHelp = new ChatMessage();
JSONArray respParams = new JSONArray(); JSONArray respParams = new JSONArray();
if (!StringUtils.equals(MainContext.ChannelType.WEBIM.toString(), c.getChannel())) { if (!StringUtils.equals(MainContext.ChannelType.WEBIM.toString(), c.getChannel())) {
// 非 WEBIM 情况,比如 Facebook Messenger,使用下面的方法
// 如果在更多渠道下,此处可能仅适应于 Messenger,那么宜将检测条件调整为 ChannelType.MESSENGER
if (data.getBoolean("logic_is_fallback")) { if (data.getBoolean("logic_is_fallback")) {
if (!StringUtils.equals(Constants.CHATBOT_HUMAN_FIRST, c.getWorkmode())) { if (!StringUtils.equals(Constants.CHATBOT_HUMAN_FIRST, c.getWorkmode())) {
JSONArray faqReplies = data.getJSONArray("faq"); JSONArray faqReplies = data.getJSONArray("faq");
...@@ -157,6 +165,20 @@ public class ChatbotEventSubscription { ...@@ -157,6 +165,20 @@ public class ChatbotEventSubscription {
message.put("attachment", attachment); message.put("attachment", attachment);
resp.setExpmsg(message.toString()); resp.setExpmsg(message.toString());
} }
} else if (StringUtils.equals(Constants.PROVIDER_FEEDBACK, data.getJSONObject("service").get("provider").toString())) {
respHelp = null;
// 反馈回复内容
String sentiment = data.getJSONObject("service").get("sentiment").toString();
if (StringUtils.equals(Constants.PROVIDER_FEEDBACK_EVAL_POSITIVE, sentiment)) {
// 积极评价
resp.setMessage(ChatbotConstants.PROVIDER_FEEDBACK_EVAL_POSITIVE_REPLY_PLACEHOLDER);
} else if (StringUtils.equals(Constants.PROVIDER_FEEDBACK_EVAL_NEGATIVE, sentiment)) {
// 消极评价
resp.setMessage(ChatbotConstants.PROVIDER_FEEDBACK_EVAL_NEGATIVE_REPLY_PLACEHOLDER);
} else {
// no response
resp.setMessage("${leaveMeAlone}");
}
} else if (StringUtils.equals(Constants.PROVIDER_FAQ, data.getJSONObject("service").get("provider").toString())) { } else if (StringUtils.equals(Constants.PROVIDER_FAQ, data.getJSONObject("service").get("provider").toString())) {
if (data.has("params")) { if (data.has("params")) {
resp.setMessage(data.getJSONArray("params").getJSONObject(0).getString("content")); resp.setMessage(data.getJSONArray("params").getJSONObject(0).getString("content"));
...@@ -197,6 +219,7 @@ public class ChatbotEventSubscription { ...@@ -197,6 +219,7 @@ public class ChatbotEventSubscription {
} }
} }
} else { } else {
// 当前渠道为 WEBIM
if (data.getBoolean("logic_is_fallback")) { if (data.getBoolean("logic_is_fallback")) {
// 兜底回复,检查FAQ // 兜底回复,检查FAQ
JSONArray faqReplies = data.getJSONArray("faq"); JSONArray faqReplies = data.getJSONArray("faq");
...@@ -221,11 +244,13 @@ public class ChatbotEventSubscription { ...@@ -221,11 +244,13 @@ public class ChatbotEventSubscription {
// 更新聊天机器人累计值 // 更新聊天机器人累计值
updateAgentUserWithRespData(request.getUserid(), request.getOrgi(), data); updateAgentUserWithRespData(request.getUserid(), request.getOrgi(), data);
// 保存并发送
// 保存并发送
if (MainContext.ChannelType.WEBIM.toString().equals(resp.getChannel())) { if (MainContext.ChannelType.WEBIM.toString().equals(resp.getChannel())) {
// WEBIM 渠道
chatbotProxy.saveAndPublish(resp); chatbotProxy.saveAndPublish(resp);
} else { } else {
// 其他渠道
chatMessageRes.save(resp); chatMessageRes.save(resp);
if (respParams.length() > 0) { if (respParams.length() > 0) {
for (int i = 0; i < respParams.length(); i++) { for (int i = 0; i < respParams.length(); i++) {
...@@ -244,7 +269,7 @@ public class ChatbotEventSubscription { ...@@ -244,7 +269,7 @@ public class ChatbotEventSubscription {
} }
} }
} else { } else {
logger.warn("[chat] can not get expected response {}", result.toString()); logger.warn("[chat] can not get expected response rc {}, error {}", result.getRc(), result.getError());
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册