diff --git a/contact-center/app/src/main/java/com/chatopera/cc/basic/Constants.java b/contact-center/app/src/main/java/com/chatopera/cc/basic/Constants.java index b3d6ab65..f9f00b19 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/basic/Constants.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/basic/Constants.java @@ -131,6 +131,9 @@ public class Constants { public static final String AUDIT_AGENT_MESSAGE = "cskefu.agent.audit"; // 机器人返回的结果数据来源为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 发送 public final static String INSTANT_MESSAGING_MQ_QUEUE_FACEBOOK_OTN = "cskefu.outbound.faceboot.otn"; diff --git a/contact-center/app/src/main/java/com/chatopera/cc/model/FbMessenger.java b/contact-center/app/src/main/java/com/chatopera/cc/model/FbMessenger.java index e735f4ea..ab2f3715 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/model/FbMessenger.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/model/FbMessenger.java @@ -16,11 +16,14 @@ package com.chatopera.cc.model; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang.StringUtils; import org.hibernate.annotations.GenericGenerator; import javax.persistence.*; import java.io.Serializable; import java.util.Date; +import java.util.Map; @Entity @Table(name = "cs_fb_messenger") @@ -151,7 +154,23 @@ public class FbMessenger implements Serializable { return config; } + /** + * Get config as map object + * + * @return + */ + public Map parseConfigMap() { + Map configMap = (Map) JSONObject.parse(StringUtils.isNotBlank(getConfig()) ? getConfig() : "{}"); + return configMap; + } + public void setConfig(String config) { this.config = config; } + + public void setConfigMap(Map config) { + String data = JSONObject.toJSONString(config); + this.config = data; + } + } diff --git a/contact-center/app/src/main/resources/static/images/messenger.png b/contact-center/app/src/main/resources/static/images/messenger.png new file mode 100644 index 00000000..00082f03 Binary files /dev/null and b/contact-center/app/src/main/resources/static/images/messenger.png differ diff --git a/contact-center/config/sql/cosinee-MySQL-slim.sql b/contact-center/config/sql/cosinee-MySQL-slim.sql index 18c00c62..43348643 100644 --- a/contact-center/config/sql/cosinee-MySQL-slim.sql +++ b/contact-center/config/sql/cosinee-MySQL-slim.sql @@ -529,7 +529,7 @@ CREATE TABLE `uk_agentservice` ( `ipaddr` varchar(50) DEFAULT NULL COMMENT 'IP地址', `osname` 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 '服务时长', `region` varchar(255) DEFAULT NULL COMMENT '区域', `agentusername` varchar(50) DEFAULT NULL COMMENT '坐席用户名', @@ -666,7 +666,7 @@ CREATE TABLE `uk_agentuser` ( `ipaddr` varchar(50) DEFAULT NULL COMMENT 'IP地址', `osname` 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 '服务次数', `region` varchar(255) DEFAULT NULL COMMENT '地区', `agentservice` varchar(32) DEFAULT NULL COMMENT '服务ID', diff --git a/contact-center/config/sql/upgrade/009.alter_uk_agentservice_sessiontimes.sql b/contact-center/config/sql/upgrade/009.alter_uk_agentservice_sessiontimes.sql new file mode 100644 index 00000000..420c4bc4 --- /dev/null +++ b/contact-center/config/sql/upgrade/009.alter_uk_agentservice_sessiontimes.sql @@ -0,0 +1,6 @@ +USE `cosinee`; +-- ----------------- +-- prepare variables +-- ----------------- + +ALTER TABLE `uk_agentservice` MODIFY COLUMN `sessiontimes` BIGINT(64) NULL DEFAULT NULL COMMENT '会话时长'; diff --git a/contact-center/config/sql/upgrade/009.alter_uk_agentuser_sessiontimes.sql b/contact-center/config/sql/upgrade/009.alter_uk_agentuser_sessiontimes.sql new file mode 100644 index 00000000..13904372 --- /dev/null +++ b/contact-center/config/sql/upgrade/009.alter_uk_agentuser_sessiontimes.sql @@ -0,0 +1,6 @@ +USE `cosinee`; +-- ----------------- +-- prepare variables +-- ----------------- + +ALTER TABLE `uk_agentuser` MODIFY COLUMN `sessiontimes` BIGINT(64) NULL DEFAULT NULL COMMENT '会话时长'; diff --git a/contact-center/root/pom.xml b/contact-center/root/pom.xml index 0cdd8a07..d9b2668c 100644 --- a/contact-center/root/pom.xml +++ b/contact-center/root/pom.xml @@ -375,7 +375,7 @@ com.chatopera.bot sdk - 3.3.2 + 3.5.0 diff --git a/public/plugins/chatbot/classes/ChatbotConstants.java b/public/plugins/chatbot/classes/ChatbotConstants.java index 1cfd6222..3011a1f2 100644 --- a/public/plugins/chatbot/classes/ChatbotConstants.java +++ b/public/plugins/chatbot/classes/ChatbotConstants.java @@ -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_SUGG_REPLY = "BOT_THRESHOLD_FAQ_SUGG_REPLY"; 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}"; } diff --git a/public/plugins/chatbot/classes/ChatbotEventSubscription.java b/public/plugins/chatbot/classes/ChatbotEventSubscription.java index e405f087..c421056f 100644 --- a/public/plugins/chatbot/classes/ChatbotEventSubscription.java +++ b/public/plugins/chatbot/classes/ChatbotEventSubscription.java @@ -17,10 +17,10 @@ package com.chatopera.cc.plugins.chatbot; import com.chatopera.bot.exception.ChatbotException; +import com.chatopera.bot.sdk.Response; import com.chatopera.cc.basic.Constants; import com.chatopera.cc.basic.MainContext; import com.chatopera.cc.cache.Cache; -import com.chatopera.cc.controller.api.request.RestUtils; import com.chatopera.cc.model.Chatbot; import com.chatopera.cc.persistence.repository.AgentUserRepository; import com.chatopera.cc.persistence.repository.ChatMessageRepository; @@ -105,21 +105,29 @@ public class ChatbotEventSubscription { // Get response from Conversational Engine. com.chatopera.bot.sdk.Chatbot bot = new com.chatopera.bot.sdk.Chatbot( 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 if (result != null) { logger.info("[chat] chat response {}", result.toString()); - if (result.getInt(RestUtils.RESP_KEY_RC) == 0) { + if (result.getRc() == 0) { // reply - JSONObject data = result.getJSONObject("data"); + JSONObject data = (JSONObject) result.getData(); if (data.has("logic_is_fallback")) { ChatMessage resp = creatChatMessage(request, c); resp.setMessage(data.getString("string")); ChatMessage respHelp = new ChatMessage(); JSONArray respParams = new JSONArray(); if (!StringUtils.equals(MainContext.ChannelType.WEBIM.toString(), c.getChannel())) { + // 非 WEBIM 情况,比如 Facebook Messenger,使用下面的方法 + // 如果在更多渠道下,此处可能仅适应于 Messenger,那么宜将检测条件调整为 ChannelType.MESSENGER if (data.getBoolean("logic_is_fallback")) { if (!StringUtils.equals(Constants.CHATBOT_HUMAN_FIRST, c.getWorkmode())) { JSONArray faqReplies = data.getJSONArray("faq"); @@ -157,6 +165,20 @@ public class ChatbotEventSubscription { message.put("attachment", attachment); 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())) { if (data.has("params")) { resp.setMessage(data.getJSONArray("params").getJSONObject(0).getString("content")); @@ -197,6 +219,7 @@ public class ChatbotEventSubscription { } } } else { + // 当前渠道为 WEBIM if (data.getBoolean("logic_is_fallback")) { // 兜底回复,检查FAQ JSONArray faqReplies = data.getJSONArray("faq"); @@ -221,11 +244,13 @@ public class ChatbotEventSubscription { // 更新聊天机器人累计值 updateAgentUserWithRespData(request.getUserid(), request.getOrgi(), data); - // 保存并发送 + // 保存并发送 if (MainContext.ChannelType.WEBIM.toString().equals(resp.getChannel())) { + // WEBIM 渠道 chatbotProxy.saveAndPublish(resp); } else { + // 其他渠道 chatMessageRes.save(resp); if (respParams.length() > 0) { for (int i = 0; i < respParams.length(); i++) { @@ -244,7 +269,7 @@ public class ChatbotEventSubscription { } } } 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()); } }