|
2 | 2 |
|
3 | 3 | import java.util.TreeSet; |
4 | 4 |
|
| 5 | +import org.json.simple.JSONArray; |
5 | 6 | import org.json.simple.JSONObject; |
6 | 7 |
|
7 | 8 | import net.b07z.sepia.server.assist.answers.Answers; |
|
10 | 11 | import net.b07z.sepia.server.assist.data.Parameter; |
11 | 12 | import net.b07z.sepia.server.assist.interpreters.NluResult; |
12 | 13 | import net.b07z.sepia.server.assist.interviews.InterviewData; |
| 14 | +import net.b07z.sepia.server.assist.services.ServiceAccessManager; |
13 | 15 | import net.b07z.sepia.server.assist.services.ServiceBuilder; |
14 | 16 | import net.b07z.sepia.server.assist.services.ServiceInfo; |
15 | 17 | import net.b07z.sepia.server.assist.services.ServiceInterface; |
@@ -150,6 +152,11 @@ public ServiceResult getResult(NluResult nluResult) { |
150 | 152 | getInfoFreshOrCache(nluResult.input, this.getClass().getCanonicalName()), |
151 | 153 | getAnswersPool(nluResult.language)); |
152 | 154 |
|
| 155 | + //test-load stored data |
| 156 | + ServiceAccessManager sam0 = new ServiceAccessManager("demokey"); |
| 157 | + JSONObject userData = api.readServiceDataForUser(sam0, "tasks"); |
| 158 | + System.out.println("result: " + userData); |
| 159 | + |
153 | 160 | //get optional parameters: |
154 | 161 |
|
155 | 162 | //-time |
@@ -178,39 +185,48 @@ public ServiceResult getResult(NluResult nluResult) { |
178 | 185 |
|
179 | 186 | //Schedule intervals |
180 | 187 | if (nluResult.input.isDuplexConnection()){ |
| 188 | + //Some info about the connection and message: |
181 | 189 | //System.out.println(nluResult.input.connection); |
182 | 190 | //System.out.println(nluResult.input.msgId); |
183 | 191 | //System.out.println(nluResult.input.duplexData); |
| 192 | + |
| 193 | + //Collect tasks |
| 194 | + JSONArray tasksArray = new JSONArray(); |
184 | 195 | //Finish |
185 | | - api.runInBackground(timeMinutes * 60 * 1000, () -> { |
| 196 | + JSON.add(tasksArray, api.runOnceInBackground(timeMinutes * 60 * 1000, () -> { |
186 | 197 | //initialize follow-up result |
187 | 198 | ServiceBuilder service = new ServiceBuilder(nluResult); |
188 | 199 | service.answer = Answers.getAnswerString(nluResult, followUpFinish); |
189 | 200 | service.status = "success"; |
190 | 201 | /*boolean wasSent =*/ service.sendFollowUpMessage(nluResult.input, service.buildResult()); |
191 | 202 | return; |
192 | | - }); |
| 203 | + }).getJson()); |
193 | 204 | //Interval minutes |
194 | 205 | if (halfTimeMinutes >= 2){ |
195 | | - api.runInBackground(halfTimeMinutes * 60 * 1000, () -> { |
| 206 | + JSON.add(tasksArray, api.runOnceInBackground(halfTimeMinutes * 60 * 1000, () -> { |
196 | 207 | //initialize follow-up result |
197 | 208 | ServiceBuilder service = new ServiceBuilder(nluResult); |
198 | 209 | service.answer = Answers.getAnswerString(nluResult, followUpIntervalMinutes, halfTimeMinutes); |
199 | 210 | service.status = "success"; |
200 | 211 | /*boolean wasSent =*/ service.sendFollowUpMessage(nluResult.input, service.buildResult()); |
201 | 212 | return; |
202 | | - }); |
| 213 | + }).getJson()); |
203 | 214 | } |
204 | 215 | //Interval 30s seconds |
205 | 216 | long seconds = 30; |
206 | | - api.runInBackground((timeMinutes * 60 * 1000) - (seconds * 1000), () -> { |
| 217 | + JSON.add(tasksArray, api.runOnceInBackground((timeMinutes * 60 * 1000) - (seconds * 1000), () -> { |
207 | 218 | //initialize follow-up result |
208 | 219 | ServiceBuilder service = new ServiceBuilder(nluResult); |
209 | 220 | service.answer = Answers.getAnswerString(nluResult, followUpIntervalSeconds, seconds); |
210 | 221 | service.status = "success"; |
211 | 222 | /*boolean wasSent =*/ service.sendFollowUpMessage(nluResult.input, service.buildResult()); |
212 | 223 | return; |
213 | | - }); |
| 224 | + }).getJson()); |
| 225 | + |
| 226 | + //Store task info for later access in service-specific storage - overwrite old if any |
| 227 | + ServiceAccessManager sam = new ServiceAccessManager("demokey"); |
| 228 | + int resCode = api.writeServiceDataForUser(sam, JSON.make("tasks", tasksArray)); |
| 229 | + System.out.println("resCode: " + resCode); //DEBUG |
214 | 230 | } |
215 | 231 |
|
216 | 232 | //all good |
|
0 commit comments