|
3 | 3 |
|
4 | 4 | package com.microsoft.bot.sample.teamssearch;
|
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.TurnContext;
|
7 | 10 | import com.microsoft.bot.builder.teams.TeamsActivityHandler;
|
8 | 11 | import com.microsoft.bot.schema.*;
|
|
12 | 15 | import okhttp3.Request;
|
13 | 16 | import okhttp3.Response;
|
14 | 17 | import org.apache.commons.lang3.StringUtils;
|
15 |
| -import org.json.JSONArray; |
16 |
| -import org.json.JSONObject; |
17 | 18 | import org.slf4j.LoggerFactory;
|
18 | 19 |
|
19 | 20 | import java.io.IOException;
|
@@ -44,11 +45,14 @@ protected CompletableFuture<MessagingExtensionResponse> onTeamsMessagingExtensio
|
44 | 45 | .thenApply(packages -> {
|
45 | 46 | List<MessagingExtensionAttachment> attachments = new ArrayList<>();
|
46 | 47 | for (String[] item : packages) {
|
| 48 | + ObjectNode data = Serialization.createObjectNode(); |
| 49 | + data.set("data", Serialization.objectToTree(item)); |
| 50 | + |
47 | 51 | ThumbnailCard previewCard = new ThumbnailCard() {{
|
48 | 52 | setTitle(item[0]);
|
49 | 53 | setTap(new CardAction() {{
|
50 | 54 | setType(ActionTypes.INVOKE);
|
51 |
| - setValue(new JSONObject().put("data", item).toString()); |
| 55 | + setValue(Serialization.toStringSilent(data)); |
52 | 56 | }});
|
53 | 57 | }};
|
54 | 58 |
|
@@ -129,23 +133,22 @@ private CompletableFuture<List<String[]>> findPackages(String text) {
|
129 | 133 | ))
|
130 | 134 | .build();
|
131 | 135 |
|
132 |
| - List<String[]> filteredItems = new ArrayList<String[]>(); |
| 136 | + List<String[]> filteredItems = new ArrayList<>(); |
133 | 137 | try {
|
134 | 138 | Response response = client.newCall(request).execute();
|
135 |
| - JSONObject obj = new JSONObject(response.body().string()); |
136 |
| - JSONArray dataArray = (JSONArray) obj.get("data"); |
137 |
| - |
138 |
| - dataArray.forEach(i -> { |
139 |
| - JSONObject item = (JSONObject) i; |
140 |
| - filteredItems.add(new String[]{ |
141 |
| - item.getString("id"), |
142 |
| - item.getString("version"), |
143 |
| - item.getString("description"), |
144 |
| - item.has("projectUrl") ? item.getString("projectUrl") : "", |
145 |
| - item.has("iconUrl") ? item.getString("iconUrl") : "" |
| 139 | + JsonNode obj = Serialization.jsonToTree(response.body().string()); |
| 140 | + ArrayNode dataArray = (ArrayNode) obj.get("data"); |
| 141 | + |
| 142 | + for (int i = 0; i < dataArray.size(); i++) { |
| 143 | + JsonNode item = dataArray.get(i); |
| 144 | + filteredItems.add(new String[] { |
| 145 | + item.get("id").asText(), |
| 146 | + item.get("version").asText(), |
| 147 | + item.get("description").asText(), |
| 148 | + item.has("projectUrl") ? item.get("projectUrl").asText() : "", |
| 149 | + item.has("iconUrl") ? item.get("iconUrl").asText() : "" |
146 | 150 | });
|
147 |
| - }); |
148 |
| - |
| 151 | + } |
149 | 152 | } catch (IOException e) {
|
150 | 153 | LoggerFactory.getLogger(TeamsMessagingExtensionsSearchBot.class)
|
151 | 154 | .error("findPackages", e);
|
|
0 commit comments