Skip to content

Commit 5522586

Browse files
committed
update to v2.0.2 with support for data-field/buttons in commands
1 parent c2a488e commit 5522586

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>net.b07z.sepia.server.teach</groupId>
44
<artifactId>sepia-teach-API</artifactId>
5-
<version>2.0.1</version>
5+
<version>2.0.2</version>
66
<name>SEPIA Teach APIs</name>
77
<description>SEPIA APIs to teach the assistant and manage user and community contributions</description>
88

src/main/java/net/b07z/sepia/server/teach/database/Elasticsearch.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ public JSONArray getAllPersonalCommands(HashMap<String, Object> filters) {
391391
long from = Converters.obj2LongOrDefault(filters.get("from"), -1l); if (from == -1) from = 0;
392392
String userId = (String) filters.get("userId");
393393
String language = (filters.containsKey("language"))? (String) filters.get("language") : "";
394+
boolean with_button_only = filters.containsKey("button"); //Note: we don't actually check the value, if its there its true!
394395

395396
//build a nested query
396397
String nestPath = "sentences";
@@ -399,6 +400,9 @@ public JSONArray getAllPersonalCommands(HashMap<String, Object> filters) {
399400
if (!language.isEmpty()){
400401
nestedMatches.add(new QueryElement(nestPath + ".language", language));
401402
}
403+
if (with_button_only){
404+
nestedMatches.add(new QueryElement(nestPath + ".data.show_button", true));
405+
}
402406
JSONObject queryJson = EsQueryBuilder.getNestedBoolMustMatch(nestPath, nestedMatches);
403407
JSON.put(queryJson, "from", from);
404408

src/main/java/net/b07z/sepia/server/teach/server/Config.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public final class Config {
2020
public static final String SERVERNAME = "SEPIA-Teach-API"; //public server name
2121
public static String localName = "sepia-teach-server"; //**user defined local server name
2222
public static String localSecret = "123456"; //**user defined secret to validate local server
23-
public static final String apiVersion = "v2.0.1"; //API version
23+
public static final String apiVersion = "v2.0.2"; //API version
2424
public static String privacyPolicyLink = ""; //Link to privacy policy
2525

2626
//helper for dynamic class creation

src/main/java/net/b07z/sepia/server/teach/server/Start.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import net.b07z.sepia.server.core.tools.Converters;
3939
import net.b07z.sepia.server.core.tools.DateTime;
4040
import net.b07z.sepia.server.core.tools.Debugger;
41+
import net.b07z.sepia.server.core.tools.Is;
4142
import net.b07z.sepia.server.core.tools.JSON;
4243
import net.b07z.sepia.server.core.tools.Timer;
4344
import net.b07z.sepia.server.core.users.Account;
@@ -574,11 +575,19 @@ static String submitPersonalCommand(Request request, Response response) {
574575
if ((cmdSummary == null || cmdSummary.isEmpty()) && (paramsJson != null && !paramsJson.isEmpty())){
575576
cmdSummary = Converters.makeCommandSummary(command, paramsJson);
576577
}
577-
String userLocation = params.getString("user_location");
578+
String userLocation = params.getString("user_location"); //TODO: The client should keeps this as detailed or vague as required
578579
String[] repliesArr = params.getStringArray("reply");
579580
List<String> replies = repliesArr == null ? new ArrayList<>() : Arrays.asList(repliesArr);
581+
//custom button data and stuff
582+
JSONObject dataJson;
583+
String dataJsonString = params.getString("data");
584+
if (Is.notNullOrEmpty(dataJsonString)){
585+
dataJson = JSON.parseString(dataJsonString);
586+
}else{
587+
dataJson = new JSONObject(); //NOTE: If no data is submitted it will kill all previous data info (anyway the whole object is overwritten)
588+
}
580589

581-
//build sentence
590+
//build sentence - Note: Commands support sentence arrays but we use only one entry
582591
List<Command.Sentence> sentenceList = new ArrayList<>();
583592
Command.Sentence sentenceObj = new SentenceBuilder(sentence, account.getUserID(), "community") //TODO: add user role check to switch from "community" to "developer"?
584593
.setLanguage(Language.valueOf(language.name().toUpperCase()))
@@ -590,6 +599,7 @@ static String submitPersonalCommand(Request request, Response response) {
590599
.setExplicit(isExplicit)
591600
.setEnvironment(environment)
592601
.setUserLocation(userLocation)
602+
.setData(dataJson)
593603
//TODO: keep it or remove it? The general answers should be stored in an index called "answers"
594604
//and the connector is the command. For chats, custom answers are inside parameter "reply". But I think its still useful here ...
595605
.setReplies(new ArrayList<>(replies))
@@ -679,10 +689,14 @@ static String getAllPersonalCommands(Request request, Response response){
679689
}
680690
String language = getOrDefault("language", userAccount.getPreferredLanguage(), params);
681691
String from = getOrDefault("from", "0", params);
692+
String with_button_only = getOrDefault("button", null, params);
682693
HashMap<String, Object> filters = new HashMap<>();
683694
filters.put("userId", userAccount.getUserID());
684695
filters.put("language", language);
685696
filters.put("from", from);
697+
if (with_button_only != null){
698+
filters.put("button", true); //Its either true or not included
699+
}
686700

687701
TeachDatabase db = getDatabase();
688702
JSONArray output = db.getAllPersonalCommands(filters);

0 commit comments

Comments
 (0)