mirror of
https://github.com/chatopera/cosin.git
synced 2025-08-01 16:38:02 +08:00
#75 设置网站配置的聊天机器人关联信息
This commit is contained in:
parent
e042e1c6cd
commit
45bf5d6333
@ -58,6 +58,7 @@ public class Application {
|
||||
static{
|
||||
UKDataContext.model.put("contacts", true) ;
|
||||
UKDataContext.model.put("sales", true);
|
||||
UKDataContext.model.put("chatbot", true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -22,9 +22,13 @@ import java.util.HashSet;
|
||||
|
||||
public class ChatbotUtils {
|
||||
public static final HashSet<String> VALID_LANGS = new HashSet<String>(Arrays.asList(new String[]{"zh_CN", "en_US"}));
|
||||
public static final HashSet<String> VALID_WORKMODELS = new HashSet<String>(Arrays.asList(new String[]{"客服机器人优先", "人工客服优先"}));
|
||||
public static final String CHATBOT_FIRST = "客服机器人优先";
|
||||
public static final String HUMAN_FIRST = "人工客服优先";
|
||||
public static final HashSet<String> VALID_WORKMODELS = new HashSet<String>(Arrays.asList(new String[]{CHATBOT_FIRST, HUMAN_FIRST}));
|
||||
|
||||
public static final String SNS_TYPE_WEBIM = "webim";
|
||||
|
||||
|
||||
/**
|
||||
* 使用snsid得到ChatbotID
|
||||
*
|
||||
|
@ -18,14 +18,13 @@ package com.chatopera.cc.webim.web.handler.api.rest;
|
||||
import com.chatopera.cc.util.Menu;
|
||||
import com.chatopera.cc.util.UKTools;
|
||||
import com.chatopera.cc.util.exception.CallOutRecordException;
|
||||
import com.chatopera.cc.webim.service.repository.ChatbotRepository;
|
||||
import com.chatopera.cc.webim.service.repository.OrganRepository;
|
||||
import com.chatopera.cc.webim.service.repository.SNSAccountRepository;
|
||||
import com.chatopera.cc.webim.service.repository.UserRepository;
|
||||
import com.chatopera.cc.webim.service.repository.*;
|
||||
import com.chatopera.cc.webim.util.OnlineUserUtils;
|
||||
import com.chatopera.cc.webim.util.chatbot.ChatbotUtils;
|
||||
import com.chatopera.cc.webim.web.handler.Handler;
|
||||
import com.chatopera.cc.webim.web.handler.api.request.RestUtils;
|
||||
import com.chatopera.cc.webim.web.model.Chatbot;
|
||||
import com.chatopera.cc.webim.web.model.CousultInvite;
|
||||
import com.chatopera.cc.webim.web.model.Organ;
|
||||
import com.chatopera.cc.webim.web.model.User;
|
||||
import com.chatopera.chatbot.ChatbotAPI;
|
||||
@ -79,6 +78,9 @@ public class ApiChatbotController extends Handler {
|
||||
@Autowired
|
||||
private OrganRepository organRes;
|
||||
|
||||
@Autowired
|
||||
private ConsultInviteRepository consultInviteRes;
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST)
|
||||
@Menu(type = "apps", subtype = "chatbot", access = true)
|
||||
@ApiOperation("聊天机器人")
|
||||
@ -147,6 +149,12 @@ public class ApiChatbotController extends Handler {
|
||||
if (c.getApi().exists(c.getChatbotID())) {
|
||||
c.setEnabled(isEnabled);
|
||||
chatbotRes.save(c);
|
||||
|
||||
// 更新访客网站配置
|
||||
CousultInvite invite = OnlineUserUtils.cousult(c.getSnsAccountIdentifier(), c.getOrgi(), consultInviteRes);
|
||||
invite.setAi(isEnabled);
|
||||
consultInviteRes.save(invite);
|
||||
|
||||
resp.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_SUCC);
|
||||
resp.addProperty(RestUtils.RESP_KEY_DATA, "完成。");
|
||||
} else {
|
||||
@ -186,12 +194,12 @@ public class ApiChatbotController extends Handler {
|
||||
return resp;
|
||||
}
|
||||
|
||||
// 更新访客网站配置
|
||||
CousultInvite invite = OnlineUserUtils.cousult(c.getSnsAccountIdentifier(), c.getOrgi(), consultInviteRes);
|
||||
|
||||
if (j.has("workmode") && ChatbotUtils.VALID_WORKMODELS.contains(j.get("workmode").getAsString())) {
|
||||
c.setWorkmode(j.get("workmode").getAsString());
|
||||
}
|
||||
|
||||
if (j.has("enabled")) {
|
||||
c.setEnabled(j.get("enabled").getAsBoolean());
|
||||
invite.setAifirst(StringUtils.equals(ChatbotUtils.CHATBOT_FIRST, c.getWorkmode()));
|
||||
}
|
||||
|
||||
String description = j.has("description") ? j.get("description").getAsString() : null;
|
||||
@ -199,6 +207,13 @@ public class ApiChatbotController extends Handler {
|
||||
String welcome = j.has("welcome") ? j.get("welcome").getAsString() : null;
|
||||
String name = j.has("name") ? j.get("name").getAsString() : null;
|
||||
|
||||
|
||||
if (j.has("enabled")) {
|
||||
boolean enabled = j.get("enabled").getAsBoolean();
|
||||
c.setEnabled(enabled);
|
||||
invite.setAi(enabled);
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(description) ||
|
||||
StringUtils.isNotBlank(fallback) ||
|
||||
StringUtils.isNotBlank(welcome)) {
|
||||
@ -228,11 +243,19 @@ public class ApiChatbotController extends Handler {
|
||||
if (StringUtils.isNotBlank(fallback))
|
||||
c.setFallback(fallback);
|
||||
|
||||
if (StringUtils.isNotBlank(welcome))
|
||||
if (StringUtils.isNotBlank(welcome)) {
|
||||
c.setWelcome(welcome);
|
||||
invite.setAimsg(welcome);
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(name)) {
|
||||
c.setName(name);
|
||||
invite.setAiname(name);
|
||||
}
|
||||
|
||||
c.setUpdatetime(new Date());
|
||||
chatbotRes.save(c);
|
||||
consultInviteRes.save(invite);
|
||||
|
||||
return resp;
|
||||
}
|
||||
@ -328,6 +351,16 @@ public class ApiChatbotController extends Handler {
|
||||
|
||||
try {
|
||||
if (c.getApi().deleteByChatbotID(c.getChatbotID())) {
|
||||
// 更新访客网站配置
|
||||
CousultInvite invite = OnlineUserUtils.cousult(c.getSnsAccountIdentifier(), c.getOrgi(), consultInviteRes);
|
||||
if (invite != null) {
|
||||
invite.setAi(false);
|
||||
invite.setAiname(null);
|
||||
invite.setAimsg(null);
|
||||
invite.setAifirst(false);
|
||||
invite.setAiid(null);
|
||||
consultInviteRes.save(invite);
|
||||
}
|
||||
chatbotRes.delete(c);
|
||||
resp.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_SUCC);
|
||||
resp.addProperty(RestUtils.RESP_KEY_DATA, "删除成功。");
|
||||
@ -464,9 +497,6 @@ public class ApiChatbotController extends Handler {
|
||||
c.setPrimaryLanguage(primaryLanguage);
|
||||
c.setName(name);
|
||||
c.setWelcome(result.getJSONObject("data").getString("welcome"));
|
||||
|
||||
// 默认不开启
|
||||
c.setEnabled(false);
|
||||
c.setCreater(creater);
|
||||
c.setOrgan(organ);
|
||||
c.setOrgi(orgi);
|
||||
@ -477,6 +507,18 @@ public class ApiChatbotController extends Handler {
|
||||
c.setUpdatetime(dt);
|
||||
c.setWorkmode(workmode);
|
||||
|
||||
// 默认不开启
|
||||
boolean enabled = false;
|
||||
c.setEnabled(enabled);
|
||||
|
||||
// 更新访客网站配置
|
||||
CousultInvite invite = OnlineUserUtils.cousult(c.getSnsAccountIdentifier(), c.getOrgi(), consultInviteRes);
|
||||
invite.setAi(enabled);
|
||||
invite.setAifirst(StringUtils.equals(ChatbotUtils.CHATBOT_FIRST, workmode));
|
||||
invite.setAiid(c.getId());
|
||||
invite.setAiname(c.getName());
|
||||
invite.setAimsg(c.getWelcome());
|
||||
consultInviteRes.save(invite);
|
||||
chatbotRes.save(c);
|
||||
|
||||
JsonObject data = new JsonObject();
|
||||
|
@ -17,27 +17,18 @@
|
||||
|
||||
package com.chatopera.cc.webim.web.handler.apps.internet;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import com.chatopera.cc.core.UKDataContext;
|
||||
import com.chatopera.cc.util.*;
|
||||
import com.chatopera.cc.util.extra.DataExchangeInterface;
|
||||
import com.chatopera.cc.util.webim.WebIMClient;
|
||||
import com.chatopera.cc.webim.service.acd.ServiceQuene;
|
||||
import com.chatopera.cc.webim.service.cache.CacheHelper;
|
||||
import com.chatopera.cc.webim.service.es.ContactsRepository;
|
||||
import com.chatopera.cc.webim.service.repository.*;
|
||||
import com.chatopera.cc.webim.util.MessageUtils;
|
||||
import com.chatopera.cc.webim.util.OnlineUserUtils;
|
||||
import com.chatopera.cc.webim.web.handler.Handler;
|
||||
import com.chatopera.cc.webim.web.model.*;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -56,39 +47,16 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
|
||||
import com.chatopera.cc.util.BrowserClient;
|
||||
import com.chatopera.cc.util.CheckMobile;
|
||||
import com.chatopera.cc.util.IP;
|
||||
import com.chatopera.cc.util.IPTools;
|
||||
import com.chatopera.cc.util.Menu;
|
||||
import com.chatopera.cc.util.UKTools;
|
||||
import com.chatopera.cc.webim.service.repository.AgentServiceSatisRepository;
|
||||
import com.chatopera.cc.webim.service.repository.AgentUserContactsRepository;
|
||||
import com.chatopera.cc.webim.service.repository.AttachmentRepository;
|
||||
import com.chatopera.cc.webim.service.repository.ChatMessageRepository;
|
||||
import com.chatopera.cc.webim.service.repository.ConsultInviteRepository;
|
||||
import com.chatopera.cc.webim.service.repository.InviteRecordRepository;
|
||||
import com.chatopera.cc.webim.service.repository.LeaveMsgRepository;
|
||||
import com.chatopera.cc.webim.service.repository.SNSAccountRepository;
|
||||
import com.chatopera.cc.webim.web.model.AgentReport;
|
||||
import com.chatopera.cc.webim.web.model.AgentServiceSatis;
|
||||
import com.chatopera.cc.webim.web.model.AgentUserContacts;
|
||||
import com.chatopera.cc.webim.web.model.AiConfig;
|
||||
import com.chatopera.cc.webim.web.model.AttachmentFile;
|
||||
import com.chatopera.cc.webim.web.model.BlackEntity;
|
||||
import com.chatopera.cc.webim.web.model.Contacts;
|
||||
import com.chatopera.cc.webim.web.model.CousultInvite;
|
||||
import com.chatopera.cc.webim.web.model.InviteRecord;
|
||||
import com.chatopera.cc.webim.web.model.KnowledgeType;
|
||||
import com.chatopera.cc.webim.web.model.LeaveMsg;
|
||||
import com.chatopera.cc.webim.web.model.SNSAccount;
|
||||
import com.chatopera.cc.webim.web.model.SessionConfig;
|
||||
import com.chatopera.cc.webim.web.model.SystemConfig;
|
||||
import com.chatopera.cc.webim.web.model.Topic;
|
||||
import com.chatopera.cc.webim.web.model.UKeFuDic;
|
||||
import com.chatopera.cc.webim.web.model.UploadStatus;
|
||||
import com.chatopera.cc.webim.web.model.User;
|
||||
import com.chatopera.cc.webim.web.model.UserHistory;
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/im")
|
||||
@ -137,7 +105,12 @@ public class IMController extends Handler {
|
||||
|
||||
@RequestMapping("/{id}")
|
||||
@Menu(type = "im", subtype = "point", access = true)
|
||||
public ModelAndView point(HttpServletRequest request , HttpServletResponse response, @PathVariable String id , @Valid String orgi , @Valid String userid , @Valid String title, @Valid String aiid) {
|
||||
public ModelAndView point(HttpServletRequest request, HttpServletResponse response,
|
||||
@PathVariable String id,
|
||||
@Valid String orgi,
|
||||
@Valid String userid,
|
||||
@Valid String title,
|
||||
@Valid String aiid) {
|
||||
ModelAndView view = request(super.createRequestPageTempletResponse("/apps/im/point"));
|
||||
String sessionid = request.getSession().getId();
|
||||
if (!StringUtils.isBlank(id)) {
|
||||
@ -165,7 +138,6 @@ public class IMController extends Handler {
|
||||
|
||||
view.addObject("mobile", CheckMobile.check(request.getHeader("User-Agent")));
|
||||
|
||||
|
||||
CousultInvite invite = OnlineUserUtils.cousult(id, orgi, inviteRepository);
|
||||
if (invite != null) {
|
||||
orgi = invite.getOrgi();
|
||||
@ -258,12 +230,15 @@ public class IMController extends Handler {
|
||||
if (!StringUtils.isBlank(userid)) {
|
||||
BlackEntity black = (BlackEntity) CacheHelper.getSystemCacheBean().getCacheObject(userid, UKDataContext.SYSTEM_ORGI);
|
||||
if ((black != null && (black.getEndtime() == null || black.getEndtime().after(new Date())))) {
|
||||
response.getWriter().write("in");;
|
||||
response.getWriter().write("in");
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 延时获取用户端浏览器的跟踪ID
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param orgi
|
||||
@ -322,7 +297,30 @@ public class IMController extends Handler {
|
||||
|
||||
@RequestMapping("/index")
|
||||
@Menu(type = "im", subtype = "index", access = true)
|
||||
public ModelAndView index(ModelMap map ,HttpServletRequest request , HttpServletResponse response, @Valid String orgi, @Valid String aiid, @Valid String traceid ,@Valid String exchange, @Valid String title ,@Valid String url,@Valid String mobile ,@Valid String phone , @Valid String ai , @Valid String client , @Valid String type, @Valid String appid, @Valid String userid, @Valid String sessionid , @Valid String skill, @Valid String agent , @Valid Contacts contacts,@Valid String product,@Valid String description,@Valid String imgurl,@Valid String pid,@Valid String purl) throws Exception {
|
||||
public ModelAndView index(ModelMap map, HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
@Valid String orgi,
|
||||
@Valid String aiid,
|
||||
@Valid String traceid,
|
||||
@Valid String exchange,
|
||||
@Valid String title,
|
||||
@Valid String url,
|
||||
@Valid String mobile,
|
||||
@Valid String phone,
|
||||
@Valid String ai,
|
||||
@Valid String client,
|
||||
@Valid String type,
|
||||
@Valid String appid,
|
||||
@Valid String userid,
|
||||
@Valid String sessionid,
|
||||
@Valid String skill,
|
||||
@Valid String agent,
|
||||
@Valid Contacts contacts,
|
||||
@Valid String product,
|
||||
@Valid String description,
|
||||
@Valid String imgurl,
|
||||
@Valid String pid,
|
||||
@Valid String purl) throws Exception {
|
||||
ModelAndView view = request(super.createRequestPageTempletResponse("/apps/im/index"));
|
||||
BlackEntity black = (BlackEntity) CacheHelper.getSystemCacheBean().getCacheObject(userid, UKDataContext.SYSTEM_ORGI);
|
||||
if (!StringUtils.isBlank(appid) && (black == null || (black.getEndtime() != null && black.getEndtime().before(new Date())))) {
|
||||
@ -473,7 +471,10 @@ public class IMController extends Handler {
|
||||
nickname = contacts.getName();
|
||||
}
|
||||
map.addAttribute("username", nickname);
|
||||
if(UKDataContext.model.get("xiaoe")!=null && !StringUtils.isBlank(invite.getAiid()) && invite.isAi() && ((!StringUtils.isBlank(ai) && ai.equals("true")) || (invite.isAifirst() && ai == null))){ //启用 AI , 并且 AI优先 接待
|
||||
if (UKDataContext.model.get("chatbot") != null &&
|
||||
StringUtils.isNotBlank(invite.getAiid()) &&
|
||||
invite.isAi() &&
|
||||
(StringUtils.equals(ai, "true") || (invite.isAifirst() && ai == null))) { //启用 AI , 并且 AI优先 接待
|
||||
DataExchangeInterface dataInterface = (DataExchangeInterface) UKDataContext.getContext().getBean("aiconfig");
|
||||
AiConfig aiConfig = (AiConfig) dataInterface.getDataByIdAndOrgi(aiid, invite.getOrgi());
|
||||
if (aiConfig != null) {
|
||||
@ -618,7 +619,6 @@ public class IMController extends Handler {
|
||||
view.addObject("purl", purl);
|
||||
|
||||
|
||||
|
||||
if (!StringUtils.isBlank(traceid)) {
|
||||
view.addObject("traceid", traceid);
|
||||
}
|
||||
@ -651,7 +651,8 @@ public class IMController extends Handler {
|
||||
if (!StringUtils.isBlank(appid)) {
|
||||
SNSAccount snsAccount = snsAccountRepository.findBySnsid(appid);
|
||||
String orgi = snsAccount.getOrgi();
|
||||
CousultInvite invite = inviteRepository.findBySnsaccountidAndOrgi(appid, orgi) ; ;
|
||||
CousultInvite invite = inviteRepository.findBySnsaccountidAndOrgi(appid, orgi);
|
||||
;
|
||||
List<LeaveMsg> msgList = leaveMsgRes.findByOrgiAndUserid(invite.getOrgi(), msg.getUserid());
|
||||
// if(msg!=null && msgList.size() == 0){
|
||||
if (msg != null) {
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user