Skip to content

Commit

Permalink
SYMPHONYP-940 MS Teams feature to submit the adaptive card
Browse files Browse the repository at this point in the history
  • Loading branch information
vaibhav-db committed Feb 24, 2023
1 parent e300cb5 commit 3f2fec6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.finos.springbot.teams.response.templating.EntityMarkupTemplateProvider;
import org.finos.springbot.teams.response.templating.MarkupAndEntities;
import org.finos.springbot.teams.state.TeamsStateStorage;
import org.finos.springbot.teams.templating.adaptivecard.AdaptiveCardPassthrough;
import org.finos.springbot.teams.templating.adaptivecard.AdaptiveCardTemplateProvider;
import org.finos.springbot.teams.templating.thymeleaf.ThymeleafTemplateProvider;
import org.finos.springbot.workflow.annotations.WorkMode;
Expand Down Expand Up @@ -142,7 +143,7 @@ protected TemplateType getTemplateType(WorkResponse wr) {
TemplateType tt;
if (displayTemplater.hasTemplate(wr)) {
tt = TemplateType.THYMELEAF;
} else if (workTemplater.hasTemplate(wr)) {
} else if (workTemplater.hasTemplate(wr) || AdaptiveCardPassthrough.isAdaptiveCard(wr)) {
tt = TemplateType.ADAPTIVE_CARD;
} else if (wr.getMode() == WorkMode.EDIT) {
tt = TemplateType.ADAPTIVE_CARD;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.finos.springbot.teams.templating.adaptivecard;

import org.finos.springbot.workflow.response.WorkResponse;

import com.fasterxml.jackson.databind.JsonNode;

public class AdaptiveCardPassthrough {

private final static String ADAPTIVE_CARD = "AdaptiveCard";
private final static String ADAPTIVE_CARD_TYPE = "type";

private final JsonNode jsonNode;

public AdaptiveCardPassthrough(JsonNode jsonNode) {
this.jsonNode = jsonNode;
}

public JsonNode getJsonNode() {
return jsonNode;
}

public static boolean isAdaptiveCard(WorkResponse wr) {
if (wr.getFormObject() instanceof AdaptiveCardPassthrough) {
AdaptiveCardPassthrough passthrough = (AdaptiveCardPassthrough) wr.getFormObject();
JsonNode node = passthrough.getJsonNode();
JsonNode adaptiveNode = node.get(ADAPTIVE_CARD_TYPE);
return adaptiveNode.asText().equals(ADAPTIVE_CARD);
}

return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.finos.springbot.teams.handlers.TeamsResponseHandler;
import org.finos.springbot.teams.templating.MatcherUtil;
import org.finos.springbot.workflow.annotations.WorkMode;
import org.finos.springbot.workflow.form.ButtonList;
import org.finos.springbot.workflow.response.WorkResponse;
import org.finos.springbot.workflow.response.templating.AbstractResourceTemplateProvider;
import org.finos.springbot.workflow.templating.Mode;
import org.finos.springbot.workflow.templating.WorkTemplater;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ResourceLoader;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
Expand All @@ -27,6 +30,8 @@

public class AdaptiveCardTemplateProvider extends AbstractResourceTemplateProvider<JsonNode, JsonNode, WorkResponse> {

private static final Logger LOG = LoggerFactory.getLogger(AdaptiveCardTemplateProvider.class);

public static final String FORMID_KEY = "formid";

private final WorkTemplater<JsonNode> formConverter;
Expand Down Expand Up @@ -58,14 +63,19 @@ public JsonNode template(WorkResponse t) {
// in this case, just provide the button template
return formConverter.convert(null, Mode.DISPLAY_WITH_BUTTONS);

} else if (AdaptiveCardPassthrough.isAdaptiveCard(t)) {
AdaptiveCardPassthrough passthrough = (AdaptiveCardPassthrough) t.getFormObject();
JsonNode template = passthrough.getJsonNode();
LOG.info("JsonNode Template: \n" + template.toPrettyString());

return template;
} else {
return super.template(t);
}
}




@Override
protected JsonNode getDefaultTemplate(WorkResponse r) {
JsonNode insert;
Expand Down

0 comments on commit 3f2fec6

Please sign in to comment.