|
3 | 3 |
|
4 | 4 | package com.microsoft.bot.sample.teamssearchauth; |
5 | 5 |
|
| 6 | +import com.fasterxml.jackson.databind.JsonNode; |
| 7 | +import com.fasterxml.jackson.databind.node.ArrayNode; |
| 8 | +import com.fasterxml.jackson.databind.node.ObjectNode; |
6 | 9 | import com.microsoft.bot.builder.StatePropertyAccessor; |
7 | 10 | import com.microsoft.bot.builder.TurnContext; |
8 | 11 | import com.microsoft.bot.builder.UserState; |
|
18 | 21 | import okhttp3.Response; |
19 | 22 | import org.apache.commons.io.IOUtils; |
20 | 23 | import org.apache.commons.lang3.StringUtils; |
21 | | -import org.json.JSONArray; |
22 | | -import org.json.JSONObject; |
23 | 24 | import org.slf4j.LoggerFactory; |
24 | 25 |
|
25 | 26 | import java.io.IOException; |
@@ -133,11 +134,14 @@ private CompletableFuture<MessagingExtensionResponse> packageExtensionQuery( |
133 | 134 | return findPackages(search).thenApply(packages -> { |
134 | 135 | List<MessagingExtensionAttachment> attachments = new ArrayList<>(); |
135 | 136 | for (String[] item : packages) { |
| 137 | + ObjectNode data = Serialization.createObjectNode(); |
| 138 | + data.set("data", Serialization.objectToTree(item)); |
| 139 | + |
136 | 140 | ThumbnailCard previewCard = new ThumbnailCard() {{ |
137 | 141 | setTitle(item[0]); |
138 | 142 | setTap(new CardAction() {{ |
139 | 143 | setType(ActionTypes.INVOKE); |
140 | | - setValue(new JSONObject().put("data", item).toString()); |
| 144 | + setValue(data); |
141 | 145 | }}); |
142 | 146 | }}; |
143 | 147 |
|
@@ -348,21 +352,21 @@ private CompletableFuture<List<String[]>> findPackages(String text) { |
348 | 352 | List<String[]> filteredItems = new ArrayList<String[]>(); |
349 | 353 | try { |
350 | 354 | Response response = client.newCall(request).execute(); |
351 | | - JSONObject obj = new JSONObject(response.body().string()); |
352 | | - JSONArray dataArray = (JSONArray) obj.get("data"); |
| 355 | + JsonNode obj = Serialization.jsonToTree(response.body().string()); |
| 356 | + ArrayNode dataArray = (ArrayNode) obj.get("data"); |
353 | 357 |
|
354 | | - dataArray.forEach(i -> { |
355 | | - JSONObject item = (JSONObject) i; |
| 358 | + for (int i = 0; i < dataArray.size(); i++) { |
| 359 | + JsonNode item = dataArray.get(i); |
356 | 360 | filteredItems.add( |
357 | | - new String[]{ |
358 | | - item.getString("id"), item.getString("version"), |
359 | | - item.getString("description"), |
360 | | - item.has("projectUrl") ? item.getString("projectUrl") : "", |
361 | | - item.has("iconUrl") ? item.getString("iconUrl") : "" |
| 361 | + new String[] { |
| 362 | + item.get("id").asText(), |
| 363 | + item.get("version").asText(), |
| 364 | + item.get("description").asText(), |
| 365 | + item.has("projectUrl") ? item.get("projectUrl").asText() : "", |
| 366 | + item.has("iconUrl") ? item.get("iconUrl").asText() : "" |
362 | 367 | } |
363 | 368 | ); |
364 | | - }); |
365 | | - |
| 369 | + } |
366 | 370 | } catch (IOException e) { |
367 | 371 | LoggerFactory.getLogger(TeamsMessagingExtensionsSearchAuthConfigBot.class) |
368 | 372 | .error("findPackages", e); |
|
0 commit comments