From 74a0fd3bde90e59f628ea9205515ef2f7bcc7e2a Mon Sep 17 00:00:00 2001 From: tracyboehrer Date: Tue, 9 Feb 2021 10:16:18 -0600 Subject: [PATCH 1/2] Teams Adaptive Cards model classes --- .../bot/schema/teams/TabContext.java | 45 ++++++++++ .../bot/schema/teams/TabEntityContext.java | 45 ++++++++++ .../bot/schema/teams/TabRequest.java | 75 +++++++++++++++++ .../bot/schema/teams/TabResponse.java | 37 +++++++++ .../bot/schema/teams/TabResponseCard.java | 37 +++++++++ .../bot/schema/teams/TabResponseCards.java | 38 +++++++++ .../bot/schema/teams/TabResponsePayload.java | 83 +++++++++++++++++++ .../microsoft/bot/schema/teams/TabSubmit.java | 75 +++++++++++++++++ .../bot/schema/teams/TabSubmitData.java | 73 ++++++++++++++++ .../bot/schema/teams/TabSuggestedActions.java | 48 +++++++++++ .../bot/schema/teams/TaskModuleRequest.java | 19 +++++ 11 files changed, 575 insertions(+) create mode 100644 libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabContext.java create mode 100644 libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabEntityContext.java create mode 100644 libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabRequest.java create mode 100644 libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabResponse.java create mode 100644 libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabResponseCard.java create mode 100644 libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabResponseCards.java create mode 100644 libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabResponsePayload.java create mode 100644 libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabSubmit.java create mode 100644 libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabSubmitData.java create mode 100644 libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabSuggestedActions.java diff --git a/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabContext.java b/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabContext.java new file mode 100644 index 000000000..bcafe7d21 --- /dev/null +++ b/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabContext.java @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.bot.schema.teams; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Current tab request context, i.e., the current theme. + */ +public class TabContext { + @JsonProperty(value = "theme") + private String theme; + + /** + * Initializes a new instance of the class. + */ + public TabContext() { + + } + + /** + * Initializes a new instance of the class. + * @param withTheme The current user's theme. + */ + public TabContext(String withTheme) { + theme = withTheme; + } + + /** + * Gets the current user's theme. + * @return The current user's theme. + */ + public String getTheme() { + return theme; + } + + /** + * Sets the current user's theme. + * @param withTheme The current user's theme. + */ + public void setTheme(String withTheme) { + theme = withTheme; + } +} diff --git a/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabEntityContext.java b/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabEntityContext.java new file mode 100644 index 000000000..04f6dc5ec --- /dev/null +++ b/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabEntityContext.java @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.bot.schema.teams; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Current TabRequest entity context, or 'tabEntityId'. + */ +public class TabEntityContext { + @JsonProperty(value = "tabEntityId") + private String tabEntityId; + + /** + * Initializes a new instance of the class. + */ + public TabEntityContext() { + + } + + /** + * Initializes a new instance of the class. + * @param withTabEntityId The entity id of the tab. + */ + public TabEntityContext(String withTabEntityId) { + tabEntityId = withTabEntityId; + } + + /** + * Gets the entity id of the tab. + * @return The entity id of the tab. + */ + public String getTabEntityId() { + return tabEntityId; + } + + /** + * Sets the entity id of the tab. + * @param withTabEntityId The entity id of the tab. + */ + public void setTabEntityId(String withTabEntityId) { + tabEntityId = withTabEntityId; + } +} diff --git a/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabRequest.java b/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabRequest.java new file mode 100644 index 000000000..25edda7e5 --- /dev/null +++ b/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabRequest.java @@ -0,0 +1,75 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.bot.schema.teams; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Invoke ('tab/fetch') request value payload. + */ +public class TabRequest { + @JsonProperty(value = "tabContext") + private TabEntityContext tabContext; + + @JsonProperty(value = "context") + private TabContext context; + + @JsonProperty(value = "state") + private String state; + + /** + * Initializes a new instance of the class. + */ + public TabRequest() { + + } + + /** + * Gets current tab entity request context. + * @return Tab context + */ + public TabEntityContext getTabContext() { + return tabContext; + } + + /** + * Sets current tab entity request context. + * @param withTabContext Tab context + */ + public void setTabContext(TabEntityContext withTabContext) { + tabContext = withTabContext; + } + + /** + * Gets current user context, i.e., the current theme. + * @return Current user context, i.e., the current theme. + */ + public TabContext getContext() { + return context; + } + + /** + * Sets current user context, i.e., the current theme. + * @param withContext Current user context, i.e., the current theme. + */ + public void setContext(TabContext withContext) { + context = withContext; + } + + /** + * Gets state, which is the magic code for OAuth Flow. + * @return State, which is the magic code for OAuth Flow. + */ + public String getState() { + return state; + } + + /** + * Sets state, which is the magic code for OAuth Flow. + * @param withState State, which is the magic code for OAuth Flow. + */ + public void setState(String withState) { + state = withState; + } +} diff --git a/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabResponse.java b/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabResponse.java new file mode 100644 index 000000000..a8f97d1f4 --- /dev/null +++ b/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabResponse.java @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.bot.schema.teams; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Envelope for Card Tab Response Payload. + */ +public class TabResponse { + @JsonProperty(value = "tab") + private TabResponsePayload tab; + + /** + * Initializes a new instance of the class. + */ + public TabResponse() { + + } + + /** + * Gets the response to the tab/fetch message. + * @return Cards in response to a TabRequest. + */ + public TabResponsePayload getTab() { + return tab; + } + + /** + * Sets the response to the tab/fetch message. + * @param withTab Cards in response to a TabRequest. + */ + public void setTab(TabResponsePayload withTab) { + tab = withTab; + } +} diff --git a/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabResponseCard.java b/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabResponseCard.java new file mode 100644 index 000000000..277ae99a6 --- /dev/null +++ b/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabResponseCard.java @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.bot.schema.teams; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Envelope for cards for a Tab request. + */ +public class TabResponseCard { + @JsonProperty(value = "card") + private Object card; + + /** + * Initializes a new instance of the class. + */ + public TabResponseCard() { + + } + + /** + * Gets adaptive card for this card tab response. + * @return Cards for this TabResponse. + */ + public Object getCard() { + return card; + } + + /** + * Sets adaptive card for this card tab response. + * @param withCard Cards for this TabResponse. + */ + public void setCard(Object withCard) { + card = withCard; + } +} diff --git a/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabResponseCards.java b/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabResponseCards.java new file mode 100644 index 000000000..c36a63c9f --- /dev/null +++ b/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabResponseCards.java @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.bot.schema.teams; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; + +/** + * Envelope for cards for a TabResponse. + */ +public class TabResponseCards { + @JsonProperty(value = "cards") + private List cards; + + /** + * Initializes a new instance of the class. + */ + public TabResponseCards() { + + } + + /** + * Gets adaptive cards for this card tab response. + * @return Cards for the TabResponse. + */ + public List getCards() { + return cards; + } + + /** + * Sets adaptive cards for this card tab response. + * @param withCards Cards for the TabResponse. + */ + public void setCards(List withCards) { + cards = withCards; + } +} diff --git a/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabResponsePayload.java b/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabResponsePayload.java new file mode 100644 index 000000000..3817f9555 --- /dev/null +++ b/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabResponsePayload.java @@ -0,0 +1,83 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.bot.schema.teams; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Payload for Tab Response. + */ +public class TabResponsePayload { + @JsonProperty(value = "type") + private String type; + + @JsonProperty(value = "value") + private TabResponseCards value; + + @JsonProperty(value = "suggestedActions") + private TabSuggestedActions suggestedActions; + + /** + * Initializes a new instance of the class. + */ + public TabResponsePayload() { + + } + + /** + * Gets choice of action options when responding to the tab/fetch message. + * Possible values include: 'continue', 'auth' or 'silentAuth'. + * + * @return One of either: 'continue', 'auth' or 'silentAuth'. + */ + public String getType() { + return type; + } + + /** + * Sets choice of action options when responding to the tab/fetch message. + * Possible values include: 'continue', 'auth' or 'silentAuth'. + + * @param withType One of either: 'continue', 'auth' or 'silentAuth'. + */ + public void setType(String withType) { + type = withType; + } + + /** + * Gets or sets the TabResponseCards when responding to + * tab/fetch activity with type of 'continue'. + * + * @return Cards in response to a TabResponseCards. + */ + public TabResponseCards getValue() { + return value; + } + + /** + * Sets or sets the TabResponseCards when responding to + * tab/fetch activity with type of 'continue'. + * + * @param withValue Cards in response to a TabResponseCards. + */ + public void setValue(TabResponseCards withValue) { + value = withValue; + } + + /** + * Gets the Suggested Actions for this card tab. + * @return The Suggested Actions for this card tab. + */ + public TabSuggestedActions getSuggestedActions() { + return suggestedActions; + } + + /** + * Sets the Suggested Actions for this card tab. + * @param withSuggestedActions The Suggested Actions for this card tab. + */ + public void setSuggestedActions(TabSuggestedActions withSuggestedActions) { + suggestedActions = withSuggestedActions; + } +} diff --git a/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabSubmit.java b/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabSubmit.java new file mode 100644 index 000000000..5f69a5757 --- /dev/null +++ b/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabSubmit.java @@ -0,0 +1,75 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.bot.schema.teams; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Invoke ('tab/submit') request value payload. + */ +public class TabSubmit { + @JsonProperty(value = "tabContext") + private TabEntityContext tabEntityContext; + + @JsonProperty(value = "context") + private TabContext context; + + @JsonProperty(value = "data") + private TabSubmitData data; + + /** + * Initializes a new instance of the class. + */ + public TabSubmit() { + + } + + /** + * Gets current tab entity request context. + * @return Tab context for the TabSubmit. + */ + public TabEntityContext getTabEntityContext() { + return tabEntityContext; + } + + /** + * Sets current tab entity request context. + * @param withTabEntityContext Tab context for the TabSubmit. + */ + public void setTabEntityContext(TabEntityContext withTabEntityContext) { + tabEntityContext = withTabEntityContext; + } + + /** + * Gets current user context, i.e., the current theme. + * @return Current user context, i.e., the current theme. + */ + public TabContext getContext() { + return context; + } + + /** + * Sets current user context, i.e., the current theme. + * @param withContext Current user context, i.e., the current theme. + */ + public void setContext(TabContext withContext) { + context = withContext; + } + + /** + * Gets user input data. Free payload containing properties of key-value pairs. + * @return User input data. Free payload containing properties of key-value pairs. + */ + public TabSubmitData getData() { + return data; + } + + /** + * Sets user input data. Free payload containing properties of key-value pairs. + * @param withData User input data. Free payload containing properties of key-value pairs. + */ + public void setData(TabSubmitData withData) { + data = withData; + } +} diff --git a/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabSubmitData.java b/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabSubmitData.java new file mode 100644 index 000000000..3f17c6376 --- /dev/null +++ b/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabSubmitData.java @@ -0,0 +1,73 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.bot.schema.teams; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.JsonNode; +import java.util.HashMap; +import java.util.Map; + +/** + * Invoke ('tab/submit') request value payload data. + */ +public class TabSubmitData { + @JsonProperty(value = "type") + private String type; + + /** + * Holds the overflow properties that aren't first class properties in the + * object. This allows extensibility while maintaining the object. + */ + private HashMap properties = new HashMap<>(); + + /** + * Initializes a new instance of the class. + */ + public TabSubmitData() { + + } + + /** + * Gets the type for this TabSubmitData. + * + * @return Currently, 'tab/submit'. + */ + public String getType() { + return type; + } + + /** + * Sets the type for this TabSubmitData. + + * @param withType Currently, 'tab/submit'. + */ + public void setType(String withType) { + type = withType; + } + + /** + * Holds the overflow properties that aren't first class properties in the + * object. This allows extensibility while maintaining the object. + * + * @return Map of additional properties. + */ + @JsonAnyGetter + public Map getProperties() { + return this.properties; + } + + /** + * Holds the overflow properties that aren't first class properties in the + * object. This allows extensibility while maintaining the object. + * + * @param key The key of the property to set. + * @param withValue The value for the property. + */ + @JsonAnySetter + public void setProperties(String key, JsonNode withValue) { + this.properties.put(key, withValue); + } +} diff --git a/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabSuggestedActions.java b/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabSuggestedActions.java new file mode 100644 index 000000000..de14ac5f7 --- /dev/null +++ b/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TabSuggestedActions.java @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.bot.schema.teams; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.bot.schema.CardAction; +import java.util.Arrays; +import java.util.List; + +/** + * Tab SuggestedActions (Only when type is 'auth' or 'silentAuth'). + */ +public class TabSuggestedActions { + @JsonProperty(value = "actions") + private List actions; + + /** + * Initializes a new instance of the class. + */ + public TabSuggestedActions() { + + } + + /** + * Gets actions for a card tab response. + * @return Actions for this TabSuggestedActions. + */ + public List getActions() { + return actions; + } + + /** + * Sets actions for a card tab response. + * @param withActions Actions for this TabSuggestedActions. + */ + public void setActions(List withActions) { + actions = withActions; + } + + /** + * Sets actions for a card tab response. + * @param withActions Actions for this TabSuggestedActions. + */ + public void setActions(CardAction... withActions) { + actions = Arrays.asList(withActions); + } +} diff --git a/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TaskModuleRequest.java b/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TaskModuleRequest.java index d2dd5d779..c4daaf9e3 100644 --- a/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TaskModuleRequest.java +++ b/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/teams/TaskModuleRequest.java @@ -15,6 +15,9 @@ public class TaskModuleRequest { @JsonProperty(value = "context") private TaskModuleRequestContext context; + @JsonProperty(value = "tabContext") + private TabContext tabContext; + /** * Gets user input data. Free payload with key-value pairs. * @@ -50,4 +53,20 @@ public TaskModuleRequestContext getContext() { public void setContext(TaskModuleRequestContext withContext) { context = withContext; } + + /** + * Gets current tab request context. + * @return Tab request context. + */ + public TabContext getTabContext() { + return tabContext; + } + + /** + * Sets current tab request context. + * @param withTabContext Tab request context. + */ + public void setTabContext(TabContext withTabContext) { + tabContext = withTabContext; + } } From b24a1e5c5be5c401b05e5dfdf38d1184c2b0f18d Mon Sep 17 00:00:00 2001 From: tracyboehrer Date: Tue, 9 Feb 2021 10:36:27 -0600 Subject: [PATCH 2/2] Teams Adaptive Cars, TeamsActivityHandler --- .../builder/teams/TeamsActivityHandler.java | 52 +++++++++++++++++-- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/teams/TeamsActivityHandler.java b/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/teams/TeamsActivityHandler.java index 4d113b82d..4831fffe6 100644 --- a/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/teams/TeamsActivityHandler.java +++ b/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/teams/TeamsActivityHandler.java @@ -23,6 +23,9 @@ import com.microsoft.bot.schema.teams.MessagingExtensionQuery; import com.microsoft.bot.schema.teams.MessagingExtensionResponse; import com.microsoft.bot.schema.teams.O365ConnectorCardActionQuery; +import com.microsoft.bot.schema.teams.TabRequest; +import com.microsoft.bot.schema.teams.TabResponse; +import com.microsoft.bot.schema.teams.TabSubmit; import com.microsoft.bot.schema.teams.TaskModuleRequest; import com.microsoft.bot.schema.teams.TaskModuleResponse; import com.microsoft.bot.schema.teams.TeamInfo; @@ -42,7 +45,7 @@ * Pre and post processing of Activities can be plugged in by deriving and * calling the base class implementation. */ -@SuppressWarnings({ "checkstyle:JavadocMethod", "checkstyle:DesignForExtension" }) +@SuppressWarnings({ "checkstyle:JavadocMethod", "checkstyle:DesignForExtension", "checkstyle:MethodLength" }) public class TeamsActivityHandler extends ActivityHandler { /** * Invoked when an invoke activity is received from the connector when the base @@ -174,6 +177,26 @@ protected CompletableFuture onInvokeActivity(TurnContext turnCon ).thenApply(ActivityHandler::createInvokeResponse); break; + case "tab/fetch": + result = onTeamsTabFetch( + turnContext, + Serialization.safeGetAs( + turnContext.getActivity().getValue(), + TabRequest.class + ) + ).thenApply(ActivityHandler::createInvokeResponse); + break; + + case "tab/submit": + result = onTeamsTabSubmit( + turnContext, + Serialization.safeGetAs( + turnContext.getActivity().getValue(), + TabSubmit.class + ) + ).thenApply(ActivityHandler::createInvokeResponse); + break; + default: result = super.onInvokeActivity(turnContext); break; @@ -484,7 +507,8 @@ protected CompletableFuture onTeamsTaskModuleFetch( } /** - * Override this in a derived class to provide logic for when a card button is clicked in a messaging extension. + * Override this in a derived class to provide logic for when a card button + * is clicked in a messaging extension. * * @param turnContext The current TurnContext. * @param cardData Object representing the card data. @@ -676,8 +700,8 @@ protected CompletableFuture onTeamsMembersAddedDispatch( } if (teamsChannelAccount == null) { - // unable to find the member added in ConversationUpdate Activity in the response from the - // getMember call + // unable to find the member added in ConversationUpdate Activity in + // the response from the getMember call teamsChannelAccount = new TeamsChannelAccount(); teamsChannelAccount.setId(memberAdded.getId()); teamsChannelAccount.setName(memberAdded.getName()); @@ -919,6 +943,26 @@ protected CompletableFuture onTeamsTeamUnarchived( return CompletableFuture.completedFuture(null); } + /** + * Override this in a derived class to provide logic for when a tab is fetched. + * @param turnContext The context object for this turn. + * @param tabRequest The tab invoke request value payload. + * @return A Tab Response for the request. + */ + protected CompletableFuture onTeamsTabFetch(TurnContext turnContext, TabRequest tabRequest) { + return withException(new InvokeResponseException(HttpURLConnection.HTTP_NOT_IMPLEMENTED)); + } + + /** + * Override this in a derived class to provide logic for when a tab is submitted. + * @param turnContext The context object for this turn. + * @param tabSubmit The tab submit invoke request value payload. + * @return A Tab Response for the request. + */ + protected CompletableFuture onTeamsTabSubmit(TurnContext turnContext, TabSubmit tabSubmit) { + return withException(new InvokeResponseException(HttpURLConnection.HTTP_NOT_IMPLEMENTED)); + } + /** * Invoke a new InvokeResponseException with a HTTP 501 code status. *