diff --git a/.project b/.project index 9153394b..7c49f5fd 100755 --- a/.project +++ b/.project @@ -5,6 +5,11 @@ + + org.eclipse.buildship.core.gradleprojectbuilder + + + org.eclipse.jdt.core.javabuilder @@ -13,6 +18,7 @@ org.eclipse.jdt.core.javanature + org.eclipse.buildship.core.gradleprojectnature diff --git a/Dockerfile b/Dockerfile index 6dcc9658..6fe0c19f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM openjdk:14-jdk-alpine +FROM openjdk:17-jdk-alpine ENV LAS2PEER_PORT=9011 ENV DATABASE_NAME=SBF diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 0cd2b3a9..e21be66a 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -84,7 +84,7 @@ fi # prevent glob expansion in lib/* set -f -LAUNCH_COMMAND='java -cp lib/* i5.las2peer.tools.L2pNodeLauncher -s service -p '"${LAS2PEER_PORT} ${SERVICE_EXTRA_ARGS}" +LAUNCH_COMMAND='java -cp lib/* --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED i5.las2peer.tools.L2pNodeLauncher -s service -p '"${LAS2PEER_PORT} ${SERVICE_EXTRA_ARGS}" if [[ ! -z "${BOOTSTRAP}" ]]; then LAUNCH_COMMAND="${LAUNCH_COMMAND} -b ${BOOTSTRAP}" fi diff --git a/gradle.properties b/gradle.properties index b1ac41c3..d98ad0cc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,8 +1,8 @@ -core.version=1.1.2 +core.version=1.2.0 service.name=i5.las2peer.services.socialBotManagerService service.class=SocialBotManagerService service.version=1.0.0 -java.version=14 +java.version=17 las2peer_user1.name=alice las2peer_user1.password=pwalice diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 12d38de6..ffed3a25 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/social-bot-manager/build.gradle b/social-bot-manager/build.gradle index ae6cf2ba..6b91b4fc 100644 --- a/social-bot-manager/build.gradle +++ b/social-bot-manager/build.gradle @@ -6,12 +6,16 @@ plugins { repositories { // Use JCenter for resolving dependencies. - jcenter() + mavenCentral() // DBIS Archiva maven { url "https://archiva.dbis.rwth-aachen.de:9911/repository/internal/" } + + maven { + url "https://archiva.dbis.rwth-aachen.de:9911/repository/snapshots/" + } } dependencies { @@ -20,7 +24,7 @@ dependencies { // las2peer bundle which is not necessary in the runtime path // compileOnly will be moved into the lib dir afterwards - compileOnly "i5:las2peer-bundle:${project.property('core.version')}" + implementation "i5:las2peer-bundle:${project.property('core.version')}" // Add service dependencies here // example: @@ -48,7 +52,7 @@ dependencies { configurations { // This ensures las2peer is available in the tests, but won't be bundled - testCompile.extendsFrom compileOnly + testImplementation.extendsFrom implementation } jar { @@ -72,14 +76,15 @@ application { archivesBaseName = group version = "${project.property('service.version')}" - mainClassName = "i5.las2peer.tools.L2pNodeLauncher" + mainClass.set("i5.las2peer.tools.L2pNodeLauncher") sourceCompatibility = "${project.property('java.version')}" targetCompatibility = "${project.property('java.version')}" } // put all .jar files into export/jars folder tasks.withType(Jar) { - destinationDir = file("$projectDir/export/jars") + duplicatesStrategy = 'include' + destinationDirectory = file("$projectDir/export/jars") } javadoc { @@ -130,7 +135,7 @@ task startscripts { # this script is autogenerated by 'gradle startscripts' # it starts a las2peer node providing the service '${project.property('service.name')}.${project.property('service.class')}' of this project # pls execute it from the root folder of your deployment, e. g. ./bin/start_network.sh -java -cp "lib/*" i5.las2peer.tools.L2pNodeLauncher --port 9011 --service-directory service uploadStartupDirectory startService\\(\\'${project.property('service.name')}.${project.property('service.class')}@${project.property('service.version')}\\'\\) startWebConnector interactive +java -cp "lib/*" --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED i5.las2peer.tools.L2pNodeLauncher --port 9011 --service-directory service uploadStartupDirectory startService\\(\\'${project.property('service.name')}.${project.property('service.class')}@${project.property('service.version')}\\'\\) startWebConnector interactive """ new File("$rootDir/bin", "start_network.bat").text = """:: this script is autogenerated by 'gradle startscripts' :: it starts a las2peer node providing the service '${project.property('service.name')}.${project.property('service.class')}' of this project @@ -140,7 +145,9 @@ cd %~p0 cd .. set BASE=%CD% set CLASSPATH="%BASE%/lib/*;" -java -cp %CLASSPATH% i5.las2peer.tools.L2pNodeLauncher --port 9011 --service-directory service uploadStartupDirectory startService('${project.property('service.name')}.${project.property('service.class')}@${project.property('service.version')}') startWebConnector interactive +set L2P_JAR_PATH="%BASE%/lib/las2peer-bundle-${project.property('core.version')}.jar" + +java -cp %CLASSPATH% -jar %L2P_JAR_PATH% --port 9011 --service-directory service uploadStartupDirectory startService('${project.property('service.name')}.${project.property('service.class')}@${project.property('service.version')}') startWebConnector interactive pause """ } @@ -256,20 +263,4 @@ test { // Only required when using Eclipse: // configuration for eclipse (this allows to import the project as a gradle project in eclipse without any problems) -eclipse { - classpath { - file { - whenMerged { - // change output directory for test, main, resources and default - def main = entries.find { it.path == "src/main/java" } - main.output = "output/main" - - def test = entries.find { it.path == "src/test/java" } - test.output = "output/test" - - def defaultEntry = entries.find { it.kind == "output" && it.path == "bin/default" } - defaultEntry.path = "output/default" - } - } - } -} \ No newline at end of file +// \ No newline at end of file diff --git a/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/SocialBotManagerService.java b/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/SocialBotManagerService.java index 35e9f0ba..f25b87fc 100644 --- a/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/SocialBotManagerService.java +++ b/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/SocialBotManagerService.java @@ -1540,7 +1540,7 @@ public void triggerChat(ChatMediator chat, JSONObject body) { channel = chat.getChannelByEmail(email); } System.out.println(channel); - if (text != null) { + if (text != null && !body.containsKey("fileBody")) { chat.sendMessageToChannel(channel, text); } if (body.containsKey("blocks")) { @@ -1548,8 +1548,13 @@ public void triggerChat(ChatMediator chat, JSONObject body) { chat.sendBlocksMessageToChannel(channel, blocks); } if (body.containsKey("fileBody")) { + if (text == null){ + + text = "" ; + } + System.out.println("text is sss" + text); chat.sendFileMessageToChannel(channel, body.getAsString("fileBody"), body.getAsString("fileName"), - body.getAsString("fileType"), ""); + body.getAsString("fileType"), text); } } } @@ -2210,9 +2215,13 @@ public static String encryptThisString(String input) { String hashtext = no.toString(16); // Add preceding 0s to make it 32 bit - while (hashtext.length() < 32) { + try{ + while (hashtext.getBytes("UTF-16BE").length * 8 < 1536) { hashtext = "0" + hashtext; } + } catch (Exception e){ + System.out.println(e); + } // return the HashText return hashtext; diff --git a/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/chat/ChatMediator.java b/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/chat/ChatMediator.java index 80767fd3..834dff0a 100644 --- a/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/chat/ChatMediator.java +++ b/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/chat/ChatMediator.java @@ -112,8 +112,8 @@ public void sendFileMessageToChannel(String channel, String fileBody, String fil * @param fileType Type of the file to be generated * @param text Text to be sent with file */ - public void sendFileMessageToChannel(String channel, String fileBody, String fileName, String text, - String fileType) { + public void sendFileMessageToChannel(String channel, String fileBody, String fileName, String fileType, + String text) { sendFileMessageToChannel(channel, fileBody, fileName, fileType, text, Optional.empty()); } diff --git a/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/chat/RocketChatMediator.java b/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/chat/RocketChatMediator.java index 01afe830..43beaf4a 100644 --- a/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/chat/RocketChatMediator.java +++ b/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/chat/RocketChatMediator.java @@ -148,7 +148,7 @@ public void sendFileMessageToChannel(String channel, File f, String text, Option } @Override - public void sendFileMessageToChannel(String channel, String fileBody, String fileName, String text, String fileType, + public void sendFileMessageToChannel(String channel, String fileBody, String fileName, String fileType, String text, Optional id) { byte[] decodedBytes = java.util.Base64.getDecoder().decode(fileBody); File file = new File(fileName + "." + fileType); diff --git a/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/chat/RocketChatMessageCollector.java b/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/chat/RocketChatMessageCollector.java index ff18708c..91a25241 100644 --- a/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/chat/RocketChatMessageCollector.java +++ b/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/chat/RocketChatMessageCollector.java @@ -76,6 +76,9 @@ public void handle(RocketChatMessage message, int role, String email) { String user = message.getSender().getUserName(); String msg = replaceUmlaute(message.getMessage()); ChatMessage cm = new ChatMessage(rid, user, msg); + System.out.println("Email of user is " + email); + cm.setEmail(email); + cm.setRole(role); // timestamp cm.setTime(message.getMsgTimestamp().toInstant().toString()); // domain diff --git a/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/chat/SlackChatMediator.java b/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/chat/SlackChatMediator.java index 7d937fd7..e2f4b92e 100644 --- a/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/chat/SlackChatMediator.java +++ b/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/chat/SlackChatMediator.java @@ -375,8 +375,8 @@ public void sendFileMessageToChannel(String channel, File f, String text, Option FilesUploadResponse response2; try { response2 = slack.methods(authToken).filesUpload(req -> req.channels(channels).file(f) - .content("Pretty stuff").filename(f.getName()).title(f.getName())); - System.out.println("File sent: " + response2.isOk()); + .content("Pretty stuff").filename(f.getName()).title(f.getName()).initialComment(text)); + System.out.println("File sent: " + response2.isOk() + text); } catch (IOException | SlackApiException e) { // TODO Auto-generated catch block e.printStackTrace(); diff --git a/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/chat/TelegramChatMediator.java b/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/chat/TelegramChatMediator.java index 47a09231..81315b04 100644 --- a/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/chat/TelegramChatMediator.java +++ b/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/chat/TelegramChatMediator.java @@ -197,7 +197,7 @@ public void sendMessageToChannel(String channel, String text, Optional i @Override public void sendFileMessageToChannel(String channel, String fileBody, String fileName, String fileType, String text, Optional id) { - String caption = ""; + String caption = text; System.out.println("Send File to Telegram channel: " + channel); try { diff --git a/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/model/IncomingMessage.java b/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/model/IncomingMessage.java index 857b603f..66ed50c7 100644 --- a/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/model/IncomingMessage.java +++ b/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/model/IncomingMessage.java @@ -37,10 +37,13 @@ public static String replaceUmlaute(String orig) { public IncomingMessage(String intent, String NluID, Boolean containsFile) { if(intent != "") { this.intentKeyword = replaceUmlaute(intent); - } else intent = ""; + } else intentKeyword = ""; this.followupMessages = new HashMap(); this.responses = new ArrayList(); this.containsFile = containsFile; + if (intentKeyword.equals("0") && containsFile){ + intentKeyword = "anyFile"; + } if(NluID == ""){ this.NluID = ""; } else this.NluID = NluID; @@ -69,7 +72,11 @@ public HashMap getFollowingMessages() { public void addFollowupMessage(String intentKeyword, IncomingMessage msg) { String[] intentList = intentKeyword.split(","); for (String intent : intentList) { - this.followupMessages.put(replaceUmlaute(intent).replaceAll("\\s+", ""), msg); + if (intent.equals("") && msg.containsFile){ + this.followupMessages.put(replaceUmlaute(intent).replaceAll("\\s+", "") + "anyFile", msg); + } else { + this.followupMessages.put(replaceUmlaute(intent).replaceAll("\\s+", ""), msg); + } } // (this.followupMessages.put(replaceUmlaute(intentKeyword), msg); } diff --git a/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/model/Messenger.java b/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/model/Messenger.java index 232c5ed3..636aa4a3 100644 --- a/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/model/Messenger.java +++ b/social-bot-manager/src/main/java/i5/las2peer/services/socialBotManagerService/model/Messenger.java @@ -182,8 +182,15 @@ public void setContextToBasic(String channel, String userid) { } } else { // If only message to be sent - this.chatMediator.sendMessageToChannel(channel, state.getResponse(random).getResponse(), - Optional.of(userid)); + String response = state.getResponse(random).getResponse(); + if( response != null && !response.equals("")) + { + this.chatMediator.sendMessageToChannel(channel, response, Optional.of(userid)); + } + if(state.getFollowingMessages().size()== 0){ + this.stateMap.remove(channel); + + } } } else { } @@ -295,9 +302,8 @@ public void handleMessages(ArrayList messageInfos, Bot bot) { && this.knownIntents.get(intent.getKeyword()).expectsFile()) { state = this.knownIntents.get(intent.getKeyword()); // get("0") refers to an empty intent that is accessible from the start state - } else if (this.knownIntents.get("0") != null - && this.knownIntents.get("0").expectsFile()) { - state = this.knownIntents.get("0"); + } else if (this.knownIntents.get("anyFile") != null) { + state = this.knownIntents.get("anyFile"); } else { state = this.knownIntents.get("default"); } @@ -308,8 +314,12 @@ public void handleMessages(ArrayList messageInfos, Bot bot) { // Incoming Message which expects file should not be chosen when no file was // sent if (state == null || state.expectsFile()) { + if(this.knownIntents.get("0") != null){ + state = this.knownIntents.get("0"); + } else{ state = this.knownIntents.get("default"); } + } System.out.println(intent.getKeyword() + " detected with " + intent.getConfidence() + " confidence."); stateMap.put(message.getChannel(), state); @@ -359,17 +369,18 @@ public void handleMessages(ArrayList messageInfos, Bot bot) { addEntityToRecognizedList(message.getChannel(), intent.getEntities()); // In a conversation state, if no fitting intent was found and an empty leadsTo // label is found - } else if (state.getFollowingMessages().get("") != null) { - System.out.println("Empty leadsTo1"); - if (message.getFileBody() != null) { - if (state.getFollowingMessages().get("").expectsFile()) { - state = state.getFollowingMessages().get(""); + } else if(state.getFollowingMessages().get("") != null || state.getFollowingMessages().get("anyFile") != null){ + if (message.getFileBody() != null ) { + if (state.getFollowingMessages().get("anyFile") != null) { + state = state.getFollowingMessages().get("anyFile"); + stateMap.put(message.getChannel(), state); + addEntityToRecognizedList(message.getChannel(), intent.getEntities()); } else { state = this.knownIntents.get("default"); } } else { - if (!state.getFollowingMessages().get("").expectsFile()) { + if (state.getFollowingMessages().get("") != null) { state = state.getFollowingMessages().get(""); stateMap.put(message.getChannel(), state); addEntityToRecognizedList(message.getChannel(), intent.getEntities());