3838import net .b07z .sepia .server .core .tools .Converters ;
3939import net .b07z .sepia .server .core .tools .DateTime ;
4040import net .b07z .sepia .server .core .tools .Debugger ;
41+ import net .b07z .sepia .server .core .tools .Is ;
4142import net .b07z .sepia .server .core .tools .JSON ;
4243import net .b07z .sepia .server .core .tools .Timer ;
4344import 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