mirror of
https://github.com/chatopera/cosin.git
synced 2025-08-01 16:38:02 +08:00
#157 机器人主动发送常见问题列表 __faq_hot_list
This commit is contained in:
parent
511e109cc7
commit
97362e68f1
@ -73,7 +73,7 @@ public class WebIMController extends Handler {
|
||||
public ModelAndView index(ModelMap map, HttpServletRequest request, @Valid String snsid) {
|
||||
|
||||
CousultInvite coultInvite = invite.findBySnsaccountidAndOrgi(snsid, super.getOrgi(request));
|
||||
logger.info("[index] snsaccount Id {}, AiFirst {}", coultInvite.getSnsaccountid(), coultInvite.isAifirst());
|
||||
logger.info("[index] snsaccount Id {}, Ai {}, Aifirst {}, Ainame {}, Aisuccess {}, Aiid {}", coultInvite.getSnsaccountid(), coultInvite.isAi(), coultInvite.isAifirst(), coultInvite.getAiname(), coultInvite.getAisuccesstip(), coultInvite.getAiid());
|
||||
|
||||
if (coultInvite != null) {
|
||||
map.addAttribute("inviteData", coultInvite);
|
||||
@ -93,6 +93,7 @@ public class WebIMController extends Handler {
|
||||
@Valid CousultInvite inviteData,
|
||||
@RequestParam(value = "webimlogo", required = false) MultipartFile webimlogo,
|
||||
@RequestParam(value = "agentheadimg", required = false) MultipartFile agentheadimg) throws IOException {
|
||||
logger.info("[save] snsaccount Id {}, Ai {}, Aifirst {}, Ainame {}, Aisuccess {}, Aiid {}", inviteData.getSnsaccountid(), inviteData.isAi(), inviteData.isAifirst(), inviteData.getAiname(), inviteData.getAisuccesstip(), inviteData.getAiid());
|
||||
|
||||
if (StringUtils.isNotBlank(inviteData.getSnsaccountid())) {
|
||||
CousultInvite tempData = invite.findBySnsaccountidAndOrgi(inviteData.getSnsaccountid(), super.getOrgi(request));
|
||||
@ -127,6 +128,8 @@ public class WebIMController extends Handler {
|
||||
@Menu(type = "app", subtype = "profile", admin = true)
|
||||
public ModelAndView profile(ModelMap map, HttpServletRequest request, @Valid String snsid) {
|
||||
CousultInvite coultInvite = invite.findBySnsaccountidAndOrgi(snsid, super.getOrgi(request));
|
||||
logger.info("[profile] snsaccount Id {}, Ai {}, Aifirst {}, Ainame {}, Aisuccess {}, Aiid {}", coultInvite.getSnsaccountid(), coultInvite.isAi(), coultInvite.isAifirst(), coultInvite.getAiname(), coultInvite.getAisuccesstip(), coultInvite.getAiid());
|
||||
|
||||
if (coultInvite != null) {
|
||||
map.addAttribute("inviteData", coultInvite);
|
||||
}
|
||||
@ -141,6 +144,8 @@ public class WebIMController extends Handler {
|
||||
@Menu(type = "admin", subtype = "profile", admin = true)
|
||||
public ModelAndView saveprofile(HttpServletRequest request, @Valid CousultInvite inviteData, @RequestParam(value = "dialogad", required = false) MultipartFile dialogad) throws IOException {
|
||||
CousultInvite tempInviteData;
|
||||
logger.info("[profile/save] snsaccount Id {}, Ai {}, Aifirst {}, Ainame {}, Aisuccess {}, Aiid {}", inviteData.getSnsaccountid(), inviteData.isAi(), inviteData.isAifirst(), inviteData.getAiname(), inviteData.getAisuccesstip(), inviteData.getAiid());
|
||||
|
||||
if (inviteData != null && StringUtils.isNotBlank(inviteData.getId())) {
|
||||
tempInviteData = invite.findOne(inviteData.getId());
|
||||
if (tempInviteData != null) {
|
||||
@ -210,6 +215,8 @@ public class WebIMController extends Handler {
|
||||
@Menu(type = "app", subtype = "invote", admin = true)
|
||||
public ModelAndView invote(ModelMap map, HttpServletRequest request, @Valid String snsid) {
|
||||
CousultInvite coultInvite = invite.findBySnsaccountidAndOrgi(snsid, super.getOrgi(request));
|
||||
logger.info("[invote] snsaccount Id {}, Ai {}, Aifirst {}, Ainame {}, Aisuccess {}, Aiid {}", coultInvite.getSnsaccountid(), coultInvite.isAi(), coultInvite.isAifirst(), coultInvite.getAiname(), coultInvite.getAisuccesstip(), coultInvite.getAiid());
|
||||
|
||||
if (coultInvite != null) {
|
||||
map.addAttribute("inviteData", coultInvite);
|
||||
}
|
||||
@ -222,6 +229,8 @@ public class WebIMController extends Handler {
|
||||
@Menu(type = "admin", subtype = "profile", admin = true)
|
||||
public ModelAndView saveinvote(HttpServletRequest request, @Valid CousultInvite inviteData, @RequestParam(value = "invotebg", required = false) MultipartFile invotebg) throws IOException {
|
||||
CousultInvite tempInviteData;
|
||||
logger.info("[invote/save] snsaccount Id {}, Ai {}, Aifirst {}, Ainame {}, Aisuccess {}, Aiid {}", inviteData.getSnsaccountid(), inviteData.isAi(), inviteData.isAifirst(), inviteData.getAiname(), inviteData.getAisuccesstip(), inviteData.getAiid());
|
||||
|
||||
if (inviteData != null && StringUtils.isNotBlank(inviteData.getId())) {
|
||||
tempInviteData = invite.findOne(inviteData.getId());
|
||||
if (tempInviteData != null) {
|
||||
|
@ -428,7 +428,6 @@ public class ApiChatbotController extends Handler {
|
||||
*/
|
||||
private JsonObject create(JsonObject j, String creater, String organ, String orgi) {
|
||||
JsonObject resp = new JsonObject();
|
||||
String baseUrl = getBotBaseUrl();
|
||||
String snsid = null;
|
||||
String workmode = null;
|
||||
String clientId = null;
|
||||
@ -494,7 +493,7 @@ public class ApiChatbotController extends Handler {
|
||||
c.setId(MainUtils.getUUID());
|
||||
c.setClientId(clientId);
|
||||
c.setSecret(secret);
|
||||
c.setBaseUrl(baseUrl);
|
||||
c.setBaseUrl(getBotBaseUrl());
|
||||
c.setDescription(botDetails.getJSONObject("data").getString("description"));
|
||||
c.setFallback(botDetails.getJSONObject("data").getString("fallback"));
|
||||
c.setPrimaryLanguage(botDetails.getJSONObject("data").getString("primaryLanguage"));
|
||||
|
@ -42,6 +42,7 @@ import com.corundumstudio.socketio.annotation.OnConnect;
|
||||
import com.corundumstudio.socketio.annotation.OnDisconnect;
|
||||
import com.corundumstudio.socketio.annotation.OnEvent;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -101,20 +102,56 @@ public class ChatbotEventHandler {
|
||||
client.sendEvent(MainContext.MessageTypeEnum.STATUS.toString(), tip);
|
||||
|
||||
// send out welcome message
|
||||
if (invite != null && StringUtils.isNotBlank(invite.getAisuccesstip())) {
|
||||
ChatMessage welcome = new ChatMessage();
|
||||
welcome.setCalltype(MainContext.CallTypeEnum.OUT.toString());
|
||||
welcome.setAppid(appid);
|
||||
welcome.setOrgi(orgi);
|
||||
welcome.setAiid(aiid);
|
||||
welcome.setMessage(invite.getAisuccesstip());
|
||||
welcome.setTouser(user);
|
||||
welcome.setTousername(nickname);
|
||||
welcome.setMsgtype(MainContext.MessageTypeEnum.MESSAGE.toString());
|
||||
welcome.setUserid(user);
|
||||
welcome.setUsername(invite.getAiname());
|
||||
welcome.setUpdatetime(System.currentTimeMillis());
|
||||
client.sendEvent(MainContext.MessageTypeEnum.MESSAGE.toString(), welcome);
|
||||
if (invite != null) {
|
||||
Chatbot chatbot = getChatbotRes().findOne(invite.getAiid());
|
||||
com.chatopera.bot.sdk.Chatbot bot = new com.chatopera.bot.sdk.Chatbot(chatbot.getClientId(), chatbot.getSecret(), chatbot.getBaseUrl());
|
||||
JSONObject details = bot.details();
|
||||
|
||||
// 发送欢迎语
|
||||
if (details.has("rc") &&
|
||||
details.getInt("rc") == 0) {
|
||||
ChatMessage welcome = new ChatMessage();
|
||||
String welcomeTextMessage = details.getJSONObject("data").getString("welcome");
|
||||
if (StringUtils.isNotBlank(welcomeTextMessage)) {
|
||||
welcome.setCalltype(MainContext.CallTypeEnum.OUT.toString());
|
||||
welcome.setAppid(appid);
|
||||
welcome.setOrgi(orgi);
|
||||
welcome.setAiid(aiid);
|
||||
welcome.setMessage(welcomeTextMessage);
|
||||
welcome.setTouser(user);
|
||||
welcome.setTousername(nickname);
|
||||
welcome.setMsgtype(MainContext.MessageTypeEnum.MESSAGE.toString());
|
||||
welcome.setUserid(user);
|
||||
welcome.setUsername(invite.getAiname());
|
||||
welcome.setUpdatetime(System.currentTimeMillis());
|
||||
client.sendEvent(MainContext.MessageTypeEnum.MESSAGE.toString(), welcome);
|
||||
}
|
||||
|
||||
// 发送常见问题列表
|
||||
JSONObject faqhotresp = bot.conversation(user, "__faq_hot_list");
|
||||
logger.info("faqhot {}", faqhotresp.toString());
|
||||
if (faqhotresp.getInt("rc") == 0) {
|
||||
JSONObject faqhotdata = faqhotresp.getJSONObject("data");
|
||||
if ((!faqhotdata.getBoolean("logic_is_fallback")) &&
|
||||
faqhotdata.has("string") &&
|
||||
faqhotdata.has("params")) {
|
||||
ChatMessage faqhotmsg = new ChatMessage();
|
||||
faqhotmsg.setCalltype(MainContext.CallTypeEnum.OUT.toString());
|
||||
faqhotmsg.setAppid(appid);
|
||||
faqhotmsg.setOrgi(orgi);
|
||||
faqhotmsg.setAiid(aiid);
|
||||
faqhotmsg.setMessage(faqhotdata.getString("string"));
|
||||
faqhotmsg.setExpmsg(faqhotdata.getJSONArray("params").toString());
|
||||
faqhotmsg.setTouser(user);
|
||||
faqhotmsg.setTousername(nickname);
|
||||
faqhotmsg.setMsgtype(MainContext.MessageTypeEnum.MESSAGE.toString());
|
||||
faqhotmsg.setUserid(user);
|
||||
faqhotmsg.setUsername(invite.getAiname());
|
||||
faqhotmsg.setUpdatetime(System.currentTimeMillis());
|
||||
client.sendEvent(MainContext.MessageTypeEnum.MESSAGE.toString(), faqhotmsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
InetSocketAddress address = (InetSocketAddress) client.getRemoteAddress();
|
||||
|
Loading…
x
Reference in New Issue
Block a user