Skip to content

Commit

Permalink
Merge pull request finos#442 from deutschebank/spring-bot-master-db
Browse files Browse the repository at this point in the history
Summary field in ms teams
  • Loading branch information
robmoffat authored Aug 8, 2024
2 parents d9736dd + 6be5abe commit 3f89063
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class WorkResponse extends DataResponse {
public static final String DEFAULT_FORM_TEMPLATE_VIEW = "default-view";
public static final String ERRORS_KEY = "errors";
public static final String OBJECT_KEY = "form";
public static final String SUMMARY_KEY = "summary-key";

private final WorkMode mode;
private final Class<?> formClass;
Expand All @@ -45,13 +46,27 @@ public WorkResponse(Addressable to, Object o, WorkMode m) {
this(to, o, m, null, null);
}

/**
* Call this contructor to create a work response with summary
*/
public WorkResponse(Addressable to, Object o, WorkMode m, String summary) {
this(to, createEntityMapWithSummay(o, null, null, summary), getTemplateNameForObject(m, o), m, o.getClass());
}

public static Map<String, Object> createEntityMap(Object o, ButtonList buttons, ErrorMap errors) {
Map<String, Object> json = new HashMap<>();
json.put(ButtonList.KEY, buttons == null ? new ButtonList() : buttons);
json.put(ERRORS_KEY, errors == null ? new ErrorMap() : errors);
json.put(OBJECT_KEY, o);
return json;
}

public static Map<String, Object> createEntityMapWithSummay(Object o, ButtonList buttons, ErrorMap errors, String summary) {
Map<String, Object> map = createEntityMap(o, buttons, errors);
map.put(SUMMARY_KEY, summary);

return map;
}

public static String getTemplateNameForObject(WorkMode m, Object o) {
return getTemplateNameForClass(m, o.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,14 @@ private BiFunction<? super ResourceResponse, Throwable, ResourceResponse> handle
};
}

protected CompletableFuture<ResourceResponse> sendCardResponse(JsonNode json, TeamsAddressable address, Map<String, Object> data) throws Exception {
protected CompletableFuture<ResourceResponse> sendCardResponse(JsonNode json, TeamsAddressable address, Map<String, Object> data) throws Exception {
Activity out = Activity.createMessageActivity();
Attachment body = new Attachment();
body.setContentType("application/vnd.microsoft.card.adaptive");
body.setContent(json);
if(data.containsKey(WorkResponse.SUMMARY_KEY)) {
out.setSummary(data.get(WorkResponse.SUMMARY_KEY).toString());
}
out.getAttachments().add(body);
return ah.handleActivity(out, address);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public MessageActivityHandler(
@Override
protected CompletableFuture<Void> onMessageActivity(TurnContext turnContext) {
return CompletableFuture.completedFuture(null)
.thenRun(() -> handleActivity(turnContext));
.thenRun(() -> CompletableFuture.runAsync(() -> handleActivity(turnContext)));
}

protected void handleActivity(TurnContext turnContext) {
Expand Down

0 comments on commit 3f89063

Please sign in to comment.