diff --git a/src/gameDesign/GlobalVariableConstructor.java b/src/gameDesign/GlobalVariableConstructor.java index 59c9b09..4cb1caa 100644 --- a/src/gameDesign/GlobalVariableConstructor.java +++ b/src/gameDesign/GlobalVariableConstructor.java @@ -40,6 +40,13 @@ public class GlobalVariableConstructor extends ElementConstructor { varInitialMap.put(attrName, attrValue); } } + + + JSONObject script = gameElements.getJSONObject("speechcraft"); + for(String key:script.keySet()){ + attrValue = (String)script.get(key); + varInitialMap.put(key, attrValue); + } }catch (Exception e){ operationStatus = 0; message = "全局变量处理出现异常"; diff --git a/src/gameDesign/MapConstructor.java b/src/gameDesign/MapConstructor.java index 7780b4e..8d5ffa7 100644 --- a/src/gameDesign/MapConstructor.java +++ b/src/gameDesign/MapConstructor.java @@ -16,6 +16,8 @@ public class MapConstructor extends ElementConstructor { Map question2keyword = new HashMap(); JSONArray locations = null; + Map script = null; //话术模板 + public MapConstructor(SqlHelper helper, int botId, int skipCount, String botAccount, HashSet exceptRelation, StringBuffer POS) { super(); @@ -83,10 +85,46 @@ public class MapConstructor extends ElementConstructor { public void construct(JSONObject gameElements, UserInfo userinfo) { try { + + + + conditionDescription.put("site", "当前地点"); JSONObject map = gameElements.getJSONObject("map"); Map question2keyword = JSONObject.toJavaObject(map.getJSONObject("question"), Map.class); + script = JSONObject.toJavaObject(gameElements.getJSONObject("speechcraft"), Map.class); + + if(!script.containsKey("PATH_AT")) + script.put("PATH_AT", "你已经在%s"); + if(!script.containsKey("WHERE_I_AM")) + script.put("WHERE_I_AM", "在%s"); + if(!script.containsKey("PATH_ADJOINT")) + script.put("PATH_ADJOINT", "就在附近哦"); + if(!script.containsKey("PATH_EXIST")) + script.put("PATH_EXIST", "通过%s可以到达目的地"); + if(!script.containsKey("PATH_NOT_EXIST")) + script.put("PATH_NOT_EXIST", "不可到达"); + if(!script.containsKey("CAN_GO_SITES")) + script.put("CAN_GO_SITES", "你可以去%s"); + if(!script.containsKey("CAN_GO_NOWHERE")) + script.put("CAN_GO_NOWHERE", "没什么地方可去的,继续玩吧"); + if(!script.containsKey("SITE_NOT_ACTIVE")) + script.put("SITE_NOT_ACTIVE", "你来到了%s\""); + if(!script.containsKey("SITE_NOT_ADJOINT")) + script.put("SITE_NOT_ADJOINT", "通过%s可以到达目的地"); + if(!script.containsKey("AROUND_PEOPLE")) + script.put("AROUND_PEOPLE", "周围有%s"); + if(!script.containsKey("AROUND_ITEMS")) + script.put("AROUND_ITEMS", "周围有%s"); + if(!script.containsKey("AROUND_THINGS")) + script.put("AROUND_THINGS", "周围有%s"); + + + + if(script == null){ + throw new Exception("话术不存在"); + } JSONArray locations = map.getJSONArray("locations"); String userName = (String) gameElements.get("userName"); this.locations = locations; @@ -112,7 +150,8 @@ public class MapConstructor extends ElementConstructor { } catch(Exception e){ operationStatus = 0; e.printStackTrace(); - message = "地图处理出现异常"; + message = "地图处理出现异常:"; + message += e.getMessage(); return; } @@ -129,7 +168,7 @@ public class MapConstructor extends ElementConstructor { String conditionKeywords = nickname + ":哪里+" + nickname + ":哪+现在:哪里+现在:哪"; jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, " ", - "match", "【{智能助手-2}】你在{site-2}", "yaobuyao", "" + "match", "【{智能助手-2}】" + String.format(script.get("WHERE_I_AM"), "{site-2}"), "yaobuyao", "" ); jConfig.setNextStepStatus("return-0"); jConfig.setAuxiliaryPriority("1"); @@ -158,24 +197,20 @@ public class MapConstructor extends ElementConstructor { placeA = (String) locations.getJSONObject(i).get("name"); placeKeywords.append("+" + placeA); -// for(String nickname:JSONArray.parseArray(locations.getJSONObject(i).getJSONArray("nickname").toJSONString(), String.class)){ -// placeKeywords.append("+" + nickname); -// } + } for (int j = 0; j < locationNum; j++) { placeB = (String) locations.getJSONObject(j).get("name"); -// for(String nickname:JSONArray.parseArray(locations.getJSONObject(i).getJSONArray("nickname").toJSONString(), String.class)){ -// placeB += "+" + nickname; -// } + jConfig = new JConfig( conditionName + "::match-Include=" + placeKeywords + ",isNeighbour:"+ conditionName + "::match-Include=0", "site::match-Include=" + placeB , "match,return-0", - "【{智能助手-2}】你已经在"+ "{" + conditionName + "-1}" + "了", + "【{智能助手-2}】" + String.format(script.get("PATH_AT"), "{site-2}"), " ", "" ); @@ -192,7 +227,7 @@ public class MapConstructor extends ElementConstructor { + ",isNeighbour:"+ conditionName + "::match-Include=1", "site::match-Include=" + placeB , "match,return-0", - "【{智能助手-2}】{" + conditionName + "-1}" + "就在旁边哦", + "【{智能助手-2}】" + String.format(script.get("PATH_ADJOINT"), "{site-2}"), " ", "" ); @@ -269,20 +304,22 @@ public class MapConstructor extends ElementConstructor { /** * 添加初始化变量 */ - if(!varInitialMap.containsKey("任务线" + placeA + "最后一个condition")) { - varInitialMap.put("任务线" + placeA + "最后一个condition", "yaobuyao"); - varInitialMap.put("任务线" + placeA + "最后的回答", "你来到了" + placeA.split("\\+")[0] + ",现在什么都没有, 请继续之前的剧情,接着往下玩吧!"); - conditionDescription.put("任务线" + placeA + "最后一个condition", "任务线" + placeA + "最后一个condition"); - conditionDescription.put("任务线" + placeA + "最后的回答", "任务线" + placeA + "最后的回答"); + String placeAMain = placeA.split("\\+")[0]; + if(!varInitialMap.containsKey("任务线" + placeAMain + "最后一个condition")) { + varInitialMap.put("任务线" + placeAMain + "最后一个condition", "yaobuyao"); + varInitialMap.put("任务线" + placeAMain + "最后的回答", "你来到了" + placeAMain + ",现在什么都没有, 请继续之前的剧情,接着往下玩吧!"); + conditionDescription.put("任务线" + placeAMain + "最后一个condition", "任务线" + placeAMain + "最后一个condition"); + conditionDescription.put("任务线" + placeAMain + "最后的回答", "任务线" + placeAMain + "最后的回答"); } for (int j = 0; j < locationNum; j++) { placeB = (String) locations.getJSONObject(j).get("name"); + String placeBMain = placeB.split("\\+")[0]; descriptionB = (String) locations.getJSONObject(j).get("description"); placeKeywords = conditionKeywords.replace("地点", placeB); - lastTaskCondition = "任务线" + placeB + "最后一个condition"; - lastTaskReply = "任务线" + placeB + "最后的回答"; + lastTaskCondition = "任务线" + placeBMain + "最后一个condition"; + lastTaskReply = "任务线" + placeBMain + "最后的回答"; jConfig = new JConfig( @@ -290,7 +327,7 @@ public class MapConstructor extends ElementConstructor { + ",isNeighbour:"+ conditionName + "::match-Include=0", "site::match-Include=" + placeA , "match,return-0", - "【{智能助手-2}】你已经在"+placeB + "了", + "【{智能助手-2}】" + String.format(script.get("PATH_AT"), placeBMain), " ", "" ); @@ -303,7 +340,7 @@ public class MapConstructor extends ElementConstructor { conditionName + "::match-Include=" + placeKeywords + "," + ",isNeighbour:"+ conditionName + "::match-Include=1", "site::match-Include=" + placeA, - "match, reutrn-0", "【{智能助手-2}】{" + lastTaskReply + "-2}", "yaobuyao", "site:" + placeB + "-<-process-nextStep:var={" + lastTaskCondition +"-2}" + "match, reutrn-0", "{" + lastTaskReply + "-2}", "yaobuyao", "site:" + placeBMain + "-<-process-nextStep:var={" + lastTaskCondition +"-2}" ); jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); @@ -333,7 +370,7 @@ public class MapConstructor extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, " ", - "match,return-0", "【{智能助手-2}】周围{map_query-2}。", "yaobuyao", "map_query:queryAroundNpcBySite:" + "match,return-0", "【{智能助手-2}】{map_query-2}。", "yaobuyao", "map_query:queryAroundNpcBySite:" ); jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); @@ -346,7 +383,7 @@ public class MapConstructor extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, " ", - "match,return-0", "【{智能助手-2}】周围{map_query-2}。", "yaobuyao", "map_query:queryAroundGoodsBySite:" + "match,return-0", "【{智能助手-2}】{map_query-2}。", "yaobuyao", "map_query:queryAroundGoodsBySite:" ); jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); @@ -359,7 +396,7 @@ public class MapConstructor extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, " ", - "match,return-0", "【{智能助手-2}】周围{map_query-2}。", "yaobuyao", "map_query:queryAroundAllBySite:" + "match,return-0", "【{智能助手-2}】{map_query-2}。", "yaobuyao", "map_query:queryAroundAllBySite:" ); jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); diff --git a/src/gameDesign/PlotConstructor.java b/src/gameDesign/PlotConstructor.java index a7c576e..19594b5 100644 --- a/src/gameDesign/PlotConstructor.java +++ b/src/gameDesign/PlotConstructor.java @@ -14,6 +14,8 @@ import java.util.*; public class PlotConstructor extends ElementConstructor { + String GAME_STEP_FORMAT = "%s_plot_%s"; + JSONArray plots = null; HashMap> adjList = new HashMap>(); HashMap> revAdjList = new HashMap>(); @@ -49,7 +51,7 @@ public class PlotConstructor extends ElementConstructor { conditionDescription.put(taskLineName, taskLineName); varInitialMap.put("unknownText", "你说啥?"); - varInitialMap.put("game_step", (String) id2j.get(start).get("id")); + varInitialMap.put("game_step", String.format(GAME_STEP_FORMAT, botAccount, (String) id2j.get(start).get("id"))); conditionDescription.put("unknownText", "对于无法识别的问题做出的回答"); conditionDescription.put("game_step", "QA问答游戏进度"); @@ -114,7 +116,7 @@ public class PlotConstructor extends ElementConstructor { */ public void BFSGenerate4(JSONObject root, UserInfo userinfo, JSONObject jsonObject) { String id, rootId = (String) root.get("id"), adjId, nextId, parentId, taskName = "", value = "", extraHP = "", extraUK = "", nextTaskName, keywordOptions, conditionName = "yaobuyao", - nextUnknownText, curUnknownText, nextCondition, location, nextLocation, taskLineName, nTaskLineName, lastTaskReply, lastTaskCondition; + nextUnknownText, curUnknownText, nextCondition, location, nextLocation, taskLineName, nTaskLineName, lastTaskReply, lastTaskCondition, reply; boolean newBranch, manyParent; JSONObject node = null, branchNode = null, adjNode = null; JSONArray branch = null; @@ -132,7 +134,7 @@ public class PlotConstructor extends ElementConstructor { conditionName = (String)root.get("conditionName"); - String startPlace = (String)root.get("place"); + String startPlace = ((String)root.get("place")).split("\\+")[0]; varInitialMap.put("site", startPlace); varInitialMap.put("任务线" + startPlace + "最后一个condition", ""); varInitialMap.put("任务线" + startPlace + "最后的回答", ""); @@ -143,15 +145,17 @@ public class PlotConstructor extends ElementConstructor { //用于开始游戏的配置 jConfig = new JConfig( - "start_options::match-Include=+开始+开始游戏+继续游戏+继续", + "start_options::match-Include=+开始+开始游戏+继续游戏+继续+重新开始", "任务线" + startPlace + "最后一个condition::match-Include=+null", "match", (String)jsonObject.get("plotStartText"), conditionName, "任务线" + startPlace + "最后一个condition:" + conditionName + "-<-" + root.get("id") + ":+1" + - "-<-任务线" + startPlace + "最后的回答:" + (String)jsonObject.get("plotStartText") + "-<-" + String.format(taskLine, root.get("place")) + ":" + root.get("id") + "-<-任务线" + startPlace + "最后的回答:" + (String)jsonObject.get("plotStartText") + "-<-" + String.format(taskLine, startPlace) + ":" + root.get("id") ); + jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); + jConfig = new JConfig( " ", "任务线" + startPlace + "最后一个condition::match-Include=+null", @@ -160,6 +164,7 @@ public class PlotConstructor extends ElementConstructor { "start_options", "" ); + jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); @@ -172,7 +177,7 @@ public class PlotConstructor extends ElementConstructor { node = queue.remove(); id = (String) node.get("id"); parentId = (String) node.get("parentId"); - location = (String) node.get("place"); + location = ((String) node.get("place")).split("\\+")[0]; conditionName = (String) node.get("conditionName"); curUnknownText = (String) node.get("nextUnknownText"); taskLineName = "任务线_" + location + "进度"; @@ -207,6 +212,7 @@ public class PlotConstructor extends ElementConstructor { branchNode = branch.getJSONObject(i); nextId = (String) branchNode.get("nextPlotId"); + reply = (String)branchNode.get("reply"); Map updateKnowledge = JSONObject.toJavaObject(branchNode.getJSONObject("updateKnowledge"), Map.class); if(updateKnowledge.containsKey("unkonwnText")) nextUnknownText = updateKnowledge.get("unknownText"); @@ -219,13 +225,15 @@ public class PlotConstructor extends ElementConstructor { nextCondition = (String) id2j.get(nextId).get("conditionName"); if(nextCondition.equals("")) nextCondition = "yaobuyao"; - nextLocation = (String) id2j.get(nextId).get("place"); + nextLocation = ((String) id2j.get(nextId).get("place")).split("\\+")[0]; nTaskLineName = "任务线_" + nextLocation + "进度"; } else { //如果不存在下一剧情,就将condition设为空,任务线进度不变 + nTaskLineName = taskLineName; nextLocation = location; nextCondition = "yaobuyao"; + continue; } lastTaskCondition = "任务线" + nextLocation + "最后一个condition"; @@ -235,8 +243,18 @@ public class PlotConstructor extends ElementConstructor { //额外条件是任务线进度达到当前剧情,额外更新变量是将任务线移动至下一剧情 extraHP = taskLineName + "::match-Include=" + id + ",site::match-Include=" + location + "," + id + "::number-BiggerOrEqual=" + 1 + "," + nextId + "::match-Include=null"; - extraUK = nTaskLineName + ":" + nextId + "-<-site:" + nextLocation + "-<-" + lastTaskCondition + ":" + nextCondition + "-<-" + lastTaskReply + ":var={reply-3}" + - "-<-" + id + ":" + "+1-<-" + nextId + ":" + "+1" + "-<-game_step:" + botAccount + "_plot_" + nextId; + extraUK = nTaskLineName + ":" + nextId + "-<-" + lastTaskCondition + ":" + nextCondition + "-<-" + lastTaskReply + ":" + (String)branchNode.get("reply") + + "-<-" + id + ":" + "+1-<-" + nextId + ":" + "+1" + "-<-game_step:" + String.format(GAME_STEP_FORMAT, botAccount, nextId); + + if(!branchNode.containsKey("moveWithPlot") || (Boolean)branchNode.get("moveWithPlot")) { + extraUK += "-<-site:" + nextLocation; + + }else { + if(!location.equals(nextLocation)){ + //如果当前地点和下一步剧情地点不同,要提示 + reply = "请到" + nextLocation + "开始下一步剧情"; + } + } List curPremiseList = JSONArray.parseArray(branchNode.getJSONArray("curPremise").toJSONString(), String.class); @@ -246,15 +264,21 @@ public class PlotConstructor extends ElementConstructor { JSONArray.parseArray(branchNode.getJSONArray("hisPremise").toJSONString(), String.class), updateKnowledge, "", extraHP, extraUK, - "match", (String) branchNode.get("reply"), (String) nextCondition, "0" + "match", reply, (String) nextCondition, "0" ); if (curPremiseList.size() == 0){ - jConfig.setFeature(jConfig.getFeature() + ",activate,post::all(http://simqa.sz.chewrobot.com:28081/game)"); + jConfig.setFeature(jConfig.getFeature() + ",activate,post::gameQA(http://simqa.sz.chewrobot.com:28081/game)"); jConfig.setNextStep("queryskip1,queryskip2,queryskip3"); jConfig.setUpdateKnowledge(jConfig.getUpdateKnowledge() + "-<-临时变量1:"+ nextCondition +"-<-临时变量2:var={reply-3}"); jConfig.setNextStepStatus("active"); } + + + + + + jConfigList.add(jConfig); @@ -284,7 +308,7 @@ public class PlotConstructor extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=unknown", "任务线_" + location + "进度::match-Include=" + parentId, - "match,return-0,post::all(" + CHITCHAT_URL + ")", + "match,return-0,post::gameQA(" + CHITCHAT_URL + ")", " ", " ", "" @@ -401,7 +425,7 @@ public class PlotConstructor extends ElementConstructor { @Override public void postProcessing(List idList, int categoryId){ if (idList.size() != 0) { - jConfig = new JConfig(" ", " ", "activate,post::all(http://simqa.sz.chewrobot.com:28081/game)", "", "unknown4,unknown3,unknown2,unknown1,common_answer", ""); + jConfig = new JConfig(" ", " ", "activate,post::gameQA(http://simqa.sz.chewrobot.com:28081/game)", "", "unknown4,unknown3,unknown2,unknown1,common_answer", ""); jConfig.setNextStepStatus("active"); JSONObject json = jConfig.toJson(this.getConditionDescription()); helper.insertConfigByBotId(botId, json, idList, categoryId); diff --git a/src/processing/ChatCacheController.java b/src/processing/ChatCacheController.java index 2e2deff..c4c35a8 100644 --- a/src/processing/ChatCacheController.java +++ b/src/processing/ChatCacheController.java @@ -14,6 +14,7 @@ import java.sql.SQLException; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.Map; @@ -188,14 +189,44 @@ public class ChatCacheController { try { chatCache = chatCacheMap.get(chatKey); + HashSet startKeySet = new HashSet(){ + { + add("开始"); + add("开始剧情"); + add("继续"); + add("继续剧情"); + } + }; + HashSet restartKeySet = new HashSet(){ + { + add("重新开始"); + } + }; + + if(chatCache == null){ - if(receiveParamters.containsKey("start_options") && (receiveParamters.get("start_options")[0].contains("开始游戏") || - receiveParamters.get("start_options")[0].contains("继续游戏")|| receiveParamters.get("start_options")[0].contains("继续"))) { - chatCache = loadChatCache(chatKey, context, userinfo, loadCacheStatus); + if(receiveParamters.containsKey("start_options")){ + String startKeyword = receiveParamters.get("start_options")[0].split(":", 2)[1]; + + if(startKeySet.contains(startKeyword)) { + chatCache = loadChatCache(chatKey, context, userinfo, loadCacheStatus); + }else { + chatCache = new ChatCache(userinfo); + } }else { chatCache = new ChatCache(userinfo); } chatCacheMap.put(chatKey, chatCache); + } else { + chatCache.setReloading(false); + if(receiveParamters.containsKey("start_options")){ + String startKeyword = receiveParamters.get("start_options")[0].split(":", 2)[1]; + if(startKeySet.contains(startKeyword)) { + chatCache.setReloading(true); + }else if(restartKeySet.contains(startKeyword)){ + chatCache = new ChatCache(userinfo); + } + } } //historyInfoPoint = (Map) context.getAttribute("chat_key+"+userinfo.userName); } catch (Exception e) { diff --git a/src/processing/FormsPoster.java b/src/processing/FormsPoster.java new file mode 100644 index 0000000..76de8b9 --- /dev/null +++ b/src/processing/FormsPoster.java @@ -0,0 +1,222 @@ +package com.qiwu.chatbotbackend.processing; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.qiwu.chatbotbackend.GameEnvironment.GameEnv; +import com.qiwu.chatbotbackend.entity.Condition; +import com.qiwu.chatbotbackend.entity.Solution; +import org.apache.http.message.BasicNameValuePair; + +import java.io.UnsupportedEncodingException; +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class FormsPoster { + + + LogWriter logWriter = null; + + public FormsPoster(LogWriter logWriter) { + this.logWriter = logWriter; + } + + HashSet skipSet = new HashSet() { + { + add("activeList"); + add("currentAction"); + add("lastUpdateTime"); + add("lastReply"); + } + }; + + static String TALKER = "^【(.*?)】"; + + /** + * 提交类型为all时,会把当前信息点和历史信息点都作为post到另一个服务器 + * @param curInfoPoint + * @param historyInfoPoint + * @param ans + * @param URL + * @throws UnsupportedEncodingException + */ + public void postAll(Map curInfoPoint, Map historyInfoPoint, Solution ans, String URL) throws UnsupportedEncodingException { + String key, keyName; + Iterator k_iter = null; + List pairList = new ArrayList(); + + k_iter = curInfoPoint.keySet().iterator(); + while (k_iter.hasNext()) { + key = k_iter.next(); + if (curInfoPoint.get(key) != "") + //infoMap.put(key + "_cur", curInfoPoint.get(key)[0]); + pairList.add(new BasicNameValuePair(key, curInfoPoint.get(key))); + } + + k_iter = historyInfoPoint.keySet().iterator(); + while (k_iter.hasNext()) { + key = k_iter.next(); + if (historyInfoPoint.get(key) != "") + //infoMap.put(key + "_his", historyInfoPoint.get(key)); + if (key.equals("game_step")) + pairList.add(new BasicNameValuePair(key, historyInfoPoint.get(key))); + else if(skipSet.contains(key)){} + else + pairList.add(new BasicNameValuePair(key + "_his", historyInfoPoint.get(key))); + } + + + logWriter.record("提交表单的数据:
" + pairList.toString(), 2); + + JSONObject jobj = MyFunc.postFORM(URL, pairList); + logWriter.record("提交表单接收到的数据:
" + jobj.toJSONString(), 2); + if((Integer)jobj.get("post_status") == 1){ + Iterator kit = jobj.keySet().iterator(); + + while (kit.hasNext()) { + keyName = kit.next(); + if (keyName.equals("process")) { + ans.setNext((String) jobj.get(keyName)); + historyInfoPoint.put("process", (String) jobj.get(keyName)); + } else if (keyName.equals("solution")) { + ans.setAnswer((String) jobj.get(keyName)); + } else if (keyName.equals("status")){ + continue; + } else{ + historyInfoPoint.put(keyName, jobj.getString(keyName)); + } + } + }else { + ans.setAnswer("提交表单出现异常"); + } + + + + + } + + /** + * 提交类型为term时只会提交最佳匹配的配置条目中包含的条件和值 + * @param curInfoPoint + * @param historyInfoPoint + * @param ans + * @param ansCondition + * @param URL + * @throws UnsupportedEncodingException + */ + public void postTerm(Map curInfoPoint, Map historyInfoPoint, Solution ans, Condition ansCondition, String URL) throws UnsupportedEncodingException { + String key, keyName; + Iterator k_iter = null; + List pairList = new ArrayList(); + + pairList.add(new BasicNameValuePair("chat_key", curInfoPoint.get("chat_key"))); + pairList.add(new BasicNameValuePair("action_name", curInfoPoint.get("action_name"))); + pairList.add(new BasicNameValuePair("bot_name", curInfoPoint.get("bot_name"))); + k_iter = ansCondition.currentPremise.keySet().iterator(); + while (k_iter.hasNext()) { + key = k_iter.next().split("::")[0]; + if (curInfoPoint.get(key) != "") + pairList.add(new BasicNameValuePair(key, curInfoPoint.get(key))); + } + + k_iter = ansCondition.historyPremise.keySet().iterator(); + while (k_iter.hasNext()) { + key = k_iter.next().split("::")[0]; + if (historyInfoPoint.get(key) != "") + pairList.add(new BasicNameValuePair(key + "_his", historyInfoPoint.get(key))); + //infoMap.put(key + "_his", historyInfoPoint.get(key)); + } + + logWriter.record("提交表单的数据:
" + pairList.toString(), 2); + + JSONObject jobj = MyFunc.postFORM(URL, pairList); + logWriter.record("提交表单接收到的数据:
" + jobj.toJSONString(), 2); + if((Integer)jobj.get("post_status") == 1){ + Iterator kit = jobj.keySet().iterator(); + + while (kit.hasNext()) { + keyName = kit.next(); + if (keyName.equals("process")) { + ans.setNext((String) jobj.get(keyName)); + historyInfoPoint.put("process", (String) jobj.get(keyName)); + } else if (keyName.equals("solution")) { + ans.setAnswer((String) jobj.get(keyName)); + } else if (keyName.equals("status")){ + continue; + } else{ + historyInfoPoint.put(keyName, jobj.getString(keyName)); + } + } + }else { + ans.setAnswer("提交表单出现异常"); + } + + } + + + /** + * 游戏专用提交表单 + * @param curInfoPoint + * @param historyInfoPoint + * @param ans + * @param gameEnv + * @param worldController + * @param URL + * @throws UnsupportedEncodingException + */ + public void postGameQA(Map curInfoPoint, Map historyInfoPoint, Solution ans,GameEnv gameEnv, WorldController worldController, String URL) throws UnsupportedEncodingException { + String key, keyName; + Iterator k_iter = null; + List pairList = new ArrayList(); + String threshold = "0.9"; + + if (historyInfoPoint.get("qa_threshold") != null) + threshold = historyInfoPoint.get("qa_threshold"); + + pairList.add(new BasicNameValuePair("game_step", historyInfoPoint.get("game_step"))); + pairList.add(new BasicNameValuePair("query_text", curInfoPoint.get("query_text"))); + pairList.add(new BasicNameValuePair("qa_threshold", threshold)); + + logWriter.record("提交表单的数据:
" + pairList.toString(), 2); + + JSONObject jobj = MyFunc.postFORM(URL, pairList); + + logWriter.record("提交表单接收到的数据:
" + jobj.toJSONString(), 2); + + String text,score, site = historyInfoPoint.get("site"), npc; + if((Integer)jobj.get("post_status") == 1){ + if(jobj.getJSONArray("qa_candidates") != null && jobj.get("qa_status").equals("OK")){ + historyInfoPoint.put("common_answer", "未找到匹配"); + historyInfoPoint.put("qa_score", "0"); + List candidates = JSON.toJavaObject(jobj.getJSONArray("qa_candidates"), List.class); + + for(JSONArray pair:candidates){ + List textscore = JSON.toJavaObject(pair, List.class); + + + Pattern findTalker = Pattern.compile(TALKER); + Matcher m = findTalker.matcher(textscore.get(0)); + if(m.find()) { + npc = m.group(1); + if (worldController.worldOperation(gameEnv, "NPC_query", "queryLocationByNPCName:", curInfoPoint, historyInfoPoint).equals(site)){ + historyInfoPoint.put("common_answer", textscore.get(0)); + historyInfoPoint.put("qa_score", textscore.get(1)); + break; + } + } + + + + } + }else{ + historyInfoPoint.put("common_answer", (String)jobj.get("common_answer")); + historyInfoPoint.put("qa_score", "0"); + historyInfoPoint.put("qa_status", (String)jobj.get("qa_status")); + } + }else { + ans.setAnswer("提交表单出现异常"); + } + + } +} diff --git a/src/processing/MyFunc.java b/src/processing/MyFunc.java index edb91d5..7cde103 100644 --- a/src/processing/MyFunc.java +++ b/src/processing/MyFunc.java @@ -21,6 +21,9 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; +import static com.qiwu.chatbotbackend.processing.QuestionMatcher.API_ERROR; +import static com.qiwu.chatbotbackend.processing.QuestionMatcher.POST_ERROR; + public class MyFunc { @@ -107,7 +110,7 @@ public class MyFunc { return true; } - public static JSONObject postJSON(String url, JSONObject data) throws UnsupportedEncodingException { + public static JSONObject postJSON(String url, JSONObject data, String auth) throws UnsupportedEncodingException { JSONObject jobj = new JSONObject(); @@ -125,16 +128,21 @@ public class MyFunc { entity.setContentType("application/json; charset=utf-8"); httpPost.setEntity(entity); + if(auth != null){ + httpPost.setHeader("Authorization", auth); + } + try { HttpResponse resp = client.execute(httpPost); if (resp.getStatusLine().getStatusCode() == 200) { HttpEntity he = resp.getEntity(); respContent = EntityUtils.toString(he, "UTF-8"); jobj = JSONObject.parseObject(respContent); + jobj.put("post_status", 1); } else { - jobj.put("status", 0); - jobj.put("parameter", "修改condition失败"); + jobj.put("post_status", 0); + jobj.put("parameter", "接收请求的程序出现异常"); } } catch (Exception e) { @@ -146,4 +154,42 @@ public class MyFunc { } -} + + + + public static JSONObject postFORM(String url, List pairList) throws UnsupportedEncodingException { + + + HttpPost httpPost = new HttpPost(url); + CloseableHttpClient client = HttpClients.createDefault(); + String respContent = null; + String keyName = null; + + UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairList, "utf-8"); + entity.setContentType("application/x-www-form-urlencoded"); + httpPost.setEntity(entity); + JSONObject jobj = new JSONObject(); + + try { + HttpResponse resp = client.execute(httpPost); + if (resp.getStatusLine().getStatusCode() == 200) { + HttpEntity he = resp.getEntity(); + respContent = EntityUtils.toString(he, "UTF-8"); + jobj = JSONObject.parseObject(respContent); + jobj.put("post_status", 1); + + } else { + jobj.put("post_status", 0); + jobj.put("parameter", "接收请求的程序出现异常"); + } + } catch (Exception e) { + e.printStackTrace(); + + } + + return jobj; + + } + + +} \ No newline at end of file diff --git a/src/processing/QuestionMatcher.java b/src/processing/QuestionMatcher.java index 2d75f16..6e56d07 100644 --- a/src/processing/QuestionMatcher.java +++ b/src/processing/QuestionMatcher.java @@ -50,7 +50,7 @@ public class QuestionMatcher { this.userinfo = userinfo; this.context = context; this.gameEnv = gameEnv; - this.worldController = new WorldController(logWriter); + this.worldController = new WorldController(logWriter, userinfo); } /** @@ -145,6 +145,8 @@ public class QuestionMatcher { curInfoPoint.put(currentAction, i); } + logWriter.record("historyInfoPoint:" + historyInfoPoint.toString(), 1); + return debugFlag; } @@ -921,6 +923,7 @@ public class QuestionMatcher { Map infoMap = new HashMap(); List pairList = new ArrayList(); Iterator k_iter = null; + FormsPoster poster = new FormsPoster(logWriter); HashSet skipSet = new HashSet() { { @@ -935,91 +938,99 @@ public class QuestionMatcher { url = elem[0]; postType = elem[1]; - //提交类型为all时,会把当前信息点和历史信息点都作为post到另一个服务器 - if (postType.equals("all")) { - k_iter = curInfoPoint.keySet().iterator(); - while (k_iter.hasNext()) { - key = k_iter.next(); - if (curInfoPoint.get(key) != "") - //infoMap.put(key + "_cur", curInfoPoint.get(key)[0]); - pairList.add(new BasicNameValuePair(key, curInfoPoint.get(key))); - } - - k_iter = historyInfoPoint.keySet().iterator(); - while (k_iter.hasNext()) { - key = k_iter.next(); - if (historyInfoPoint.get(key) != "") - //infoMap.put(key + "_his", historyInfoPoint.get(key)); - if (key.equals("game_step")) - pairList.add(new BasicNameValuePair(key, historyInfoPoint.get(key))); - else if(skipSet.contains(key)){} - else - pairList.add(new BasicNameValuePair(key + "_his", historyInfoPoint.get(key))); - } - - //提交类型为term时只会提交最佳匹配的配置条目中包含的条件和值 - } else if (postType.equals("term")) { - pairList.add(new BasicNameValuePair("chat_key", curInfoPoint.get("chat_key"))); - pairList.add(new BasicNameValuePair("action_name", curInfoPoint.get("action_name"))); - pairList.add(new BasicNameValuePair("bot_name", curInfoPoint.get("bot_name"))); - k_iter = ansCondition.currentPremise.keySet().iterator(); - while (k_iter.hasNext()) { - key = k_iter.next().split("::")[0]; - if (curInfoPoint.get(key) != "") - pairList.add(new BasicNameValuePair(key, curInfoPoint.get(key))); - } - - k_iter = ansCondition.historyPremise.keySet().iterator(); - while (k_iter.hasNext()) { - key = k_iter.next().split("::")[0]; - if (historyInfoPoint.get(key) != "") - pairList.add(new BasicNameValuePair(key + "_his", historyInfoPoint.get(key))); - //infoMap.put(key + "_his", historyInfoPoint.get(key)); - } - } - - logWriter.record("提交表单的数据:
" + pairList.toString(), 2); - - HttpPost httpPost = new HttpPost(url); - CloseableHttpClient client = HttpClients.createDefault(); - String respContent = null; - String keyName = null; - - - UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairList, "utf-8"); - entity.setContentType("application/x-www-form-urlencoded"); - httpPost.setEntity(entity); - - try { - HttpResponse resp = client.execute(httpPost); - if (resp.getStatusLine().getStatusCode() == 200) { - HttpEntity he = resp.getEntity(); - respContent = EntityUtils.toString(he, "UTF-8"); - logWriter.record("提交表单接收到的数据:
" + respContent, 2); - JSONObject jobj = JSONObject.parseObject(respContent); - Iterator kit = jobj.keySet().iterator(); - - while (kit.hasNext()) { - keyName = kit.next(); - if (keyName.equals("process")) { - ans.setNext((String) jobj.get(keyName)); - historyInfoPoint.put("process", (String) jobj.get(keyName)); - } else if (keyName.equals("solution")) { - ans.setAnswer((String) jobj.get(keyName)); - } else if (keyName.equals("status")){ - continue; - } else{ - historyInfoPoint.put(keyName, jobj.getString(keyName)); - } - } - } else { - ans.setAnswer(API_ERROR); - } - } catch (Exception e) { - e.printStackTrace(); - ans.setAnswer(POST_ERROR + url); - return ans; +// if (postType.equals("all")) { +// k_iter = curInfoPoint.keySet().iterator(); +// while (k_iter.hasNext()) { +// key = k_iter.next(); +// if (curInfoPoint.get(key) != "") +// //infoMap.put(key + "_cur", curInfoPoint.get(key)[0]); +// pairList.add(new BasicNameValuePair(key, curInfoPoint.get(key))); +// } +// +// k_iter = historyInfoPoint.keySet().iterator(); +// while (k_iter.hasNext()) { +// key = k_iter.next(); +// if (historyInfoPoint.get(key) != "") +// //infoMap.put(key + "_his", historyInfoPoint.get(key)); +// if (key.equals("game_step")) +// pairList.add(new BasicNameValuePair(key, historyInfoPoint.get(key))); +// else if(skipSet.contains(key)){} +// else +// pairList.add(new BasicNameValuePair(key + "_his", historyInfoPoint.get(key))); +// } +// + +// } else if (postType.equals("term")) { +// pairList.add(new BasicNameValuePair("chat_key", curInfoPoint.get("chat_key"))); +// pairList.add(new BasicNameValuePair("action_name", curInfoPoint.get("action_name"))); +// pairList.add(new BasicNameValuePair("bot_name", curInfoPoint.get("bot_name"))); +// k_iter = ansCondition.currentPremise.keySet().iterator(); +// while (k_iter.hasNext()) { +// key = k_iter.next().split("::")[0]; +// if (curInfoPoint.get(key) != "") +// pairList.add(new BasicNameValuePair(key, curInfoPoint.get(key))); +// } +// +// k_iter = ansCondition.historyPremise.keySet().iterator(); +// while (k_iter.hasNext()) { +// key = k_iter.next().split("::")[0]; +// if (historyInfoPoint.get(key) != "") +// pairList.add(new BasicNameValuePair(key + "_his", historyInfoPoint.get(key))); +// //infoMap.put(key + "_his", historyInfoPoint.get(key)); +// } +// } +// +// logWriter.record("提交表单的数据:
" + pairList.toString(), 2); +// +// HttpPost httpPost = new HttpPost(url); +// CloseableHttpClient client = HttpClients.createDefault(); +// String respContent = null; +// String keyName = null; +// +// +// UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairList, "utf-8"); +// entity.setContentType("application/x-www-form-urlencoded"); +// httpPost.setEntity(entity); +// +// try { +// HttpResponse resp = client.execute(httpPost); +// if (resp.getStatusLine().getStatusCode() == 200) { +// HttpEntity he = resp.getEntity(); +// respContent = EntityUtils.toString(he, "UTF-8"); +// logWriter.record("提交表单接收到的数据:
" + respContent, 2); +// JSONObject jobj = JSONObject.parseObject(respContent); +// Iterator kit = jobj.keySet().iterator(); +// +// while (kit.hasNext()) { +// keyName = kit.next(); +// if (keyName.equals("process")) { +// ans.setNext((String) jobj.get(keyName)); +// historyInfoPoint.put("process", (String) jobj.get(keyName)); +// } else if (keyName.equals("solution")) { +// ans.setAnswer((String) jobj.get(keyName)); +// } else if (keyName.equals("status")){ +// continue; +// } else{ +// historyInfoPoint.put(keyName, jobj.getString(keyName)); +// } +// } +// } else { +// ans.setAnswer(API_ERROR); +// } +// } catch (Exception e) { +// e.printStackTrace(); +// +// ans.setAnswer(POST_ERROR + url); +// return ans; +// } + + if(postType.equals("all")){ + poster.postAll(curInfoPoint, historyInfoPoint, ans, url); + }else if(postType.equals("term")){ + poster.postTerm(curInfoPoint, historyInfoPoint, ans, ansCondition, url); + }else if(postType.equals("gameQA")){ + poster.postGameQA(curInfoPoint, historyInfoPoint, ans, gameEnv, worldController, url); } return ans; diff --git a/src/processing/WorldController.java b/src/processing/WorldController.java index d6dd61f..11aeb9b 100644 --- a/src/processing/WorldController.java +++ b/src/processing/WorldController.java @@ -2,6 +2,7 @@ package com.qiwu.chatbotbackend.processing; import com.qiwu.chatbotbackend.GameEnvironment.GameEnv; +import com.qiwu.chatbotbackend.entity.UserInfo; import java.util.ArrayList; import java.util.List; @@ -9,9 +10,11 @@ import java.util.Map; public class WorldController { public LogWriter logWriter = null; + public UserInfo userInfo = null; - public WorldController(LogWriter logWriter) { + public WorldController(LogWriter logWriter, UserInfo userInfo) { this.logWriter = logWriter; + this.userInfo = userInfo; } public String worldOperation(GameEnv gameEnv, String varName, String varValue, Map currentInfoPoint, MaphistoryInfoPoint){ @@ -75,126 +78,169 @@ public class WorldController { break; case "queryAttrByNPCName": - + //根据condition的名字,从当前信息点中获取npc的名字 subValuePair = currentInfoPoint.get(valuePair[1]).split(":", 2); subValuePair[0] = subValuePair[0].replace("哪里", "location"); returnStr = gameEnv.queryNpcAttrByNpcName(subValuePair[0], subValuePair[1]); if(returnStr == null) returnStr = "无"; break; + case "queryLocationByNPCName": + // + returnStr = gameEnv.queryNpcAttrByNpcName(valuePair[1], "location"); + if(returnStr == null) + returnStr = "无"; + break; default: } }else if (varName.startsWith("map_")) { + String format = ""; List sites = new ArrayList<>(); + switch (valuePair[0]) { case "queryAroundAllBySite": + if(userInfo.varInitialMap.containsKey("AROUND_THINGS")) { + format = userInfo.varInitialMap.get("AROUND_THINGS"); + }else { + format = "有%s"; + } + + sites = gameEnv.queryAroundAllBySite(historyInfoPoint.get("site")); if(sites == null || sites.size() == 0) - returnStr = "啥都没有"; + returnStr = "什么都没有"; else { - returnStr = "有"; - if(sites.size() > 0) { - for (String site : sites) - returnStr += "、" + site; - }else{ - returnStr = "啥都没有"; + + StringBuffer text = new StringBuffer(); + + for(String site:sites){ + text.append("、" + site); } + + returnStr = String.format(format, text.substring(1)); } break; case "queryAroundNpcBySite": + if(userInfo.varInitialMap.containsKey("AROUND_PEOPLE")) { + format = userInfo.varInitialMap.get("AROUND_PEOPLE"); + }else { + format = "有%s"; + } + + sites = gameEnv.queryAroundNpcBySite(historyInfoPoint.get("site")); if(sites == null || sites.size() == 0) - returnStr = "啥都没有"; + returnStr = "什么都没有"; else { - returnStr = "有"; - if(sites.size() > 0) { - for (String site : sites) - returnStr += "、" + site; - }else{ - returnStr = "啥都没有"; + + StringBuffer text = new StringBuffer(); + + for(String site:sites){ + text.append("、" + site); } + + returnStr = String.format(format, text.substring(1)); } break; case "queryAroundGoodsBySite": + + if(userInfo.varInitialMap.containsKey("AROUND_ITEMS")) { + format = userInfo.varInitialMap.get("AROUND_ITEMS"); + }else { + format = "有%s"; + } + sites = gameEnv.queryAroundGoodsBySite(historyInfoPoint.get("site")); if(sites == null || sites.size() == 0) - returnStr = "啥都没有"; + returnStr = "什么都没有"; else { - returnStr = "有"; if(sites.size() > 0) { - for (String site : sites) - returnStr += "、" + site; - }else{ - returnStr = "啥都没有"; + StringBuffer text = new StringBuffer(); + + for(String site:sites){ + text.append("、" + site); + } + returnStr = String.format(format, text.substring(1)); } } break; case "queryCanGoBySite": - if(!currentInfoPoint.containsKey(valuePair[1])) { - returnStr = "不可到达"; - break; + + if(userInfo.varInitialMap.containsKey("CAN_GO_SITES")) { + format = userInfo.varInitialMap.get("CAN_GO_SITES"); + }else { + format = "可以去%s"; } + sites = gameEnv.queryCanGoBySite(historyInfoPoint.get("site")); if(sites == null) { - returnStr = "没什么地方可去的,继续玩吧"; + returnStr = userInfo.varInitialMap.get("CAN_GO_NOWHERE"); } else if(sites.size() == 0){ - returnStr = "没什么地方可去的,继续玩吧"; + returnStr = userInfo.varInitialMap.get("CAN_GO_NOWHERE"); } else { - returnStr = "可以去"; if(sites.size() > 0) { - for (String site : sites) - returnStr += "、" + site; - System.out.println("returnStr" + returnStr); - }else{ - returnStr = "没什么地方可去的,继续玩吧"; + StringBuffer text = new StringBuffer(); + + for(String site:sites){ + text.append("、" + site); + } + returnStr = String.format(format, text.substring(1)); } } break; + case "queryHowToPathBySite": + if(userInfo.varInitialMap.containsKey("PATH_EXIST")) { + format = userInfo.varInitialMap.get("PATH_EXIST"); + }else { + format = "通过%s可以到达"; + } + if(!currentInfoPoint.containsKey(valuePair[1])) { - returnStr = "不可到达"; + returnStr = userInfo.varInitialMap.get("PATH_NOT_EXIST"); break; } sites = gameEnv.queryPathBySite(historyInfoPoint.get("site"), currentInfoPoint.get(valuePair[1]).split(":")[1]); if(sites == null) { - returnStr = "不可到达"; + returnStr = userInfo.varInitialMap.get("PATH_NOT_EXIST"); } - else if(sites.size() == 0){ - returnStr = "就在附近哦"; - }else { - returnStr = "通过"; + else { if(sites.size() > 0) { - for (String site : sites) - returnStr += "、" + site; - returnStr += "可以到达"; - }else{ - returnStr = "就在附近哦"; + StringBuffer text = new StringBuffer(); + + for(String site:sites){ + text.append("、" + site); + } + returnStr = String.format(format, text.substring(1)); } } break; case "queryToDoPathBySite": + if(userInfo.varInitialMap.containsKey("SITE_NOT_ADJOINT")) { + format = userInfo.varInitialMap.get("SITE_NOT_ADJOINT"); + }else { + format = "通过%s可以到达"; + } + if(!currentInfoPoint.containsKey(valuePair[1])) { - returnStr = "不可到达"; + returnStr = userInfo.varInitialMap.get("PATH_NOT_EXIST"); break; } sites = gameEnv.queryPathBySite(historyInfoPoint.get("site"), currentInfoPoint.get(valuePair[1]).split(":")[1]); if(sites == null) { - returnStr = "不可到达"; - } - else if(sites.size() == 0){ - returnStr = "就在附近哦"; - }else { - returnStr = "通过"; + returnStr = userInfo.varInitialMap.get("PATH_NOT_EXIST"); + } else { if(sites.size() > 0) { - for (String site : sites) - returnStr += "、" + site; - returnStr += "可以到达"; - }else{ - returnStr = "就在附近哦"; + StringBuffer text = new StringBuffer(); + + for(String site:sites){ + text.append("、" + site); + } + returnStr = String.format(format, text.substring(1)); } } break; diff --git a/src/servlet/GameDesignServlet.java b/src/servlet/GameDesignServlet.java index dbeccfa..032caef 100644 --- a/src/servlet/GameDesignServlet.java +++ b/src/servlet/GameDesignServlet.java @@ -39,6 +39,14 @@ public class GameDesignServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + Enumeration enum1 = request.getHeaderNames(); + + + while(enum1.hasMoreElements()) { + System.out.println(enum1.nextElement()); + + } + //所有需要修改的词性 StringBuffer POS = new StringBuffer(); @@ -75,6 +83,7 @@ public class GameDesignServlet extends HttpServlet { JSONObject gameElements = helper.queryGameElementsByBotId(dataId); + gameElements.put("auth", request.getHeader("authorization")); System.out.println(gameElements.toJSONString()); botId = (Integer)gameElements.get("botId"); botAccount = (String) gameElements.get("botAccount"); @@ -82,7 +91,6 @@ public class GameDesignServlet extends HttpServlet { - System.out.println("botId:" + botId + ",botAccount:" + botAccount); //假设重建用户信息 if (context.getAttribute(botAccount) == null) { @@ -243,8 +251,9 @@ public class GameDesignServlet extends HttpServlet { actionPostData.put("botName", botName); actionPostData.put("botId", (Integer)gameElements.get("botId")); actionPostData.put("type", "game_plot_init"); - actionPostData.put("welcome", "欢迎来到" + (String)gameElements.get("botName") + ",请说开始游戏或者继续游戏"); + actionPostData.put("welcome", "欢迎来到" + (String)gameElements.get("botName") + ",请说开始剧情或者重新开始"); actionPostData.put("relationKeywords", relationKeywords); + actionPostData.put("auth", gameElements.get("auth")); if (gameElements.containsKey("POS")) @@ -257,7 +266,7 @@ public class GameDesignServlet extends HttpServlet { userInfo.extraInfo.put("activeAction", startCondition); try { - returnMessage = MyFunc.postJSON(POST_URL, actionPostData); + returnMessage = MyFunc.postJSON(POST_URL, actionPostData, (String)gameElements.get("auth")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } diff --git a/src/servlet/GetAnswerServlet.java b/src/servlet/GetAnswerServlet.java index 362cb58..a5d1a63 100644 --- a/src/servlet/GetAnswerServlet.java +++ b/src/servlet/GetAnswerServlet.java @@ -35,7 +35,10 @@ public class GetAnswerServlet extends HttpServlet { String ansJ = "", return_str = "", state = "", chatKey = ""; String botName = receiveParamters.get("bot_name")[0]; - chatKey = receiveParamters.get("chat_key")[0].split("@")[0]; + if(!receiveParamters.get("chat_key")[0].startsWith("@")) + chatKey = receiveParamters.get("chat_key")[0].split("@")[0]; + else + chatKey = receiveParamters.get("chat_key")[0]; receiveParamters.get("chat_key")[0] = chatKey; OutputStream out = response.getOutputStream();