From c24b0e4046d258f421c2c3aa96ec4c90fed9f1ce Mon Sep 17 00:00:00 2001
From: Lee Parrish <30470292+LeeParrishMSFT@users.noreply.github.com>
Date: Thu, 18 Mar 2021 09:46:23 -0500
Subject: [PATCH] Completed adaptive card sample 07.using-adaptive-cards
(#1064)
* Completed adaptive card sample
* Remove commented code line.
---
samples/07.using-adaptive-cards/LICENSE | 21 +
samples/07.using-adaptive-cards/README.md | 59 +++
.../template-with-new-rg.json | 291 ++++++++++++
.../template-with-preexisting-rg.json | 259 +++++++++++
samples/07.using-adaptive-cards/pom.xml | 249 +++++++++++
.../usingadaptivecards/Application.java | 67 +++
.../bots/AdaptiveCardsBot.java | 97 ++++
.../main/resources/FlightItineraryCard.json | 204 +++++++++
.../src/main/resources/ImageGalleryCard.json | 60 +++
.../src/main/resources/LargeWeatherCard.json | 205 +++++++++
.../src/main/resources/RestaurantCard.json | 60 +++
.../src/main/resources/SolitaireCard.json | 39 ++
.../src/main/resources/application.properties | 3 +
.../src/main/resources/log4j2.json | 18 +
.../src/main/webapp/META-INF/MANIFEST.MF | 3 +
.../src/main/webapp/WEB-INF/web.xml | 12 +
.../src/main/webapp/index.html | 418 ++++++++++++++++++
.../usingadaptivecards/ApplicationTest.java | 19 +
18 files changed, 2084 insertions(+)
create mode 100644 samples/07.using-adaptive-cards/LICENSE
create mode 100644 samples/07.using-adaptive-cards/README.md
create mode 100644 samples/07.using-adaptive-cards/deploymentTemplates/template-with-new-rg.json
create mode 100644 samples/07.using-adaptive-cards/deploymentTemplates/template-with-preexisting-rg.json
create mode 100644 samples/07.using-adaptive-cards/pom.xml
create mode 100644 samples/07.using-adaptive-cards/src/main/java/com/microsoft/bot/sample/usingadaptivecards/Application.java
create mode 100644 samples/07.using-adaptive-cards/src/main/java/com/microsoft/bot/sample/usingadaptivecards/bots/AdaptiveCardsBot.java
create mode 100644 samples/07.using-adaptive-cards/src/main/resources/FlightItineraryCard.json
create mode 100644 samples/07.using-adaptive-cards/src/main/resources/ImageGalleryCard.json
create mode 100644 samples/07.using-adaptive-cards/src/main/resources/LargeWeatherCard.json
create mode 100644 samples/07.using-adaptive-cards/src/main/resources/RestaurantCard.json
create mode 100644 samples/07.using-adaptive-cards/src/main/resources/SolitaireCard.json
create mode 100644 samples/07.using-adaptive-cards/src/main/resources/application.properties
create mode 100644 samples/07.using-adaptive-cards/src/main/resources/log4j2.json
create mode 100644 samples/07.using-adaptive-cards/src/main/webapp/META-INF/MANIFEST.MF
create mode 100644 samples/07.using-adaptive-cards/src/main/webapp/WEB-INF/web.xml
create mode 100644 samples/07.using-adaptive-cards/src/main/webapp/index.html
create mode 100644 samples/07.using-adaptive-cards/src/test/java/com/microsoft/bot/sample/usingadaptivecards/ApplicationTest.java
diff --git a/samples/07.using-adaptive-cards/LICENSE b/samples/07.using-adaptive-cards/LICENSE
new file mode 100644
index 00000000..21071075
--- /dev/null
+++ b/samples/07.using-adaptive-cards/LICENSE
@@ -0,0 +1,21 @@
+ MIT License
+
+ Copyright (c) Microsoft Corporation. All rights reserved.
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE
diff --git a/samples/07.using-adaptive-cards/README.md b/samples/07.using-adaptive-cards/README.md
new file mode 100644
index 00000000..3212a04a
--- /dev/null
+++ b/samples/07.using-adaptive-cards/README.md
@@ -0,0 +1,59 @@
+# Using Adaptive Cards
+
+Bot Framework v4 using adaptive cards bot sample
+
+This bot has been created using [Bot Framework](https://dev.botframework.com), is shows how to send an Adaptive Card from the bot to the user.
+
+## Prerequisites
+
+- Java 1.8+
+- Install [Maven](https://maven.apache.org/)
+- An account on [Azure](https://azure.microsoft.com) if you want to deploy to Azure.
+
+## To try this sample locally
+- From the root of this project folder:
+ - Build the sample using `mvn package`
+ - Run it by using `java -jar .\target\adaptive-cards-sample.jar`
+
+## Testing the bot using Bot Framework Emulator
+
+[Bot Framework Emulator](https://github.com/microsoft/botframework-emulator) is a desktop application that allows bot developers to test and debug their bots on localhost or running remotely through a tunnel.
+
+- Install the latest Bot Framework Emulator from [here](https://github.com/Microsoft/BotFramework-Emulator/releases)
+
+### Connect to the bot using Bot Framework Emulator
+
+- Launch Bot Framework Emulator
+- File -> Open Bot
+- Enter a Bot URL of `http://localhost:3978/api/messages`
+
+## Interacting with the bot
+
+Card authors describe their content as a simple JSON object. That content can then be rendered natively inside a host application, automatically adapting to the look and feel of the host. For example, Contoso Bot can author an Adaptive Card through the Bot Framework, and when delivered to Cortana, it will look and feel like a Cortana card. When that same payload is sent to Microsoft Teams, it will look and feel like Microsoft Teams. As more host apps start to support Adaptive Cards, that same payload will automatically light up inside these applications, yet still feel entirely native to the app. Users win because everything feels familiar. Host apps win because they control the user experience. Card authors win because their content gets broader reach without any additional work.
+
+The Bot Framework provides support for Adaptive Cards. See the following to learn more about Adaptive Cards.
+
+- [Adaptive card](http://adaptivecards.io)
+- [Send an Adaptive card](https://docs.microsoft.com/en-us/azure/bot-service/nodejs/bot-builder-nodejs-send-rich-cards?view=azure-bot-service-3.0&viewFallbackFrom=azure-bot-service-4.0#send-an-adaptive-card)
+
+### Adding media to messages
+
+A message exchange between user and bot can contain media attachments, such as cards, images, video, audio, and files.
+
+## Deploy the bot to Azure
+
+To learn more about deploying a bot to Azure, see [Deploy your bot to Azure](https://aka.ms/azuredeployment) for a complete list of deployment instructions.
+
+## Further reading
+
+- [Bot Framework Documentation](https://docs.botframework.com)
+- [Bot Basics](https://docs.microsoft.com/azure/bot-service/bot-builder-basics?view=azure-bot-service-4.0)
+- [Adaptive Cards](https://adaptivecards.io/)
+- [Send an Adaptive card](https://docs.microsoft.com/en-us/azure/bot-service/nodejs/bot-builder-nodejs-send-rich-cards?view=azure-bot-service-3.0&viewFallbackFrom=azure-bot-service-4.0#send-an-adaptive-card)
+- [Activity processing](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-concept-activity-processing?view=azure-bot-service-4.0)
+- [Azure Bot Service Introduction](https://docs.microsoft.com/azure/bot-service/bot-service-overview-introduction?view=azure-bot-service-4.0)
+- [Azure Bot Service Documentation](https://docs.microsoft.com/azure/bot-service/?view=azure-bot-service-4.0)
+- [.NET Core CLI tools](https://docs.microsoft.com/en-us/dotnet/core/tools/?tabs=netcore2x)
+- [Azure CLI](https://docs.microsoft.com/cli/azure/?view=azure-cli-latest)
+- [Azure Portal](https://portal.azure.com)
+- [Channels and Bot Connector Service](https://docs.microsoft.com/en-us/azure/bot-service/bot-concepts?view=azure-bot-service-4.0)
diff --git a/samples/07.using-adaptive-cards/deploymentTemplates/template-with-new-rg.json b/samples/07.using-adaptive-cards/deploymentTemplates/template-with-new-rg.json
new file mode 100644
index 00000000..ec2460d3
--- /dev/null
+++ b/samples/07.using-adaptive-cards/deploymentTemplates/template-with-new-rg.json
@@ -0,0 +1,291 @@
+{
+ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
+ "contentVersion": "1.0.0.0",
+ "parameters": {
+ "groupLocation": {
+ "defaultValue": "",
+ "type": "string",
+ "metadata": {
+ "description": "Specifies the location of the Resource Group."
+ }
+ },
+ "groupName": {
+ "type": "string",
+ "metadata": {
+ "description": "Specifies the name of the Resource Group."
+ }
+ },
+ "appId": {
+ "type": "string",
+ "metadata": {
+ "description": "Active Directory App ID, set as MicrosoftAppId in the Web App's Application Settings."
+ }
+ },
+ "appSecret": {
+ "type": "string",
+ "metadata": {
+ "description": "Active Directory App Password, set as MicrosoftAppPassword in the Web App's Application Settings."
+ }
+ },
+ "botId": {
+ "type": "string",
+ "metadata": {
+ "description": "The globally unique and immutable bot ID. Also used to configure the displayName of the bot, which is mutable."
+ }
+ },
+ "botSku": {
+ "defaultValue": "S1",
+ "type": "string",
+ "metadata": {
+ "description": "The pricing tier of the Bot Service Registration. Acceptable values are F0 and S1."
+ }
+ },
+ "newAppServicePlanName": {
+ "defaultValue": "",
+ "type": "string",
+ "metadata": {
+ "description": "The name of the App Service Plan."
+ }
+ },
+ "newAppServicePlanSku": {
+ "type": "object",
+ "defaultValue": {
+ "name": "P1v2",
+ "tier": "PremiumV2",
+ "size": "P1v2",
+ "family": "Pv2",
+ "capacity": 1
+ },
+ "metadata": {
+ "description": "The SKU of the App Service Plan. Defaults to Standard values."
+ }
+ },
+ "newAppServicePlanLocation": {
+ "defaultValue": "",
+ "type": "string",
+ "metadata": {
+ "description": "The location of the App Service Plan. Defaults to \"westus\"."
+ }
+ },
+ "newWebAppName": {
+ "type": "string",
+ "defaultValue": "",
+ "metadata": {
+ "description": "The globally unique name of the Web App. Defaults to the value passed in for \"botId\"."
+ }
+ }
+ },
+ "variables": {
+ "appServicePlanName": "[parameters('newAppServicePlanName')]",
+ "resourcesLocation": "[parameters('newAppServicePlanLocation')]",
+ "webAppName": "[if(empty(parameters('newWebAppName')), parameters('botId'), parameters('newWebAppName'))]",
+ "siteHost": "[concat(variables('webAppName'), '.azurewebsites.net')]",
+ "botEndpoint": "[concat('https://', variables('siteHost'), '/api/messages')]",
+ "publishingUsername": "[concat('$', parameters('newWebAppName'))]",
+ "resourceGroupId": "[concat(subscription().id, '/resourceGroups/', parameters('groupName'))]"
+ },
+ "resources": [
+ {
+ "name": "[parameters('groupName')]",
+ "type": "Microsoft.Resources/resourceGroups",
+ "apiVersion": "2018-05-01",
+ "location": "[parameters('groupLocation')]",
+ "properties": {}
+ },
+ {
+ "type": "Microsoft.Resources/deployments",
+ "apiVersion": "2018-05-01",
+ "name": "storageDeployment",
+ "resourceGroup": "[parameters('groupName')]",
+ "dependsOn": [
+ "[resourceId('Microsoft.Resources/resourceGroups/', parameters('groupName'))]"
+ ],
+ "properties": {
+ "mode": "Incremental",
+ "template": {
+ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
+ "contentVersion": "1.0.0.0",
+ "parameters": {},
+ "variables": {},
+ "resources": [
+ {
+ "comments": "Create a new Linux App Service Plan if no existing App Service Plan name was passed in.",
+ "type": "Microsoft.Web/serverfarms",
+ "name": "[variables('appServicePlanName')]",
+ "apiVersion": "2018-02-01",
+ "location": "[variables('resourcesLocation')]",
+ "sku": "[parameters('newAppServicePlanSku')]",
+ "kind": "linux",
+ "properties": {
+ "perSiteScaling": false,
+ "maximumElasticWorkerCount": 1,
+ "isSpot": false,
+ "reserved": true,
+ "isXenon": false,
+ "hyperV": false,
+ "targetWorkerCount": 0,
+ "targetWorkerSizeId": 0
+ }
+ },
+ {
+ "comments": "Create a Web App using a Linux App Service Plan",
+ "type": "Microsoft.Web/sites",
+ "apiVersion": "2018-11-01",
+ "location": "[variables('resourcesLocation')]",
+ "kind": "app,linux",
+ "dependsOn": [
+ "[concat(variables('resourceGroupId'), '/providers/Microsoft.Web/serverfarms/', variables('appServicePlanName'))]"
+ ],
+ "name": "[variables('webAppName')]",
+ "properties": {
+ "name": "[variables('webAppName')]",
+ "hostNameSslStates": [
+ {
+ "name": "[concat(parameters('newWebAppName'), '.azurewebsites.net')]",
+ "sslState": "Disabled",
+ "hostType": "Standard"
+ },
+ {
+ "name": "[concat(parameters('newWebAppName'), '.scm.azurewebsites.net')]",
+ "sslState": "Disabled",
+ "hostType": "Repository"
+ }
+ ],
+ "serverFarmId": "[variables('appServicePlanName')]",
+ "reserved": true,
+ "isXenon": false,
+ "hyperV": false,
+ "scmSiteAlsoStopped": false,
+ "clientAffinityEnabled": true,
+ "clientCertEnabled": false,
+ "hostNamesDisabled": false,
+ "containerSize": 0,
+ "dailyMemoryTimeQuota": 0,
+ "httpsOnly": false,
+ "redundancyMode": "None",
+ "siteConfig": {
+ "appSettings": [
+ {
+ "name": "JAVA_OPTS",
+ "value": "-Dserver.port=80"
+ },
+ {
+ "name": "MicrosoftAppId",
+ "value": "[parameters('appId')]"
+ },
+ {
+ "name": "MicrosoftAppPassword",
+ "value": "[parameters('appSecret')]"
+ }
+ ],
+ "cors": {
+ "allowedOrigins": [
+ "https://botservice.hosting.portal.azure.net",
+ "https://hosting.onecloud.azure-test.net/"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "type": "Microsoft.Web/sites/config",
+ "apiVersion": "2018-11-01",
+ "name": "[concat(variables('webAppName'), '/web')]",
+ "location": "[variables('resourcesLocation')]",
+ "dependsOn": [
+ "[concat(variables('resourceGroupId'), '/providers/Microsoft.Web/sites/', variables('webAppName'))]"
+ ],
+ "properties": {
+ "numberOfWorkers": 1,
+ "defaultDocuments": [
+ "Default.htm",
+ "Default.html",
+ "Default.asp",
+ "index.htm",
+ "index.html",
+ "iisstart.htm",
+ "default.aspx",
+ "index.php",
+ "hostingstart.html"
+ ],
+ "netFrameworkVersion": "v4.0",
+ "linuxFxVersion": "JAVA|8-jre8",
+ "requestTracingEnabled": false,
+ "remoteDebuggingEnabled": false,
+ "httpLoggingEnabled": false,
+ "logsDirectorySizeLimit": 35,
+ "detailedErrorLoggingEnabled": false,
+ "publishingUsername": "[variables('publishingUsername')]",
+ "scmType": "None",
+ "use32BitWorkerProcess": true,
+ "webSocketsEnabled": false,
+ "alwaysOn": true,
+ "managedPipelineMode": "Integrated",
+ "virtualApplications": [
+ {
+ "virtualPath": "/",
+ "physicalPath": "site\\wwwroot",
+ "preloadEnabled": true
+ }
+ ],
+ "loadBalancing": "LeastRequests",
+ "experiments": {
+ "rampUpRules": []
+ },
+ "autoHealEnabled": false,
+ "localMySqlEnabled": false,
+ "ipSecurityRestrictions": [
+ {
+ "ipAddress": "Any",
+ "action": "Allow",
+ "priority": 1,
+ "name": "Allow all",
+ "description": "Allow all access"
+ }
+ ],
+ "scmIpSecurityRestrictions": [
+ {
+ "ipAddress": "Any",
+ "action": "Allow",
+ "priority": 1,
+ "name": "Allow all",
+ "description": "Allow all access"
+ }
+ ],
+ "scmIpSecurityRestrictionsUseMain": false,
+ "http20Enabled": false,
+ "minTlsVersion": "1.2",
+ "ftpsState": "AllAllowed",
+ "reservedInstanceCount": 0
+ }
+ },
+ {
+ "apiVersion": "2017-12-01",
+ "type": "Microsoft.BotService/botServices",
+ "name": "[parameters('botId')]",
+ "location": "global",
+ "kind": "bot",
+ "sku": {
+ "name": "[parameters('botSku')]"
+ },
+ "properties": {
+ "name": "[parameters('botId')]",
+ "displayName": "[parameters('botId')]",
+ "endpoint": "[variables('botEndpoint')]",
+ "msaAppId": "[parameters('appId')]",
+ "developerAppInsightsApplicationId": null,
+ "developerAppInsightKey": null,
+ "publishingCredentials": null,
+ "storageResourceId": null
+ },
+ "dependsOn": [
+ "[concat(variables('resourceGroupId'), '/providers/Microsoft.Web/sites/', variables('webAppName'))]"
+ ]
+ }
+ ],
+ "outputs": {}
+ }
+ }
+ }
+ ]
+}
diff --git a/samples/07.using-adaptive-cards/deploymentTemplates/template-with-preexisting-rg.json b/samples/07.using-adaptive-cards/deploymentTemplates/template-with-preexisting-rg.json
new file mode 100644
index 00000000..024dcf08
--- /dev/null
+++ b/samples/07.using-adaptive-cards/deploymentTemplates/template-with-preexisting-rg.json
@@ -0,0 +1,259 @@
+{
+ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
+ "contentVersion": "1.0.0.0",
+ "parameters": {
+ "appId": {
+ "type": "string",
+ "metadata": {
+ "description": "Active Directory App ID, set as MicrosoftAppId in the Web App's Application Settings."
+ }
+ },
+ "appSecret": {
+ "type": "string",
+ "metadata": {
+ "description": "Active Directory App Password, set as MicrosoftAppPassword in the Web App's Application Settings. Defaults to \"\"."
+ }
+ },
+ "botId": {
+ "type": "string",
+ "metadata": {
+ "description": "The globally unique and immutable bot ID. Also used to configure the displayName of the bot, which is mutable."
+ }
+ },
+ "botSku": {
+ "defaultValue": "S1",
+ "type": "string",
+ "metadata": {
+ "description": "The pricing tier of the Bot Service Registration. Acceptable values are F0 and S1."
+ }
+ },
+ "newAppServicePlanName": {
+ "type": "string",
+ "defaultValue": "",
+ "metadata": {
+ "description": "The name of the new App Service Plan."
+ }
+ },
+ "newAppServicePlanSku": {
+ "type": "object",
+ "defaultValue": {
+ "name": "P1v2",
+ "tier": "PremiumV2",
+ "size": "P1v2",
+ "family": "Pv2",
+ "capacity": 1
+ },
+ "metadata": {
+ "description": "The SKU of the App Service Plan. Defaults to Standard values."
+ }
+ },
+ "appServicePlanLocation": {
+ "type": "string",
+ "defaultValue": "",
+ "metadata": {
+ "description": "The location of the App Service Plan."
+ }
+ },
+ "existingAppServicePlan": {
+ "type": "string",
+ "defaultValue": "",
+ "metadata": {
+ "description": "Name of the existing App Service Plan used to create the Web App for the bot."
+ }
+ },
+ "newWebAppName": {
+ "type": "string",
+ "defaultValue": "",
+ "metadata": {
+ "description": "The globally unique name of the Web App. Defaults to the value passed in for \"botId\"."
+ }
+ }
+ },
+ "variables": {
+ "defaultAppServicePlanName": "[if(empty(parameters('existingAppServicePlan')), 'createNewAppServicePlan', parameters('existingAppServicePlan'))]",
+ "useExistingAppServicePlan": "[not(equals(variables('defaultAppServicePlanName'), 'createNewAppServicePlan'))]",
+ "servicePlanName": "[if(variables('useExistingAppServicePlan'), parameters('existingAppServicePlan'), parameters('newAppServicePlanName'))]",
+ "publishingUsername": "[concat('$', parameters('newWebAppName'))]",
+ "resourcesLocation": "[parameters('appServicePlanLocation')]",
+ "webAppName": "[if(empty(parameters('newWebAppName')), parameters('botId'), parameters('newWebAppName'))]",
+ "siteHost": "[concat(variables('webAppName'), '.azurewebsites.net')]",
+ "botEndpoint": "[concat('https://', variables('siteHost'), '/api/messages')]"
+ },
+ "resources": [
+ {
+ "comments": "Create a new Linux App Service Plan if no existing App Service Plan name was passed in.",
+ "type": "Microsoft.Web/serverfarms",
+ "condition": "[not(variables('useExistingAppServicePlan'))]",
+ "name": "[variables('servicePlanName')]",
+ "apiVersion": "2018-02-01",
+ "location": "[variables('resourcesLocation')]",
+ "sku": "[parameters('newAppServicePlanSku')]",
+ "kind": "linux",
+ "properties": {
+ "perSiteScaling": false,
+ "maximumElasticWorkerCount": 1,
+ "isSpot": false,
+ "reserved": true,
+ "isXenon": false,
+ "hyperV": false,
+ "targetWorkerCount": 0,
+ "targetWorkerSizeId": 0
+ }
+ },
+ {
+ "comments": "Create a Web App using a Linux App Service Plan",
+ "type": "Microsoft.Web/sites",
+ "apiVersion": "2018-11-01",
+ "location": "[variables('resourcesLocation')]",
+ "kind": "app,linux",
+ "dependsOn": [
+ "[resourceId('Microsoft.Web/serverfarms', variables('servicePlanName'))]"
+ ],
+ "name": "[variables('webAppName')]",
+ "properties": {
+ "name": "[variables('webAppName')]",
+ "hostNameSslStates": [
+ {
+ "name": "[concat(parameters('newWebAppName'), '.azurewebsites.net')]",
+ "sslState": "Disabled",
+ "hostType": "Standard"
+ },
+ {
+ "name": "[concat(parameters('newWebAppName'), '.scm.azurewebsites.net')]",
+ "sslState": "Disabled",
+ "hostType": "Repository"
+ }
+ ],
+ "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('servicePlanName'))]",
+ "reserved": true,
+ "isXenon": false,
+ "hyperV": false,
+ "scmSiteAlsoStopped": false,
+ "clientAffinityEnabled": true,
+ "clientCertEnabled": false,
+ "hostNamesDisabled": false,
+ "containerSize": 0,
+ "dailyMemoryTimeQuota": 0,
+ "httpsOnly": false,
+ "redundancyMode": "None",
+ "siteConfig": {
+ "appSettings": [
+ {
+ "name": "JAVA_OPTS",
+ "value": "-Dserver.port=80"
+ },
+ {
+ "name": "MicrosoftAppId",
+ "value": "[parameters('appId')]"
+ },
+ {
+ "name": "MicrosoftAppPassword",
+ "value": "[parameters('appSecret')]"
+ }
+ ],
+ "cors": {
+ "allowedOrigins": [
+ "https://botservice.hosting.portal.azure.net",
+ "https://hosting.onecloud.azure-test.net/"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "type": "Microsoft.Web/sites/config",
+ "apiVersion": "2018-11-01",
+ "name": "[concat(variables('webAppName'), '/web')]",
+ "location": "[variables('resourcesLocation')]",
+ "dependsOn": [
+ "[resourceId('Microsoft.Web/sites/', variables('webAppName'))]"
+ ],
+ "properties": {
+ "numberOfWorkers": 1,
+ "defaultDocuments": [
+ "Default.htm",
+ "Default.html",
+ "Default.asp",
+ "index.htm",
+ "index.html",
+ "iisstart.htm",
+ "default.aspx",
+ "index.php",
+ "hostingstart.html"
+ ],
+ "netFrameworkVersion": "v4.0",
+ "linuxFxVersion": "JAVA|8-jre8",
+ "requestTracingEnabled": false,
+ "remoteDebuggingEnabled": false,
+ "httpLoggingEnabled": false,
+ "logsDirectorySizeLimit": 35,
+ "detailedErrorLoggingEnabled": false,
+ "publishingUsername": "[variables('publishingUsername')]",
+ "scmType": "None",
+ "use32BitWorkerProcess": true,
+ "webSocketsEnabled": false,
+ "alwaysOn": true,
+ "managedPipelineMode": "Integrated",
+ "virtualApplications": [
+ {
+ "virtualPath": "/",
+ "physicalPath": "site\\wwwroot",
+ "preloadEnabled": true
+ }
+ ],
+ "loadBalancing": "LeastRequests",
+ "experiments": {
+ "rampUpRules": []
+ },
+ "autoHealEnabled": false,
+ "localMySqlEnabled": false,
+ "ipSecurityRestrictions": [
+ {
+ "ipAddress": "Any",
+ "action": "Allow",
+ "priority": 1,
+ "name": "Allow all",
+ "description": "Allow all access"
+ }
+ ],
+ "scmIpSecurityRestrictions": [
+ {
+ "ipAddress": "Any",
+ "action": "Allow",
+ "priority": 1,
+ "name": "Allow all",
+ "description": "Allow all access"
+ }
+ ],
+ "scmIpSecurityRestrictionsUseMain": false,
+ "http20Enabled": false,
+ "minTlsVersion": "1.2",
+ "ftpsState": "AllAllowed",
+ "reservedInstanceCount": 0
+ }
+ },
+ {
+ "apiVersion": "2017-12-01",
+ "type": "Microsoft.BotService/botServices",
+ "name": "[parameters('botId')]",
+ "location": "global",
+ "kind": "bot",
+ "sku": {
+ "name": "[parameters('botSku')]"
+ },
+ "properties": {
+ "name": "[parameters('botId')]",
+ "displayName": "[parameters('botId')]",
+ "endpoint": "[variables('botEndpoint')]",
+ "msaAppId": "[parameters('appId')]",
+ "developerAppInsightsApplicationId": null,
+ "developerAppInsightKey": null,
+ "publishingCredentials": null,
+ "storageResourceId": null
+ },
+ "dependsOn": [
+ "[resourceId('Microsoft.Web/sites/', variables('webAppName'))]"
+ ]
+ }
+ ]
+}
diff --git a/samples/07.using-adaptive-cards/pom.xml b/samples/07.using-adaptive-cards/pom.xml
new file mode 100644
index 00000000..ece6a390
--- /dev/null
+++ b/samples/07.using-adaptive-cards/pom.xml
@@ -0,0 +1,249 @@
+
+
+
+ * The @Component annotation could be used on the Bot class instead of this method + * with the @Bean annotation. + *
+ * + * @return The Bot implementation for this application. + */ + @Bean + public Bot getBot() { + return new AdaptiveCardsBot(); + } + + /** + * Returns a custom Adapter that provides error handling. + * + * @param configuration The Configuration object to use. + * @return An error handling BotFrameworkHttpAdapter. + */ + @Override + public BotFrameworkHttpAdapter getBotFrameworkHttpAdaptor(Configuration configuration) { + return new AdapterWithErrorHandler(configuration); + } +} diff --git a/samples/07.using-adaptive-cards/src/main/java/com/microsoft/bot/sample/usingadaptivecards/bots/AdaptiveCardsBot.java b/samples/07.using-adaptive-cards/src/main/java/com/microsoft/bot/sample/usingadaptivecards/bots/AdaptiveCardsBot.java new file mode 100644 index 00000000..a64e090e --- /dev/null +++ b/samples/07.using-adaptive-cards/src/main/java/com/microsoft/bot/sample/usingadaptivecards/bots/AdaptiveCardsBot.java @@ -0,0 +1,97 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MT License. + +package com.microsoft.bot.sample.usingadaptivecards.bots; + +import java.io.InputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Random; +import java.util.concurrent.CompletableFuture; + + +import com.microsoft.bot.builder.ActivityHandler; +import com.microsoft.bot.builder.MessageFactory; +import com.microsoft.bot.builder.TurnContext; +import com.microsoft.bot.schema.Attachment; +import com.microsoft.bot.schema.ChannelAccount; +import com.microsoft.bot.schema.Serialization; + +import org.apache.commons.io.IOUtils; + +// This bot will respond to the user's input with an Adaptive Card. +// Adaptive Cards are a way for developers to exchange card content +// in a common and consistent way. A simple open card format enables +// an ecosystem of shared tooling, seamless integration between apps, +// and native cross-platform performance on any device. +// For each user interaction, an instance of this class instanceof created and the OnTurnAsync method instanceof called. +// This instanceof a Transient lifetime service. Transient lifetime services are created +// each time they're requested. For each Activity received, a new instance of this +// class instanceof created. Objects that are expensive to construct, or have a lifetime +// beyond the single turn, should be carefully managed. + +public class AdaptiveCardsBot extends ActivityHandler { + + private static final String welcomeText = "This bot will introduce you to AdaptiveCards. " + + "Type anything to see an AdaptiveCard."; + + // This array contains the file names of our adaptive cards + private final String[] cards = { + "FlightItineraryCard.json", + "ImageGalleryCard.json", + "LargeWeatherCard.json", + "RestaurantCard.json", + "SolitaireCard.json" + }; + + @Override + protected CompletableFuture