mirror of
https://github.com/chatopera/cosin.git
synced 2025-07-24 08:31:45 +08:00
https://github.com/chatopera/cskefu/issues/455 Fix session time period, upgrade chatopera sdk
This commit is contained in:
parent
46aff0c33f
commit
625ba34401
@ -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";
|
||||
|
@ -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<String, String> parseConfigMap() {
|
||||
Map<String, String> configMap = (Map<String, String>) JSONObject.parse(StringUtils.isNotBlank(getConfig()) ? getConfig() : "{}");
|
||||
return configMap;
|
||||
}
|
||||
|
||||
public void setConfig(String config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public <K, V> void setConfigMap(Map<K, V> config) {
|
||||
String data = JSONObject.toJSONString(config);
|
||||
this.config = data;
|
||||
}
|
||||
|
||||
}
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
@ -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',
|
||||
|
@ -0,0 +1,6 @@
|
||||
USE `cosinee`;
|
||||
-- -----------------
|
||||
-- prepare variables
|
||||
-- -----------------
|
||||
|
||||
ALTER TABLE `uk_agentservice` MODIFY COLUMN `sessiontimes` BIGINT(64) NULL DEFAULT NULL COMMENT '会话时长';
|
@ -0,0 +1,6 @@
|
||||
USE `cosinee`;
|
||||
-- -----------------
|
||||
-- prepare variables
|
||||
-- -----------------
|
||||
|
||||
ALTER TABLE `uk_agentuser` MODIFY COLUMN `sessiontimes` BIGINT(64) NULL DEFAULT NULL COMMENT '会话时长';
|
@ -375,7 +375,7 @@
|
||||
<dependency>
|
||||
<groupId>com.chatopera.bot</groupId>
|
||||
<artifactId>sdk</artifactId>
|
||||
<version>3.3.2</version>
|
||||
<version>3.5.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
|
@ -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}";
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user