From fd6c3b67a4bc737d5b73565a801b104123d3ab45 Mon Sep 17 00:00:00 2001 From: tracyboehrer Date: Tue, 7 Apr 2020 15:59:53 -0500 Subject: [PATCH 1/2] Added 55.teams-link-unfurling --- pom.xml | 1 + samples/55.teams-link-unfurling/LICENSE | 21 + samples/55.teams-link-unfurling/README.md | 60 +++ .../new-rg-parameters.json | 42 ++ .../preexisting-rg-parameters.json | 39 ++ .../template-with-new-rg.json | 191 ++++++++ .../template-with-preexisting-rg.json | 158 +++++++ samples/55.teams-link-unfurling/pom.xml | 315 +++++++++++++ .../bot/sample/teamsunfurl/Application.java | 46 ++ .../sample/teamsunfurl/LinkUnfurlingBot.java | 89 ++++ .../src/main/resources/application.properties | 2 + .../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 ++++++++++++++++++ .../sample/teamsunfurl/ApplicationTests.java | 19 + .../teamsAppManifest/icon-color.png | Bin 0 -> 1229 bytes .../teamsAppManifest/icon-outline.png | Bin 0 -> 383 bytes .../teamsAppManifest/manifest.json | 58 +++ 19 files changed, 1492 insertions(+) create mode 100644 samples/55.teams-link-unfurling/LICENSE create mode 100644 samples/55.teams-link-unfurling/README.md create mode 100644 samples/55.teams-link-unfurling/deploymentTemplates/new-rg-parameters.json create mode 100644 samples/55.teams-link-unfurling/deploymentTemplates/preexisting-rg-parameters.json create mode 100644 samples/55.teams-link-unfurling/deploymentTemplates/template-with-new-rg.json create mode 100644 samples/55.teams-link-unfurling/deploymentTemplates/template-with-preexisting-rg.json create mode 100644 samples/55.teams-link-unfurling/pom.xml create mode 100644 samples/55.teams-link-unfurling/src/main/java/com/microsoft/bot/sample/teamsunfurl/Application.java create mode 100644 samples/55.teams-link-unfurling/src/main/java/com/microsoft/bot/sample/teamsunfurl/LinkUnfurlingBot.java create mode 100644 samples/55.teams-link-unfurling/src/main/resources/application.properties create mode 100644 samples/55.teams-link-unfurling/src/main/resources/log4j2.json create mode 100644 samples/55.teams-link-unfurling/src/main/webapp/META-INF/MANIFEST.MF create mode 100644 samples/55.teams-link-unfurling/src/main/webapp/WEB-INF/web.xml create mode 100644 samples/55.teams-link-unfurling/src/main/webapp/index.html create mode 100644 samples/55.teams-link-unfurling/src/test/java/com/microsoft/bot/sample/teamsunfurl/ApplicationTests.java create mode 100644 samples/55.teams-link-unfurling/teamsAppManifest/icon-color.png create mode 100644 samples/55.teams-link-unfurling/teamsAppManifest/icon-outline.png create mode 100644 samples/55.teams-link-unfurling/teamsAppManifest/manifest.json diff --git a/pom.xml b/pom.xml index 488cdd1a5..388d68327 100644 --- a/pom.xml +++ b/pom.xml @@ -379,6 +379,7 @@ samples/51.teams-messaging-extensions-action samples/52.teams-messaging-extensions-search-auth-config samples/53.teams-messaging-extensions-action-preview + samples/55.teams-link-unfurling samples/57.teams-conversation-bot diff --git a/samples/55.teams-link-unfurling/LICENSE b/samples/55.teams-link-unfurling/LICENSE new file mode 100644 index 000000000..21071075c --- /dev/null +++ b/samples/55.teams-link-unfurling/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/55.teams-link-unfurling/README.md b/samples/55.teams-link-unfurling/README.md new file mode 100644 index 000000000..7a2446381 --- /dev/null +++ b/samples/55.teams-link-unfurling/README.md @@ -0,0 +1,60 @@ + +# Teams Link Unfurl Bot + +Bot Framework v4 Teams [link unfurling](https://docs.microsoft.com/en-us/microsoftteams/platform/messaging-extensions/how-to/link-unfurling?tabs=json) bot sample for Teams. + +This bot has been created using [Bot Framework](https://dev.botframework.com), it shows how to create a simple bot that performs link unfurling in Teams. + +## Prerequisites + +- Microsoft Teams is installed and you have an account +- [ngrok](https://ngrok.com/) or equivalent tunnelling solution + +## To try this sample + +> Note these instructions are for running the sample on your local machine, the tunnelling solution is required because +the Teams service needs to call into the bot. + +1) Clone the repository + + ```bash + git clone https://github.com/Microsoft/botbuilder-java.git + ``` + +1) Run ngrok - point to port 8080 + + ```bash + ngrok http -host-header=rewrite 8080 + ``` + +1) Create [Bot Framework registration resource](https://docs.microsoft.com/en-us/azure/bot-service/bot-service-quickstart-registration) in Azure + - Use the current `https` URL you were given by running ngrok. Append with the path `/api/messages` used by this sample + - Ensure that you've [enabled the Teams Channel](https://docs.microsoft.com/en-us/azure/bot-service/channel-connect-teams?view=azure-bot-service-4.0) + - __*If you don't have an Azure account*__ you can use this [Bot Framework registration](https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/create-a-bot-for-teams#register-your-web-service-with-the-bot-framework) + +1) Update the `resources/application.properties` configuration for the bot to use the Microsoft App Id and App Password from the Bot Framework registration. (Note the App Password is referred to as the "client secret" in the azure portal and you can always create a new client secret anytime.) + +1) __*This step is specific to Teams.*__ + - **Edit** the `manifest.json` contained in the `teamsAppManifest` folder to replace your Microsoft App Id (that was created when you registered your bot earlier) *everywhere* you see the place holder string `<>` (depending on the scenario the Microsoft App Id may occur multiple times in the `manifest.json`) + - **Zip** up the contents of the `teamsAppManifest` folder to create a `manifest.zip` + - **Upload** the `manifest.zip` to Teams (in the Apps view click "Upload a custom app") + +1) From the root of this project folder: + - Build the sample using `mvn package` + - Unless done previously, install the packages in the local cache by using `mvn install` + - Run it by using `java -jar .\target\bot-teams-link-unfurl-sample.jar` + +## Interacting with the bot in Teams + +> Note the Teams `manifest.json` for this sample also includes a Search Query. This Messaging Extension is only introduced in order to enable installation, because there is no mechanism for installing a link unfurling feature in isolation. + +If you copy and paste a link from https://www.BotFramework.com into the compose message area the link will unfurl. + +## 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 + +- [How Microsoft Teams bots work](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-basics-teams?view=azure-bot-service-4.0&tabs=javascript) + diff --git a/samples/55.teams-link-unfurling/deploymentTemplates/new-rg-parameters.json b/samples/55.teams-link-unfurling/deploymentTemplates/new-rg-parameters.json new file mode 100644 index 000000000..ead339093 --- /dev/null +++ b/samples/55.teams-link-unfurling/deploymentTemplates/new-rg-parameters.json @@ -0,0 +1,42 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "groupLocation": { + "value": "" + }, + "groupName": { + "value": "" + }, + "appId": { + "value": "" + }, + "appSecret": { + "value": "" + }, + "botId": { + "value": "" + }, + "botSku": { + "value": "" + }, + "newAppServicePlanName": { + "value": "" + }, + "newAppServicePlanSku": { + "value": { + "name": "S1", + "tier": "Standard", + "size": "S1", + "family": "S", + "capacity": 1 + } + }, + "newAppServicePlanLocation": { + "value": "" + }, + "newWebAppName": { + "value": "" + } + } +} \ No newline at end of file diff --git a/samples/55.teams-link-unfurling/deploymentTemplates/preexisting-rg-parameters.json b/samples/55.teams-link-unfurling/deploymentTemplates/preexisting-rg-parameters.json new file mode 100644 index 000000000..b6f5114fc --- /dev/null +++ b/samples/55.teams-link-unfurling/deploymentTemplates/preexisting-rg-parameters.json @@ -0,0 +1,39 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "appId": { + "value": "" + }, + "appSecret": { + "value": "" + }, + "botId": { + "value": "" + }, + "botSku": { + "value": "" + }, + "newAppServicePlanName": { + "value": "" + }, + "newAppServicePlanSku": { + "value": { + "name": "S1", + "tier": "Standard", + "size": "S1", + "family": "S", + "capacity": 1 + } + }, + "appServicePlanLocation": { + "value": "" + }, + "existingAppServicePlan": { + "value": "" + }, + "newWebAppName": { + "value": "" + } + } +} \ No newline at end of file diff --git a/samples/55.teams-link-unfurling/deploymentTemplates/template-with-new-rg.json b/samples/55.teams-link-unfurling/deploymentTemplates/template-with-new-rg.json new file mode 100644 index 000000000..dcd6260a5 --- /dev/null +++ b/samples/55.teams-link-unfurling/deploymentTemplates/template-with-new-rg.json @@ -0,0 +1,191 @@ +{ + "$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": "F0", + "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": { + "resourcesLocation": "[deployment().location]", + "effectiveGroupLocation": "[if(empty(parameters('groupLocation')), variables('resourcesLocation'), parameters('groupLocation'))]", + "effectivePlanLocation": "[if(empty(parameters('newAppServicePlanLocation')), variables('resourcesLocation'), parameters('newAppServicePlanLocation'))]", + "appServicePlanName": "[if(empty(parameters('newAppServicePlanName')), concat(parameters('botId'), 'ServicePlan'), parameters('newAppServicePlanName'))]", + "webAppName": "[if(empty(parameters('newWebAppName')), parameters('botId'), parameters('newWebAppName'))]", + "siteHost": "[concat(variables('webAppName'), '.azurewebsites.net')]", + "botEndpoint": "[concat('https://', variables('siteHost'), '/api/messages')]" + }, + "resources": [ + { + "name": "[parameters('groupName')]", + "type": "Microsoft.Resources/resourceGroups", + "apiVersion": "2018-05-01", + "location": "[variables('effectiveGroupLocation')]", + "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 App Service Plan", + "type": "Microsoft.Web/serverfarms", + "name": "[variables('appServicePlanName')]", + "apiVersion": "2018-02-01", + "location": "[variables('effectivePlanLocation')]", + "sku": "[parameters('newAppServicePlanSku')]", + "kind": "linux", + "properties": { + "name": "[variables('appServicePlanName')]", + "reserved":true + } + }, + { + "comments": "Create a Web App using the new App Service Plan", + "type": "Microsoft.Web/sites", + "apiVersion": "2015-08-01", + "location": "[variables('resourcesLocation')]", + "kind": "app", + "dependsOn": [ + "[resourceId('Microsoft.Web/serverfarms/', variables('appServicePlanName'))]" + ], + "name": "[variables('webAppName')]", + "properties": { + "name": "[variables('webAppName')]", + "serverFarmId": "[variables('appServicePlanName')]", + "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/" + ] + } + } + } + }, + { + "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'))]" + ] + } + ], + "outputs": {} + } + } + } + ] +} \ No newline at end of file diff --git a/samples/55.teams-link-unfurling/deploymentTemplates/template-with-preexisting-rg.json b/samples/55.teams-link-unfurling/deploymentTemplates/template-with-preexisting-rg.json new file mode 100644 index 000000000..b790d2bdc --- /dev/null +++ b/samples/55.teams-link-unfurling/deploymentTemplates/template-with-preexisting-rg.json @@ -0,0 +1,158 @@ +{ + "$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'), if(empty(parameters('newAppServicePlanName')),concat(parameters('botId'), 'ServicePlan'),parameters('newAppServicePlanName')))]", + "resourcesLocation": "[if(empty(parameters('appServicePlanLocation')), resourceGroup().location, 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 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": { + "name": "[variables('servicePlanName')]", + "reserved":true + } + }, + { + "comments": "Create a Web App using an App Service Plan", + "type": "Microsoft.Web/sites", + "apiVersion": "2016-08-01", + "location": "[variables('resourcesLocation')]", + "kind": "app", + "dependsOn": [ + "[resourceId('Microsoft.Web/serverfarms/', variables('servicePlanName'))]" + ], + "name": "[variables('webAppName')]", + "properties": { + "name": "[variables('webAppName')]", + "serverFarmId": "[variables('servicePlanName')]", + "siteConfig": { + "linuxFxVersion": "JAVA|8-jre8", + "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/" + ] + } + } + } + }, + { + "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'))]" + ] + } + ] +} \ No newline at end of file diff --git a/samples/55.teams-link-unfurling/pom.xml b/samples/55.teams-link-unfurling/pom.xml new file mode 100644 index 000000000..d4179a386 --- /dev/null +++ b/samples/55.teams-link-unfurling/pom.xml @@ -0,0 +1,315 @@ + + + + 4.0.0 + + com.microsoft.bot.sample + bot-teams-link-unfurl + sample + jar + + ${project.groupId}:${project.artifactId} + This package contains a Java Teams Link Unfurl sample using Spring Boot. + http://maven.apache.org + + + org.springframework.boot + spring-boot-starter-parent + 2.1.7.RELEASE + + + + + + MIT License + http://www.opensource.org/licenses/mit-license.php + + + + + + Bot Framework Development + + Microsoft + https://dev.botframework.com/ + + + + + UTF-8 + UTF-8 + 1.8 + 1.8 + 1.8 + com.microsoft.bot.sample.teamsunfurl.Application + https://botbuilder.myget.org/F/botbuilder-v4-java-daily/maven/ + + + + + junit + junit + 4.12 + test + + + org.springframework.boot + spring-boot-starter-test + 2.1.8.RELEASE + test + + + + org.slf4j + slf4j-api + + + org.apache.logging.log4j + log4j-api + 2.11.0 + + + org.apache.logging.log4j + log4j-core + 2.11.0 + + + + com.microsoft.bot + bot-integration-spring + 4.0.0-SNAPSHOT + compile + + + + + + MyGet + ${repo.url} + + + + + + ossrh + + https://oss.sonatype.org/ + + + + + + + build + + true + + + + + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + maven-war-plugin + 3.2.3 + + src/main/webapp + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + com.microsoft.bot.sample.teamsunfurl.Application + + + + + + com.microsoft.azure + azure-webapp-maven-plugin + 1.7.0 + + V2 + {groupname} + {botname} + + + JAVA_OPTS + -Dserver.port=80 + + + + linux + jre8 + jre8 + + + + + ${project.basedir}/target + + *.jar + + + + + + + + org.eluder.coveralls + coveralls-maven-plugin + 4.3.0 + + yourcoverallsprojectrepositorytoken + + + + org.codehaus.mojo + cobertura-maven-plugin + 2.7 + + ../../cobertura-report/spring-teamsunfurl-sample + xml + 256m + + true + + + + + + org.apache.maven.plugins + maven-site-plugin + 3.7.1 + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 3.0.0 + + + + + + + + publish + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.8 + true + + true + ossrh + https://oss.sonatype.org/ + true + + + + + org.apache.maven.plugins + maven-gpg-plugin + + + sign-artifacts + verify + + sign + + + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + 8 + false + + + + attach-javadocs + + jar + + + + + + + + + + + + + org.apache.maven.plugins + maven-pmd-plugin + 3.12.0 + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.1.0 + + + + checkstyle + + + + + + + + diff --git a/samples/55.teams-link-unfurling/src/main/java/com/microsoft/bot/sample/teamsunfurl/Application.java b/samples/55.teams-link-unfurling/src/main/java/com/microsoft/bot/sample/teamsunfurl/Application.java new file mode 100644 index 000000000..2bb526955 --- /dev/null +++ b/samples/55.teams-link-unfurling/src/main/java/com/microsoft/bot/sample/teamsunfurl/Application.java @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.bot.sample.teamsunfurl; + +import com.microsoft.bot.integration.AdapterWithErrorHandler; +import com.microsoft.bot.integration.BotFrameworkHttpAdapter; +import com.microsoft.bot.integration.Configuration; +import com.microsoft.bot.integration.spring.BotController; +import com.microsoft.bot.integration.spring.BotDependencyConfiguration; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Import; + +/** + * This is the starting point of the Sprint Boot Bot application. + * + * This class also provides overrides for dependency injections. A class that extends the + * {@link com.microsoft.bot.builder.Bot} interface should be annotated with @Component. + * + * @see LinkUnfurlingBot + */ +@SpringBootApplication + +// Use the default BotController to receive incoming Channel messages. A custom controller +// could be used by eliminating this import and creating a new RestController. The default +// controller is created by the Spring Boot container using dependency injection. The +// default route is /api/messages. +@Import({BotController.class}) + +public class Application extends BotDependencyConfiguration { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + + /** + * 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/55.teams-link-unfurling/src/main/java/com/microsoft/bot/sample/teamsunfurl/LinkUnfurlingBot.java b/samples/55.teams-link-unfurling/src/main/java/com/microsoft/bot/sample/teamsunfurl/LinkUnfurlingBot.java new file mode 100644 index 000000000..8277a408e --- /dev/null +++ b/samples/55.teams-link-unfurling/src/main/java/com/microsoft/bot/sample/teamsunfurl/LinkUnfurlingBot.java @@ -0,0 +1,89 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.bot.sample.teamsunfurl; + +import com.microsoft.bot.builder.TurnContext; +import com.microsoft.bot.builder.teams.TeamsActivityHandler; +import com.microsoft.bot.schema.CardImage; +import com.microsoft.bot.schema.HeroCard; +import com.microsoft.bot.schema.ThumbnailCard; +import com.microsoft.bot.schema.teams.AppBasedLinkQuery; +import com.microsoft.bot.schema.teams.MessagingExtensionAttachment; +import com.microsoft.bot.schema.teams.MessagingExtensionQuery; +import com.microsoft.bot.schema.teams.MessagingExtensionResponse; +import com.microsoft.bot.schema.teams.MessagingExtensionResult; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import java.util.Collections; +import java.util.concurrent.CompletableFuture; + +/** + * This class implements the functionality of the Bot. + * + *

This is where application specific logic for interacting with the users would be + * added.

+ */ +@Component +public class LinkUnfurlingBot extends TeamsActivityHandler { + @Override + protected CompletableFuture onTeamsAppBasedLinkQuery( + TurnContext turnContext, + AppBasedLinkQuery query + ) { + ThumbnailCard card = new ThumbnailCard() {{ + setTitle("Thumbnail Card"); + setText(query.getUrl()); + setImages(Collections.singletonList( + new CardImage("https://raw.githubusercontent.com/microsoft/botframework-sdk/master/icon.png") + )); + }}; + + MessagingExtensionAttachment attachments = new MessagingExtensionAttachment() {{ + setContentType(HeroCard.CONTENTTYPE); + setContent(card); + }}; + + MessagingExtensionResult result = new MessagingExtensionResult() {{ + setAttachmentLayout("list"); + setType("result"); + setAttachments(Collections.singletonList(attachments)); + }}; + + return CompletableFuture.completedFuture(new MessagingExtensionResponse(result)); + } + + protected CompletableFuture onTeamsMessagingExtensionQuery( + TurnContext turnContext, + MessagingExtensionQuery query + ) { + //Note: The Teams manifest.json for this sample also includes a Search Query, in order to enable installing from App Studio. + + // These commandIds are defined in the Teams App Manifest. + if (StringUtils.equalsIgnoreCase("searchQuery", query.getCommandId())) { + HeroCard card = new HeroCard() {{ + setTitle("This is a Link Unfurling Sample"); + setSubtitle("It will unfurl links from *.BotFramework.com"); + setText("This sample demonstrates how to handle link unfurling in Teams. " + + "Please review the readme for more information."); + }}; + + return CompletableFuture.completedFuture(new MessagingExtensionResponse( + new MessagingExtensionResult() {{ + setAttachmentLayout("list"); + setType("result"); + setAttachment( + new MessagingExtensionAttachment() {{ + setContent(card); + setContentType(HeroCard.CONTENTTYPE); + setPreview(card.toAttachment()); + }} + ); + }} + )); + } + + return notImplemented(String.format("Invalid CommandId: %s", query.getCommandId())); + } +} diff --git a/samples/55.teams-link-unfurling/src/main/resources/application.properties b/samples/55.teams-link-unfurling/src/main/resources/application.properties new file mode 100644 index 000000000..a695b3bf0 --- /dev/null +++ b/samples/55.teams-link-unfurling/src/main/resources/application.properties @@ -0,0 +1,2 @@ +MicrosoftAppId= +MicrosoftAppPassword= diff --git a/samples/55.teams-link-unfurling/src/main/resources/log4j2.json b/samples/55.teams-link-unfurling/src/main/resources/log4j2.json new file mode 100644 index 000000000..67c0ad530 --- /dev/null +++ b/samples/55.teams-link-unfurling/src/main/resources/log4j2.json @@ -0,0 +1,18 @@ +{ + "configuration": { + "name": "Default", + "appenders": { + "Console": { + "name": "Console-Appender", + "target": "SYSTEM_OUT", + "PatternLayout": {"pattern": "[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n"} + } + }, + "loggers": { + "root": { + "level": "debug", + "appender-ref": {"ref": "Console-Appender","level": "debug"} + } + } + } +} diff --git a/samples/55.teams-link-unfurling/src/main/webapp/META-INF/MANIFEST.MF b/samples/55.teams-link-unfurling/src/main/webapp/META-INF/MANIFEST.MF new file mode 100644 index 000000000..254272e1c --- /dev/null +++ b/samples/55.teams-link-unfurling/src/main/webapp/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/samples/55.teams-link-unfurling/src/main/webapp/WEB-INF/web.xml b/samples/55.teams-link-unfurling/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..383c19004 --- /dev/null +++ b/samples/55.teams-link-unfurling/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,12 @@ + + + dispatcher + + org.springframework.web.servlet.DispatcherServlet + + + contextConfigLocation + /WEB-INF/spring/dispatcher-config.xml + + 1 + \ No newline at end of file diff --git a/samples/55.teams-link-unfurling/src/main/webapp/index.html b/samples/55.teams-link-unfurling/src/main/webapp/index.html new file mode 100644 index 000000000..40b74c007 --- /dev/null +++ b/samples/55.teams-link-unfurling/src/main/webapp/index.html @@ -0,0 +1,418 @@ + + + + + + + EchoBot + + + + + +
+
+
+
Spring Boot Bot
+
+
+
+
+
Your bot is ready!
+
You can test your bot in the Bot Framework Emulator
+ by connecting to http://localhost:8080/api/messages.
+ +
Visit Azure + Bot Service to register your bot and add it to
+ various channels. The bot's endpoint URL typically looks + like this:
+
https://your_bots_hostname/api/messages
+
+
+
+
+ +
+ + + diff --git a/samples/55.teams-link-unfurling/src/test/java/com/microsoft/bot/sample/teamsunfurl/ApplicationTests.java b/samples/55.teams-link-unfurling/src/test/java/com/microsoft/bot/sample/teamsunfurl/ApplicationTests.java new file mode 100644 index 000000000..b653c4e76 --- /dev/null +++ b/samples/55.teams-link-unfurling/src/test/java/com/microsoft/bot/sample/teamsunfurl/ApplicationTests.java @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.bot.sample.teamsunfurl; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class ApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/samples/55.teams-link-unfurling/teamsAppManifest/icon-color.png b/samples/55.teams-link-unfurling/teamsAppManifest/icon-color.png new file mode 100644 index 0000000000000000000000000000000000000000..48a2de13303e1e8a25f76391f4a34c7c4700fd3d GIT binary patch literal 1229 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD1|%QND7OGojKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCe1|JzX3_D&pSWuFnWfl{x;g|9jrEYf8Vqrkk2Ba|%ol3OT){=#|7ID~|e{ zODQ{kU&ME#@`*-tm%Tukt_gFr+`F?$dx9wg-jad`^gsMn2_%Kh%WH91&SjKq5 zgkdI|!exdOVgw@>>=!Tjnk6q)zV*T8$FdgRFYC{kQ7``NOcl@R(_%_8e5e0E;>v0G zEM9kb)2itgOTSfH7M=b3-S61B?PiazMdwXZwrS)^5UUS#HQjaoua5h_{Gx*_Zz|XK z$tf0mZ&=tpf2!!Q)!A_l&o_$g*|JM$VZa~F^0{x1T{=QFu*x$`=V%~jUW=G`iqqp=lquB-`P{Qjw`=zEu3cMc_x7m2f#9m}uoFBMMQ^+%cOL)F_)N@JZ}Axoxi1y= zeebq`y==e!nl+?cK-PhOec!3%|IupShHrcjW8sSt)F1>NW*{ zW%ljk2)nk%-}+F&?gi=7^$L#VeX3@kp%f{n}fR z`}uZPx$IY~r8R5%gMlrc`jP!L3IloKFoq~sFFH5|cdklX=R08T)}71BhaN8$`AsNf0_ zq>WNhAtCd|-nBlTU=y5zl_vXlXZ~bkuaYENMp>3QSQ_#zuYZ+eQh*OIHRxP~s(}ic zN2J4$u=AQcPt)|>F3zZLsjtP;Tajkugx;NcYED2~JVBlVO>{`uAY?Q4O|AA z=16}CJieK^5P_TKnou!zGR`$!PUC)DqtkO;?!`p!+9v3lP_mu=%Vt3BkoWsq%;FN1sp58w*zfr-z^7tIb*q>!yncCjrzLuOk3N+d&~^Cxd| z>", + "packageName": "com.teams.sample.linkunfurling", + "developer": { + "name": "Link Unfurling", + "websiteUrl": "https://www.microsoft.com", + "privacyUrl": "https://www.teams.com/privacy", + "termsOfUseUrl": "https://www.teams.com/termsofuser" + }, + "icons": { + "color": "icon-color.png", + "outline": "icon-outline.png" + }, + "name": { + "short": "Link Unfurling", + "full": "Link Unfurling Sample" + }, + "description": { + "short": "Link Unfurling sample", + "full": "This sample demonstrates Link Unfurling for *.BotFramework.com urls." + }, + "accentColor": "#FFFFFF", + "composeExtensions": [ + { + "botId": "<>", + "commands": [ + { + "id": "searchQuery", + "context": [ "commandBox" ], + "description": "Test command to run query", + "title": "Search Command", + "type": "query", + "parameters": [ + { + "name": "searchQuery", + "title": "Search Query", + "description": "Your search query", + "inputType": "text" + } + ] + } + ], + "messageHandlers": [ + { + "type": "link", + "value": { + "domains": [ + "*.botframework.com" + ] + } + } + ] + } + ] +} From b49ac5908cc6d483b7a946291439f9109c642966 Mon Sep 17 00:00:00 2001 From: tracyboehrer Date: Fri, 17 Apr 2020 16:15:39 -0500 Subject: [PATCH 2/2] Style updates --- .../bot/sample/teamsunfurl/Application.java | 7 ++--- .../sample/teamsunfurl/LinkUnfurlingBot.java | 27 ++++++++++--------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/samples/55.teams-link-unfurling/src/main/java/com/microsoft/bot/sample/teamsunfurl/Application.java b/samples/55.teams-link-unfurling/src/main/java/com/microsoft/bot/sample/teamsunfurl/Application.java index 2bb526955..889cf95cb 100644 --- a/samples/55.teams-link-unfurling/src/main/java/com/microsoft/bot/sample/teamsunfurl/Application.java +++ b/samples/55.teams-link-unfurling/src/main/java/com/microsoft/bot/sample/teamsunfurl/Application.java @@ -14,9 +14,9 @@ /** * This is the starting point of the Sprint Boot Bot application. - * - * This class also provides overrides for dependency injections. A class that extends the - * {@link com.microsoft.bot.builder.Bot} interface should be annotated with @Component. + *

+ * This class also provides overrides for dependency injections. A class that extends the {@link + * com.microsoft.bot.builder.Bot} interface should be annotated with @Component. * * @see LinkUnfurlingBot */ @@ -29,6 +29,7 @@ @Import({BotController.class}) public class Application extends BotDependencyConfiguration { + public static void main(String[] args) { SpringApplication.run(Application.class, args); } diff --git a/samples/55.teams-link-unfurling/src/main/java/com/microsoft/bot/sample/teamsunfurl/LinkUnfurlingBot.java b/samples/55.teams-link-unfurling/src/main/java/com/microsoft/bot/sample/teamsunfurl/LinkUnfurlingBot.java index 8277a408e..fcd9ea09a 100644 --- a/samples/55.teams-link-unfurling/src/main/java/com/microsoft/bot/sample/teamsunfurl/LinkUnfurlingBot.java +++ b/samples/55.teams-link-unfurling/src/main/java/com/microsoft/bot/sample/teamsunfurl/LinkUnfurlingBot.java @@ -27,28 +27,30 @@ */ @Component public class LinkUnfurlingBot extends TeamsActivityHandler { + @Override protected CompletableFuture onTeamsAppBasedLinkQuery( TurnContext turnContext, AppBasedLinkQuery query ) { ThumbnailCard card = new ThumbnailCard() {{ - setTitle("Thumbnail Card"); - setText(query.getUrl()); - setImages(Collections.singletonList( - new CardImage("https://raw.githubusercontent.com/microsoft/botframework-sdk/master/icon.png") - )); + setTitle("Thumbnail Card"); + setText(query.getUrl()); + setImages(Collections.singletonList( + new CardImage( + "https://raw.githubusercontent.com/microsoft/botframework-sdk/master/icon.png") + )); }}; MessagingExtensionAttachment attachments = new MessagingExtensionAttachment() {{ - setContentType(HeroCard.CONTENTTYPE); - setContent(card); + setContentType(HeroCard.CONTENTTYPE); + setContent(card); }}; MessagingExtensionResult result = new MessagingExtensionResult() {{ - setAttachmentLayout("list"); - setType("result"); - setAttachments(Collections.singletonList(attachments)); + setAttachmentLayout("list"); + setType("result"); + setAttachments(Collections.singletonList(attachments)); }}; return CompletableFuture.completedFuture(new MessagingExtensionResponse(result)); @@ -58,7 +60,8 @@ protected CompletableFuture onTeamsMessagingExtensio TurnContext turnContext, MessagingExtensionQuery query ) { - //Note: The Teams manifest.json for this sample also includes a Search Query, in order to enable installing from App Studio. + // Note: The Teams manifest.json for this sample also includes a Search Query, in + // order to enable installing from App Studio. // These commandIds are defined in the Teams App Manifest. if (StringUtils.equalsIgnoreCase("searchQuery", query.getCommandId())) { @@ -66,7 +69,7 @@ protected CompletableFuture onTeamsMessagingExtensio setTitle("This is a Link Unfurling Sample"); setSubtitle("It will unfurl links from *.BotFramework.com"); setText("This sample demonstrates how to handle link unfurling in Teams. " - + "Please review the readme for more information."); + + "Please review the readme for more information."); }}; return CompletableFuture.completedFuture(new MessagingExtensionResponse(