Skip to content

Commit

Permalink
cskefu#157 机器人主动发送常见问题列表 __faq_hot_list
Browse files Browse the repository at this point in the history
  • Loading branch information
hailiang-wang committed Nov 17, 2018
1 parent 511e109 commit 97362e6
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -93,6 +93,7 @@ public ModelAndView save(HttpServletRequest request,
@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));
Expand Down Expand Up @@ -127,6 +128,8 @@ public ModelAndView save(HttpServletRequest request,
@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);
}
Expand All @@ -141,6 +144,8 @@ public ModelAndView profile(ModelMap map, HttpServletRequest request, @Valid Str
@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) {
Expand Down Expand Up @@ -210,6 +215,8 @@ public ModelAndView saveprofile(HttpServletRequest request, @Valid CousultInvite
@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);
}
Expand All @@ -222,6 +229,8 @@ public ModelAndView invote(ModelMap map, HttpServletRequest request, @Valid Stri
@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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ private JsonObject delete(JsonObject j, String uid, String organ, String orgi) {
*/
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;
Expand Down Expand Up @@ -494,7 +493,7 @@ private JsonObject create(JsonObject j, String creater, String organ, String org
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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
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;
Expand Down Expand Up @@ -101,20 +102,56 @@ public void onConnect(SocketIOClient client) {
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();
Expand Down

0 comments on commit 97362e6

Please sign in to comment.