diff --git a/libs/chat-workflow/src/main/java/org/finos/springbot/workflow/response/DataResponse.java b/libs/chat-workflow/src/main/java/org/finos/springbot/workflow/response/DataResponse.java index f0416937f..bc70ec2f2 100644 --- a/libs/chat-workflow/src/main/java/org/finos/springbot/workflow/response/DataResponse.java +++ b/libs/chat-workflow/src/main/java/org/finos/springbot/workflow/response/DataResponse.java @@ -1,10 +1,10 @@ package org.finos.springbot.workflow.response; -import java.util.Map; - import org.finos.springbot.workflow.content.Addressable; import org.finos.springbot.workflow.response.handlers.ResponseHandler; +import java.util.Map; + /** * A Response that contains some JSON data to be included in the message. * @@ -17,8 +17,6 @@ public class DataResponse implements Response { private final String templateName; private final Addressable to; - private String summary; - public DataResponse(Addressable to, Map data, String templateName) { super(); this.to = to; @@ -26,19 +24,6 @@ public DataResponse(Addressable to, Map data, String templateNam this.templateName = templateName; } - public DataResponse(Addressable to, Map data, String templateName, String summary) { - this(to,data,templateName); - this.summary = summary; - } - - public void setSummary(String summary) { - this.summary = summary; - } - - public String getSummary() { - return summary; - } - public Map getData() { return data; } diff --git a/libs/chat-workflow/src/main/java/org/finos/springbot/workflow/response/MessageResponse.java b/libs/chat-workflow/src/main/java/org/finos/springbot/workflow/response/MessageResponse.java index 3c31f8342..1bb690005 100644 --- a/libs/chat-workflow/src/main/java/org/finos/springbot/workflow/response/MessageResponse.java +++ b/libs/chat-workflow/src/main/java/org/finos/springbot/workflow/response/MessageResponse.java @@ -1,12 +1,12 @@ package org.finos.springbot.workflow.response; -import java.util.HashMap; -import java.util.Map; - import org.finos.springbot.workflow.content.Addressable; import org.finos.springbot.workflow.content.Content; import org.finos.springbot.workflow.content.Message; +import java.util.HashMap; +import java.util.Map; + /** * A Response that includes a message {@link Content} to send back to the user. * @@ -25,10 +25,6 @@ public MessageResponse(Addressable stream, Map data, Content m, public MessageResponse(Addressable stream, String textContent) { this(stream, Message.of(textContent)); } - public MessageResponse(Addressable stream, String textContent, String responseSummary) { - this(stream, Message.of(textContent)); - setSummary(responseSummary); - } public MessageResponse(Addressable stream, Content m) { super(stream, new HashMap<>(), null); diff --git a/libs/chat-workflow/src/main/java/org/finos/springbot/workflow/response/WorkResponse.java b/libs/chat-workflow/src/main/java/org/finos/springbot/workflow/response/WorkResponse.java index d941d3cbc..240875e34 100644 --- a/libs/chat-workflow/src/main/java/org/finos/springbot/workflow/response/WorkResponse.java +++ b/libs/chat-workflow/src/main/java/org/finos/springbot/workflow/response/WorkResponse.java @@ -1,8 +1,5 @@ package org.finos.springbot.workflow.response; -import java.util.HashMap; -import java.util.Map; - import org.finos.springbot.workflow.annotations.Template; import org.finos.springbot.workflow.annotations.WorkMode; import org.finos.springbot.workflow.content.Addressable; @@ -11,6 +8,9 @@ import org.springframework.util.StringUtils; import org.springframework.validation.Errors; +import java.util.HashMap; +import java.util.Map; + /** * Returns @Work-annotated object back to the user, either as form if editable=true, or * displayed in the chat if editable=false. @@ -43,11 +43,6 @@ public WorkResponse(Addressable to, Object o, WorkMode m, ButtonList buttons, Er public WorkResponse(Addressable to, Object o, WorkMode m) { this(to, o, m, null, null); } - - public WorkResponse(Addressable to, Object o, WorkMode m, String responseSummary){ - this(to,o,m); - setSummary(responseSummary); - } public static Map createEntityMap(Object o, ButtonList buttons, ErrorMap errors) { Map json = new HashMap<>(); diff --git a/libs/chat-workflow/src/main/java/org/finos/springbot/workflow/response/templating/TeamsWorkResponse.java b/libs/chat-workflow/src/main/java/org/finos/springbot/workflow/response/templating/TeamsWorkResponse.java new file mode 100644 index 000000000..8cd092794 --- /dev/null +++ b/libs/chat-workflow/src/main/java/org/finos/springbot/workflow/response/templating/TeamsWorkResponse.java @@ -0,0 +1,32 @@ +package org.finos.springbot.workflow.response.templating; + +import org.finos.springbot.workflow.annotations.WorkMode; +import org.finos.springbot.workflow.content.Addressable; +import org.finos.springbot.workflow.form.ButtonList; +import org.finos.springbot.workflow.form.ErrorMap; +import org.finos.springbot.workflow.response.WorkResponse; + +import java.util.Map; + +public class TeamsWorkResponse extends WorkResponse { + private final String summary; + + public TeamsWorkResponse(Addressable to, Map data, String templateName, WorkMode m, Class formClass, String summary) { + super(to, data, templateName, m, formClass); + this.summary = summary; + } + + public TeamsWorkResponse(Addressable to, Object o, WorkMode m, ButtonList buttons, ErrorMap errors, String summary) { + super(to, o, m, buttons, errors); + this.summary = summary; + } + + public TeamsWorkResponse(Addressable to, Object o, WorkMode m, String summary) { + super(to, o, m); + this.summary = summary; + } + + public String getSummary() { + return summary; + } +} diff --git a/libs/teams/teams-chat-workflow-spring-boot-starter/src/main/java/org/finos/springbot/teams/handlers/TeamsResponseHandler.java b/libs/teams/teams-chat-workflow-spring-boot-starter/src/main/java/org/finos/springbot/teams/handlers/TeamsResponseHandler.java index 454ceb17f..7904755a7 100644 --- a/libs/teams/teams-chat-workflow-spring-boot-starter/src/main/java/org/finos/springbot/teams/handlers/TeamsResponseHandler.java +++ b/libs/teams/teams-chat-workflow-spring-boot-starter/src/main/java/org/finos/springbot/teams/handlers/TeamsResponseHandler.java @@ -1,13 +1,11 @@ package org.finos.springbot.teams.handlers; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionException; -import java.util.function.BiFunction; - +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.microsoft.bot.connector.rest.ErrorResponseException; +import com.microsoft.bot.schema.*; import org.apache.commons.lang3.StringUtils; import org.finos.springbot.teams.TeamsException; import org.finos.springbot.teams.content.TeamsAddressable; @@ -23,12 +21,10 @@ import org.finos.springbot.workflow.actions.Action; import org.finos.springbot.workflow.actions.ErrorAction; import org.finos.springbot.workflow.annotations.WorkMode; -import org.finos.springbot.workflow.response.AttachmentResponse; import org.finos.springbot.workflow.response.ErrorResponse; -import org.finos.springbot.workflow.response.MessageResponse; -import org.finos.springbot.workflow.response.Response; -import org.finos.springbot.workflow.response.WorkResponse; +import org.finos.springbot.workflow.response.*; import org.finos.springbot.workflow.response.handlers.ResponseHandler; +import org.finos.springbot.workflow.response.templating.TeamsWorkResponse; import org.finos.springbot.workflow.tags.HeaderDetails; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,16 +33,10 @@ import org.springframework.context.ApplicationContextAware; import org.springframework.util.ErrorHandler; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.microsoft.bot.connector.rest.ErrorResponseException; -import com.microsoft.bot.schema.Activity; -import com.microsoft.bot.schema.Attachment; -import com.microsoft.bot.schema.Entity; -import com.microsoft.bot.schema.ResourceResponse; -import com.microsoft.bot.schema.TextFormatTypes; +import java.util.*; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; +import java.util.function.BiFunction; public class TeamsResponseHandler implements ResponseHandler, ApplicationContextAware { @@ -104,7 +94,7 @@ public ResourceResponse apply(Response t) { attachment = attachmentHandler.formatAttachment((AttachmentResponse) mr); } - return sendXMLResponse(content, attachment, ta, entities, mr.getData(), mr.getSummary()) + return sendXMLResponse(content, attachment, ta, entities, mr.getData()) .handle(handleErrorAndStorage(content, ta, mr.getData(), t)).get(); } else if (t instanceof WorkResponse) { @@ -113,13 +103,14 @@ public ResourceResponse apply(Response t) { if (tt == TemplateType.ADAPTIVE_CARD) { JsonNode cardJson = workTemplater.template(wr); - return sendCardResponse(cardJson, ta, wr.getData(), wr.getSummary()) + Optional responseSummaryOptional = t instanceof TeamsWorkResponse ? Optional.of(((TeamsWorkResponse) t).getSummary()) : Optional.empty() ; + return sendCardResponse(cardJson, ta, wr.getData(), responseSummaryOptional) .handle(handleErrorAndStorage(cardJson, ta, wr.getData(), t)).get(); } else { MarkupAndEntities mae = displayTemplater.template(wr); String content = mae.getContents(); List entities = mae.getEntities(); - return sendXMLResponse(content, null, ta, entities, wr.getData(), wr.getSummary()) + return sendXMLResponse(content, null, ta, entities, wr.getData()) .handle(handleButtonsIfNeeded(tt, wr)) .handle(handleErrorAndStorage(content, ta, wr.getData(), t)).get(); @@ -151,12 +142,11 @@ protected TemplateType getTemplateType(WorkResponse wr) { return tt; } - protected CompletableFuture sendXMLResponse(String xml, Attachment attachment, TeamsAddressable address, List entities, Map data, String summary) throws Exception { + protected CompletableFuture sendXMLResponse(String xml, Attachment attachment, TeamsAddressable address, List entities, Map data) throws Exception { Activity out = Activity.createMessageActivity(); if(Objects.nonNull(attachment)) { out.getAttachments().add(attachment); }else { - if(StringUtils.isNotBlank(summary)) out.setSummary(summary); out.setEntities(entities); out.setTextFormat(TextFormatTypes.XML); } @@ -173,7 +163,8 @@ private BiFunction handle JsonNode buttonsJson = workTemplater.template(null); wr.getData().put(AdaptiveCardTemplateProvider.FORMID_KEY, "just-buttons"); JsonNode expandedJson = workTemplater.applyTemplate(buttonsJson, wr); - return sendCardResponse(expandedJson, (TeamsAddressable) wr.getAddress(), wr.getData(), wr.getSummary()).get(); + Optional responseSummaryOptional = wr instanceof TeamsWorkResponse ? Optional.of(((TeamsWorkResponse) wr).getSummary()) : Optional.empty() ; + return sendCardResponse(expandedJson, (TeamsAddressable) wr.getAddress(), wr.getData(), responseSummaryOptional).get(); } else { return rr; } @@ -221,12 +212,13 @@ private BiFunction handle }; } - protected CompletableFuture sendCardResponse(JsonNode json, TeamsAddressable address, Map data, String summary) throws Exception { + protected CompletableFuture sendCardResponse(JsonNode json, TeamsAddressable address, Map data, Optional summaryOptional) throws Exception { Activity out = Activity.createMessageActivity(); Attachment body = new Attachment(); body.setContentType("application/vnd.microsoft.card.adaptive"); body.setContent(json); - if(StringUtils.isNotBlank(summary)) out.setSummary(summary); + if(summaryOptional.isPresent() && StringUtils.isNotBlank(summaryOptional.get())) + out.setSummary(summaryOptional.get()); out.getAttachments().add(body); return ah.handleActivity(out, address); }