From 1652aabe82ee7e610acc8e632375a1d48c67b84a Mon Sep 17 00:00:00 2001 From: Lee Parrish <30470292+LeeParrishMSFT@users.noreply.github.com> Date: Mon, 1 Feb 2021 14:14:36 -0600 Subject: [PATCH 1/5] Completed sample --- samples/44.prompt-users-for-input/LICENSE | 21 + samples/44.prompt-users-for-input/README.md | 90 ++++ .../new-rg-parameters.json | 42 ++ .../preexisting-rg-parameters.json | 39 ++ .../template-with-new-rg.json | 191 ++++++++ .../template-with-preexisting-rg.json | 158 +++++++ samples/44.prompt-users-for-input/pom.xml | 244 ++++++++++ .../promptusersforinput/Application.java | 48 ++ .../sample/promptusersforinput/DialogBot.java | 55 +++ .../promptusersforinput/UserProfile.java | 13 + .../UserProfileDialog.java | 224 ++++++++++ .../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 ++++++++++++++++++ .../promptusersforinput/ApplicationTest.java | 19 + 17 files changed, 1598 insertions(+) create mode 100644 samples/44.prompt-users-for-input/LICENSE create mode 100644 samples/44.prompt-users-for-input/README.md create mode 100644 samples/44.prompt-users-for-input/deploymentTemplates/new-rg-parameters.json create mode 100644 samples/44.prompt-users-for-input/deploymentTemplates/preexisting-rg-parameters.json create mode 100644 samples/44.prompt-users-for-input/deploymentTemplates/template-with-new-rg.json create mode 100644 samples/44.prompt-users-for-input/deploymentTemplates/template-with-preexisting-rg.json create mode 100644 samples/44.prompt-users-for-input/pom.xml create mode 100644 samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/Application.java create mode 100644 samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/DialogBot.java create mode 100644 samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/UserProfile.java create mode 100644 samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/UserProfileDialog.java create mode 100644 samples/44.prompt-users-for-input/src/main/resources/application.properties create mode 100644 samples/44.prompt-users-for-input/src/main/resources/log4j2.json create mode 100644 samples/44.prompt-users-for-input/src/main/webapp/META-INF/MANIFEST.MF create mode 100644 samples/44.prompt-users-for-input/src/main/webapp/WEB-INF/web.xml create mode 100644 samples/44.prompt-users-for-input/src/main/webapp/index.html create mode 100644 samples/44.prompt-users-for-input/src/test/java/com/microsoft/bot/sample/promptusersforinput/ApplicationTest.java diff --git a/samples/44.prompt-users-for-input/LICENSE b/samples/44.prompt-users-for-input/LICENSE new file mode 100644 index 000000000..21071075c --- /dev/null +++ b/samples/44.prompt-users-for-input/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/44.prompt-users-for-input/README.md b/samples/44.prompt-users-for-input/README.md new file mode 100644 index 000000000..e4375c425 --- /dev/null +++ b/samples/44.prompt-users-for-input/README.md @@ -0,0 +1,90 @@ +# Multi-turn prompt + +Bot Framework v4 multi-turn prompt bot sample + +This bot has been created using [Bot Framework](https://dev.botframework.com), it shows how to use the prompts classes included in `botbuilder-dialogs`. This bot will ask for the user's name and age, then store the responses. It demonstrates a multi-turn dialog flow using a text prompt, a number prompt, and state accessors to store and retrieve values. + +## 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\bot-multiturnprompt-sample.jar` + +- Test 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 Bot Framework Emulator version 4.3.0 or greater 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` + +## Deploy the bot to Azure + +As described on [Deploy your bot](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-deploy-az-cli), you will perform the first 4 steps to setup the Azure app, then deploy the code using the azure-webapp Maven plugin. + +### 1. Login to Azure +From a command (or PowerShell) prompt in the root of the bot folder, execute: +`az login` + +### 2. Set the subscription +`az account set --subscription ""` + +If you aren't sure which subscription to use for deploying the bot, you can view the list of subscriptions for your account by using `az account list` command. + +### 3. Create an App registration +`az ad app create --display-name "" --password "" --available-to-other-tenants` + +Replace `` and `` with your own values. + +`` is the unique name of your bot. +`` is a minimum 16 character password for your bot. + +Record the `appid` from the returned JSON + +### 4. Create the Azure resources +Replace the values for ``, ``, ``, and `` in the following commands: + +#### To a new Resource Group +`az deployment create --name "stateBotDeploy" --location "westus" --template-file ".\deploymentTemplates\template-with-new-rg.json" --parameters groupName="" botId="" appId="" appSecret=""` + +#### To an existing Resource Group +`az group deployment create --name "stateBotDeploy" --resource-group "" --template-file ".\deploymentTemplates\template-with-preexisting-rg.json" --parameters botId="" appId="" appSecret=""` + +### 5. Update app id and password +In src/main/resources/application.properties update + - `MicrosoftAppPassword` with the botsecret value + - `MicrosoftAppId` with the appid from the first step + +### 6. Deploy the code +- Execute `mvn clean package` +- Execute `mvn azure-webapp:deploy -Dgroupname="" -Dbotname=""` + +If the deployment is successful, you will be able to test it via "Test in Web Chat" from the Azure Portal using the "Bot Channel Registration" for the bot. + +After the bot is deployed, you only need to execute #6 if you make changes to the bot. + + +## 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) +- [Dialogs](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-concept-dialog?view=azure-bot-service-4.0) +- [Gathering Input Using Prompts](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-prompts?view=azure-bot-service-4.0&tabs=csharp) +- [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) +- [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) +- [Maven Plugin for Azure App Service](https://docs.microsoft.com/en-us/java/api/overview/azure/maven/azure-webapp-maven-plugin/readme?view=azure-java-stable) +- [Spring Boot](https://spring.io/projects/spring-boot) +- [Azure for Java cloud developers](https://docs.microsoft.com/en-us/azure/java/?view=azure-java-stable) diff --git a/samples/44.prompt-users-for-input/deploymentTemplates/new-rg-parameters.json b/samples/44.prompt-users-for-input/deploymentTemplates/new-rg-parameters.json new file mode 100644 index 000000000..ead339093 --- /dev/null +++ b/samples/44.prompt-users-for-input/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/44.prompt-users-for-input/deploymentTemplates/preexisting-rg-parameters.json b/samples/44.prompt-users-for-input/deploymentTemplates/preexisting-rg-parameters.json new file mode 100644 index 000000000..b6f5114fc --- /dev/null +++ b/samples/44.prompt-users-for-input/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/44.prompt-users-for-input/deploymentTemplates/template-with-new-rg.json b/samples/44.prompt-users-for-input/deploymentTemplates/template-with-new-rg.json new file mode 100644 index 000000000..dcd6260a5 --- /dev/null +++ b/samples/44.prompt-users-for-input/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/44.prompt-users-for-input/deploymentTemplates/template-with-preexisting-rg.json b/samples/44.prompt-users-for-input/deploymentTemplates/template-with-preexisting-rg.json new file mode 100644 index 000000000..b790d2bdc --- /dev/null +++ b/samples/44.prompt-users-for-input/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/44.prompt-users-for-input/pom.xml b/samples/44.prompt-users-for-input/pom.xml new file mode 100644 index 000000000..7dfbebe83 --- /dev/null +++ b/samples/44.prompt-users-for-input/pom.xml @@ -0,0 +1,244 @@ + + + + 4.0.0 + + com.microsoft.bot.sample + bot-multiturnprompt + sample + jar + + ${project.groupId}:${project.artifactId} + This package contains the Multi-turn Prompt sample using Spring Boot. + http://maven.apache.org + + + org.springframework.boot + spring-boot-starter-parent + 2.4.0 + + + + + + MIT License + http://www.opensource.org/licenses/mit-license.php + + + + + + Bot Framework Development + + Microsoft + https://dev.botframework.com/ + + + + + 1.8 + 1.8 + 1.8 + com.microsoft.bot.sample.multiturnprompt.Application + + + + + org.springframework.boot + spring-boot-starter-test + 2.4.0 + test + + + junit + junit + 4.13.1 + test + + + org.junit.vintage + junit-vintage-engine + test + + + + org.slf4j + slf4j-api + + + org.apache.logging.log4j + log4j-api + 2.11.0 + + + org.apache.logging.log4j + log4j-core + 2.13.2 + + + + com.microsoft.bot + bot-integration-spring + 4.6.0-preview8 + compile + + + com.microsoft.bot + bot-dialogs + 4.6.0-preview8 + compile + + + + + + build + + true + + + + + src/main/resources + false + + + + + maven-compiler-plugin + 3.8.1 + + + maven-war-plugin + 3.2.3 + + src/main/webapp + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + com.microsoft.bot.sample.multiturnprompt.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 + + + + + + + + + + + + publish + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + maven-war-plugin + 3.2.3 + + src/main/webapp + + + + + 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 + + + + + + + + + diff --git a/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/Application.java b/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/Application.java new file mode 100644 index 000000000..1324a2348 --- /dev/null +++ b/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/Application.java @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.bot.sample.multiturnprompt; + +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 DialogBot + */ +@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/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/DialogBot.java b/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/DialogBot.java new file mode 100644 index 000000000..d71d53ed6 --- /dev/null +++ b/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/DialogBot.java @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.bot.sample.multiturnprompt; + +import com.microsoft.bot.builder.ActivityHandler; +import com.microsoft.bot.builder.BotState; +import com.microsoft.bot.builder.ConversationState; +import com.microsoft.bot.dialogs.Dialog; +import com.microsoft.bot.builder.TurnContext; +import com.microsoft.bot.builder.UserState; +import java.util.concurrent.CompletableFuture; +import org.springframework.stereotype.Component; + +/** + * This IBot implementation can run any type of Dialog. The use of type parameterization is to + * allows multiple different bots to be run at different endpoints within the same project. This + * can be achieved by defining distinct Controller types each with dependency on distinct IBot + * types, this way ASP Dependency Injection can glue everything together without ambiguity. The + * ConversationState is used by the Dialog system. The UserState isn't, however, it might have + * been used in a Dialog implementation, and the requirement is that all BotState objects are + * saved at the end of a turn. + */ +@Component +public class DialogBot extends ActivityHandler { + protected Dialog dialog; + protected BotState conversationState; + protected BotState userState; + + public DialogBot( + ConversationState withConversationState, + UserState withUserState, + Dialog withDialog + ) { + dialog = withDialog; + conversationState = withConversationState; + userState = withUserState; + } + + @Override + public CompletableFuture onTurn( + TurnContext turnContext + ) { + return super.onTurn(turnContext) + .thenCompose(result -> conversationState.saveChanges(turnContext)) + .thenCompose(result -> userState.saveChanges(turnContext)); + } + + @Override + protected CompletableFuture onMessageActivity( + TurnContext turnContext + ) { + return Dialog.run(dialog, turnContext, conversationState.createProperty("DialogState")); + } +} diff --git a/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/UserProfile.java b/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/UserProfile.java new file mode 100644 index 000000000..a04f2f72b --- /dev/null +++ b/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/UserProfile.java @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.bot.sample.multiturnprompt; + +import com.microsoft.bot.schema.Attachment; + +public class UserProfile { + public String transport; + public String name; + public Integer age; + public Attachment picture; +} diff --git a/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/UserProfileDialog.java b/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/UserProfileDialog.java new file mode 100644 index 000000000..302fe5d3a --- /dev/null +++ b/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/UserProfileDialog.java @@ -0,0 +1,224 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.bot.sample.multiturnprompt; + +import com.microsoft.bot.builder.MessageFactory; +import com.microsoft.bot.builder.StatePropertyAccessor; +import com.microsoft.bot.builder.UserState; +import com.microsoft.bot.connector.Channels; +import com.microsoft.bot.dialogs.ComponentDialog; +import com.microsoft.bot.dialogs.DialogTurnResult; +import com.microsoft.bot.dialogs.WaterfallDialog; +import com.microsoft.bot.dialogs.WaterfallStep; +import com.microsoft.bot.dialogs.WaterfallStepContext; +import com.microsoft.bot.dialogs.choices.ChoiceFactory; +import com.microsoft.bot.dialogs.choices.FoundChoice; +import com.microsoft.bot.dialogs.prompts.AttachmentPrompt; +import com.microsoft.bot.dialogs.prompts.ChoicePrompt; +import com.microsoft.bot.dialogs.prompts.ConfirmPrompt; +import com.microsoft.bot.dialogs.prompts.NumberPrompt; +import com.microsoft.bot.dialogs.prompts.PromptOptions; +import com.microsoft.bot.dialogs.prompts.PromptValidatorContext; +import com.microsoft.bot.dialogs.prompts.TextPrompt; +import com.microsoft.bot.schema.Attachment; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +@Component +public class UserProfileDialog extends ComponentDialog { + private StatePropertyAccessor userProfileAccessor; + + public UserProfileDialog(UserState withUserState) { + super("UserProfileDialog"); + + userProfileAccessor = withUserState.createProperty("UserProfile"); + + WaterfallStep[] waterfallSteps = { + UserProfileDialog::transportStep, + UserProfileDialog::nameStep, + UserProfileDialog::nameConfirmStep, + UserProfileDialog::ageStep, + UserProfileDialog::pictureStep, + UserProfileDialog::confirmStep, + this::summaryStep + }; + + // Add named dialogs to the DialogSet. These names are saved in the dialog state. + addDialog(new WaterfallDialog("WaterfallDialog", Arrays.asList(waterfallSteps))); + addDialog(new TextPrompt("TextPrompt")); + addDialog(new NumberPrompt("NumberPrompt", UserProfileDialog::agePromptValidator, Integer.class)); + addDialog(new ChoicePrompt("ChoicePrompt")); + addDialog(new ConfirmPrompt("ConfirmPrompt")); + addDialog(new AttachmentPrompt("AttachmentPrompt", UserProfileDialog::picturePromptValidator)); + + // The initial child Dialog to run. + setInitialDialogId("WaterfallDialog"); + } + + private static CompletableFuture transportStep(WaterfallStepContext stepContext) { + // WaterfallStep always finishes with the end of the Waterfall or with another dialog; here it is a Prompt Dialog. + // Running a prompt here means the next WaterfallStep will be run when the user's response is received. + PromptOptions promptOptions = new PromptOptions(); + promptOptions.setPrompt(MessageFactory.text("Please enter your mode of transport.")); + promptOptions.setChoices(ChoiceFactory.toChoices("Car", "Bus", "Bicycle")); + + return stepContext.prompt("ChoicePrompt", promptOptions); + } + + private static CompletableFuture nameStep(WaterfallStepContext stepContext) { + stepContext.getValues().put("transport", ((FoundChoice) stepContext.getResult()).getValue()); + + PromptOptions promptOptions = new PromptOptions(); + promptOptions.setPrompt(MessageFactory.text("Please enter your name.")); + return stepContext.prompt("TextPrompt", promptOptions); + } + + private static CompletableFuture nameConfirmStep(WaterfallStepContext stepContext) { + stepContext.getValues().put("name", stepContext.getResult()); + + // We can send messages to the user at any point in the WaterfallStep. + return stepContext.getContext().sendActivity(MessageFactory.text(String.format("Thanks %s", stepContext.getResult()))) + .thenCompose(resourceResponse -> { + // WaterfallStep always finishes with the end of the Waterfall or with another dialog; here it is a Prompt Dialog. + PromptOptions promptOptions = new PromptOptions(); + promptOptions.setPrompt(MessageFactory.text("Would you like to give your age?")); + return stepContext.prompt("ConfirmPrompt", promptOptions); + }); + } + + private static CompletableFuture ageStep(WaterfallStepContext stepContext) { + if ((Boolean)stepContext.getResult()) { + // User said "yes" so we will be prompting for the age. + // WaterfallStep always finishes with the end of the Waterfall or with another dialog; here it is a Prompt Dialog. + PromptOptions promptOptions = new PromptOptions(); + promptOptions.setPrompt(MessageFactory.text("Please enter your age.")); + promptOptions.setRetryPrompt(MessageFactory.text("The value entered must be greater than 0 and less than 150.")); + + return stepContext.prompt("NumberPrompt", promptOptions); + } + + // User said "no" so we will skip the next step. Give -1 as the age. + return stepContext.next(-1); + } + + private static CompletableFuture pictureStep(WaterfallStepContext stepContext) { + stepContext.getValues().put("age", (Integer) stepContext.getResult()); + + String msg = (Integer)stepContext.getValues().get("age") == -1 + ? "No age given." + : String.format("I have your age as %d.", (Integer)stepContext.getValues().get("age")); + + // We can send messages to the user at any point in the WaterfallStep. + return stepContext.getContext().sendActivity(MessageFactory.text(msg)) + .thenCompose(resourceResponse -> { + if (StringUtils.equals(stepContext.getContext().getActivity().getChannelId(), Channels.MSTEAMS)) { + // This attachment prompt example is not designed to work for Teams attachments, so skip it in this case + return stepContext.getContext().sendActivity(MessageFactory.text("Skipping attachment prompt in Teams channel...")) + .thenCompose(resourceResponse1 -> stepContext.next(null)); + } + + // WaterfallStep always finishes with the end of the Waterfall or with another dialog; here it is a Prompt Dialog. + PromptOptions promptOptions = new PromptOptions(); + promptOptions.setPrompt(MessageFactory.text("Please attach a profile picture (or type any message to skip).")); + promptOptions.setRetryPrompt(MessageFactory.text("The attachment must be a jpeg/png image file.")); + + return stepContext.prompt("AttachmentPrompt", promptOptions); + }); + } + + private static CompletableFuture confirmStep(WaterfallStepContext stepContext) { + List attachments = (List)stepContext.getResult(); + stepContext.getValues().put("picture", attachments == null ? null : attachments.get(0)); + + // WaterfallStep always finishes with the end of the Waterfall or with another dialog; here it is a Prompt Dialog. + PromptOptions promptOptions = new PromptOptions(); + promptOptions.setPrompt(MessageFactory.text("Is this ok?")); + return stepContext.prompt("ConfirmPrompt", promptOptions); + } + + private CompletableFuture summaryStep(WaterfallStepContext stepContext) { + if ((Boolean)stepContext.getResult()) { + // Get the current profile object from user state. + return userProfileAccessor.get(stepContext.getContext(), () -> new UserProfile()) + .thenCompose(userProfile -> { + userProfile.transport = (String) stepContext.getValues().get("transport"); + userProfile.name = (String) stepContext.getValues().get("name"); + userProfile.age = (Integer) stepContext.getValues().get("age"); + userProfile.picture = (Attachment) stepContext.getValues().get("picture"); + + String msg = String.format( + "I have your mode of transport as %s and your name as %s", + userProfile.transport, userProfile.name + ); + + if (userProfile.age != -1) { + msg += String.format(" and your age as %s", userProfile.age); + } + + msg += "."; + + return stepContext.getContext().sendActivity(MessageFactory.text(msg)) + .thenApply(resourceResponse -> userProfile); + }) + .thenCompose(userProfile -> { + if (userProfile.picture != null) { + return stepContext.getContext().sendActivity( + MessageFactory.attachment(userProfile.picture, + "This is your profile picture." + )); + } + + return stepContext.getContext().sendActivity( + MessageFactory.text("A profile picture wasn't attached.") + ); + }) + .thenCompose(resourceResponse -> stepContext.endDialog()); + } + + // WaterfallStep always finishes with the end of the Waterfall or with another dialog; here it is the end. + return stepContext.getContext().sendActivity(MessageFactory.text("Thanks. Your profile will not be kept.")) + .thenCompose(resourceResponse -> stepContext.endDialog()); + } + + private static CompletableFuture picturePromptValidator( + PromptValidatorContext> promptContext + ) { + if (promptContext.getRecognized().getSucceeded()) { + List attachments = promptContext.getRecognized().getValue(); + List validImages = new ArrayList<>(); + + for (Attachment attachment : attachments) { + if (StringUtils.equals( + attachment.getContentType(), "image/jpeg") || StringUtils.equals(attachment.getContentType(), "image/png") + ) { + validImages.add(attachment); + } + } + + promptContext.getRecognized().setValue(validImages); + + // If none of the attachments are valid images, the retry prompt should be sent. + return CompletableFuture.completedFuture(!validImages.isEmpty()); + } + else { + // We can return true from a validator function even if Recognized.Succeeded is false. + return promptContext.getContext().sendActivity("No attachments received. Proceeding without a profile picture...") + .thenApply(resourceResponse -> true); + } + } + + private static CompletableFuture agePromptValidator( + PromptValidatorContext promptContext + ) { + // This condition is our validation rule. You can also change the value at this point. + return CompletableFuture.completedFuture( + promptContext.getRecognized().getSucceeded() + && promptContext.getRecognized().getValue() > 0 + && promptContext.getRecognized().getValue() < 150); + } +} diff --git a/samples/44.prompt-users-for-input/src/main/resources/application.properties b/samples/44.prompt-users-for-input/src/main/resources/application.properties new file mode 100644 index 000000000..d7d0ee864 --- /dev/null +++ b/samples/44.prompt-users-for-input/src/main/resources/application.properties @@ -0,0 +1,3 @@ +MicrosoftAppId= +MicrosoftAppPassword= +server.port=3978 diff --git a/samples/44.prompt-users-for-input/src/main/resources/log4j2.json b/samples/44.prompt-users-for-input/src/main/resources/log4j2.json new file mode 100644 index 000000000..67c0ad530 --- /dev/null +++ b/samples/44.prompt-users-for-input/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/44.prompt-users-for-input/src/main/webapp/META-INF/MANIFEST.MF b/samples/44.prompt-users-for-input/src/main/webapp/META-INF/MANIFEST.MF new file mode 100644 index 000000000..254272e1c --- /dev/null +++ b/samples/44.prompt-users-for-input/src/main/webapp/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/samples/44.prompt-users-for-input/src/main/webapp/WEB-INF/web.xml b/samples/44.prompt-users-for-input/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..383c19004 --- /dev/null +++ b/samples/44.prompt-users-for-input/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/44.prompt-users-for-input/src/main/webapp/index.html b/samples/44.prompt-users-for-input/src/main/webapp/index.html new file mode 100644 index 000000000..d5ba5158e --- /dev/null +++ b/samples/44.prompt-users-for-input/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:3978/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/44.prompt-users-for-input/src/test/java/com/microsoft/bot/sample/promptusersforinput/ApplicationTest.java b/samples/44.prompt-users-for-input/src/test/java/com/microsoft/bot/sample/promptusersforinput/ApplicationTest.java new file mode 100644 index 000000000..ced035bd3 --- /dev/null +++ b/samples/44.prompt-users-for-input/src/test/java/com/microsoft/bot/sample/promptusersforinput/ApplicationTest.java @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.bot.sample.multiturnprompt; + +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 ApplicationTest { + + @Test + public void contextLoads() { + } + +} From 9dbc2cfd27f90bd8e20d9064b08bbe8f0cb1cdf1 Mon Sep 17 00:00:00 2001 From: Lee Parrish <30470292+LeeParrishMSFT@users.noreply.github.com> Date: Mon, 1 Feb 2021 14:14:58 -0600 Subject: [PATCH 2/5] Sample code --- .../.vscode/settings.json | 3 + samples/44.prompt-users-for-input/README.md | 2 +- samples/44.prompt-users-for-input/pom.xml | 6 +- .../promptusersforinput/Application.java | 2 +- .../promptusersforinput/ConversationFlow.java | 32 +++ .../promptusersforinput/CustomPromptBot.java | 223 +++++++++++++++++ .../sample/promptusersforinput/DialogBot.java | 55 ----- .../promptusersforinput/UserProfile.java | 7 +- .../UserProfileDialog.java | 224 ------------------ .../promptusersforinput/ApplicationTest.java | 2 +- 10 files changed, 266 insertions(+), 290 deletions(-) create mode 100644 samples/44.prompt-users-for-input/.vscode/settings.json create mode 100644 samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/ConversationFlow.java create mode 100644 samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/CustomPromptBot.java delete mode 100644 samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/DialogBot.java delete mode 100644 samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/UserProfileDialog.java diff --git a/samples/44.prompt-users-for-input/.vscode/settings.json b/samples/44.prompt-users-for-input/.vscode/settings.json new file mode 100644 index 000000000..e0f15db2e --- /dev/null +++ b/samples/44.prompt-users-for-input/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "automatic" +} \ No newline at end of file diff --git a/samples/44.prompt-users-for-input/README.md b/samples/44.prompt-users-for-input/README.md index e4375c425..ec1a736ed 100644 --- a/samples/44.prompt-users-for-input/README.md +++ b/samples/44.prompt-users-for-input/README.md @@ -13,7 +13,7 @@ This bot has been created using [Bot Framework](https://dev.botframework.com), i ## 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\bot-multiturnprompt-sample.jar` + - Run it by using `java -jar .\target\bot-promptusersforinput-sample.jar` - Test the bot using Bot Framework Emulator diff --git a/samples/44.prompt-users-for-input/pom.xml b/samples/44.prompt-users-for-input/pom.xml index 7dfbebe83..91b260ccf 100644 --- a/samples/44.prompt-users-for-input/pom.xml +++ b/samples/44.prompt-users-for-input/pom.xml @@ -6,7 +6,7 @@ 4.0.0 com.microsoft.bot.sample - bot-multiturnprompt + bot-promptusersforinput sample jar @@ -41,7 +41,7 @@ 1.8 1.8 1.8 - com.microsoft.bot.sample.multiturnprompt.Application + com.microsoft.bot.sample.promptusersforinput.Application @@ -126,7 +126,7 @@ repackage - com.microsoft.bot.sample.multiturnprompt.Application + com.microsoft.bot.sample.promptusersforinput.Application diff --git a/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/Application.java b/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/Application.java index 1324a2348..bd12d9ab2 100644 --- a/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/Application.java +++ b/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/Application.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.microsoft.bot.sample.multiturnprompt; +package com.microsoft.bot.sample.promptusersforinput; import com.microsoft.bot.integration.AdapterWithErrorHandler; import com.microsoft.bot.integration.BotFrameworkHttpAdapter; diff --git a/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/ConversationFlow.java b/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/ConversationFlow.java new file mode 100644 index 000000000..cf9f51702 --- /dev/null +++ b/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/ConversationFlow.java @@ -0,0 +1,32 @@ +package com.microsoft.bot.sample.promptusersforinput; + +public class ConversationFlow { + + private Question lastQuestionAsked = Question.None; + + /** + * Identifies the last question asked. + */ + public enum Question { + Name, + Age, + Date, + None //Our last action did not involved a question. + } + + /** + * Gets the last question asked. + * @return The last question asked. + */ + public Question getLastQuestionAsked() { + return lastQuestionAsked; + } + + /** + * Sets the last question asked. + * @param withLastQuestionAsked the last question asked. + */ + public void setLastQuestionAsked(Question withLastQuestionAsked) { + this.lastQuestionAsked = withLastQuestionAsked; + } +} diff --git a/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/CustomPromptBot.java b/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/CustomPromptBot.java new file mode 100644 index 000000000..08320dce6 --- /dev/null +++ b/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/CustomPromptBot.java @@ -0,0 +1,223 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.microsoft.bot.sample.promptusersforinput; + +import com.microsoft.bot.builder.ActivityHandler; +import com.microsoft.bot.builder.BotState; +import com.microsoft.bot.builder.ConversationState; +import com.microsoft.bot.builder.StatePropertyAccessor; +import com.microsoft.bot.dialogs.prompts.PromptCultureModels; +import com.microsoft.recognizers.text.ModelResult; +import com.microsoft.recognizers.text.datetime.DateTimeRecognizer; +import com.microsoft.recognizers.text.number.NumberRecognizer; +import com.microsoft.bot.builder.TurnContext; +import com.microsoft.bot.builder.UserState; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.atomic.AtomicReference; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.Triple; +import org.springframework.stereotype.Component; + +/** + * This Bot implementation can run any type of Dialog. The use of type + * parameterization is to allows multiple different bots to be run at different + * endpoints within the same project. This can be achieved by defining distinct + * Controller types each with dependency on distinct Bot types. + */ +@Component +public class CustomPromptBot extends ActivityHandler { + + private final BotState userState; + private final BotState conversationState; + + public CustomPromptBot(ConversationState conversationState, UserState userState) { + this.conversationState = conversationState; + this.userState = userState; + } + + @Override + protected CompletableFuture onMessageActivity(TurnContext turnContext) { + + StatePropertyAccessor conversationStateAccessors = + conversationState.createProperty("ConversationFlow"); + + StatePropertyAccessor userStateAccessors = userState.createProperty("UserProfile"); + return userStateAccessors.get(turnContext, () -> new UserProfile()).thenCompose(profile -> { + return conversationStateAccessors.get(turnContext, () -> new ConversationFlow()).thenCompose(flow -> { + return fillOutUserProfile(flow, profile, turnContext); + }); + }) + .thenCompose(result -> conversationState.saveChanges(turnContext)) + .thenCompose(result -> userState.saveChanges(turnContext)); + } + + private static CompletableFuture fillOutUserProfile(ConversationFlow flow, + UserProfile profile, + TurnContext turnContext) { + String input = ""; + if (StringUtils.isNotBlank(turnContext.getActivity().getText())) { + input = turnContext.getActivity().getText().trim(); + } + + switch (flow.getLastQuestionAsked()) { + case None: + return turnContext.sendActivity("Let's get started. What is your name?", null, null) + .thenRun(() -> {flow.setLastQuestionAsked(ConversationFlow.Question.Name);}); + case Name: + Triple nameValidationResult = validateName(input); + if (nameValidationResult.getLeft()) { + profile.name = nameValidationResult.getMiddle(); + return turnContext.sendActivity(String.format("Hi %s.", profile.name), null, null) + .thenCompose(result -> turnContext.sendActivity("How old are you?", null, null)) + .thenRun(() -> { flow.setLastQuestionAsked(ConversationFlow.Question.Age); }); + } else { + if (StringUtils.isNotBlank(nameValidationResult.getRight())) { + return turnContext.sendActivity(nameValidationResult.getRight(), null, null) + .thenApply(result -> null); + } else { + return turnContext.sendActivity("I'm sorry, I didn't understand that.", null, null) + .thenApply(result -> null); + } + } + case Age: + Triple ageValidationResult = ValidateAge(input); + if (ageValidationResult.getLeft()) { + profile.age = ageValidationResult.getMiddle(); + return turnContext.sendActivity(String.format("I have your age as %d.", profile.age), null, null) + .thenCompose(result -> turnContext.sendActivity("When is your flight?", null, null)) + .thenRun(() -> { flow.setLastQuestionAsked(ConversationFlow.Question.Date); }); + } else { + if (StringUtils.isNotBlank(ageValidationResult.getRight())) { + return turnContext.sendActivity(ageValidationResult.getRight(), null, null) + .thenApply(result -> null); + } else { + return turnContext.sendActivity("I'm sorry, I didn't understand that.", null, null) + .thenApply(result -> null); + } + } + + case Date: + Triple dateValidationResult = ValidateDate(input); + AtomicReference profileReference = new AtomicReference(profile); + if (dateValidationResult.getLeft()) { + profile.date = dateValidationResult.getMiddle(); + return turnContext.sendActivity( + String.format("Your cab ride to the airport is scheduled for %s.", + profileReference.get().date)) + .thenCompose(result -> turnContext.sendActivity( + String.format("Thanks for completing the booking %s.", profileReference.get().name))) + .thenCompose(result -> turnContext.sendActivity("Type anything to run the bot again.")) + .thenRun(() -> { + flow.setLastQuestionAsked(ConversationFlow.Question.None); + profileReference.set(new UserProfile()); + }); + } else { + if (StringUtils.isNotBlank(dateValidationResult.getRight())) { + return turnContext.sendActivity(dateValidationResult.getRight(), null, null) + .thenApply(result -> null); + } else { + return turnContext.sendActivity("I'm sorry, I didn't understand that.", null, null) + .thenApply(result -> null); } + } + default: + return CompletableFuture.completedFuture(null); + } + } + + private static Triple validateName(String input) { + String name = null; + String message = null; + + if (StringUtils.isEmpty(input)) { + message = "Please enter a name that contains at least one character."; + } else { + name = input.trim(); + } + + return Triple.of(StringUtils.isBlank(message), name, message); + } + + private static Triple ValidateAge(String input) { + int age = 0; + String message = null; + + // Try to recognize the input as a number. This works for responses such as "twelve" as well as "12". + try { + // Attempt to convert the Recognizer result to an integer. This works for "a dozen", "twelve", "12", and so on. + // The recognizer returns a list of potential recognition results, if any. + + List results = NumberRecognizer.recognizeNumber(input, PromptCultureModels.ENGLISH_CULTURE); + for (ModelResult result : results) { + // The result resolution is a dictionary, where the "value" entry contains the processed String. + Object value = result.resolution.get("value"); + if (value != null) { + age = Integer.parseInt((String) value); + if (age >= 18 && age <= 120) { + return Triple.of(true, age, ""); + } + } + } + + message = "Please enter an age between 18 and 120."; + } + catch (Throwable th) { + message = "I'm sorry, I could not interpret that as an age. Please enter an age between 18 and 120."; + } + + return Triple.of(StringUtils.isBlank(message), age, message); + } + + private static Triple ValidateDate(String input) { + String date = null; + String message = null; + + // Try to recognize the input as a date-time. This works for responses such as "11/14/2018", "9pm", "tomorrow", "Sunday at 5pm", and so on. + // The recognizer returns a list of potential recognition results, if any. + try { + List results = DateTimeRecognizer.recognizeDateTime(input, PromptCultureModels.ENGLISH_CULTURE); + + // Check whether any of the recognized date-times are appropriate, + // and if so, return the first appropriate date-time. We're checking for a value at least an hour in the future. + LocalDateTime earliest = LocalDateTime.now().plus(1, ChronoUnit.HOURS); + + for (ModelResult result : results) { + // The result resolution is a dictionary, where the "values" entry contains the processed input. + List> resolutions = (List>) result.resolution.get("values"); + + for (Map resolution : resolutions) { + // The processed input contains a "value" entry if it is a date-time value, or "start" and + // "end" entries if it is a date-time range. + String dateString = (String) resolution.get("value"); + if (StringUtils.isBlank(dateString)) { + dateString = (String) resolution.get("start"); + } + if (StringUtils.isNotBlank(dateString)){ + DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + LocalDateTime candidate = LocalDateTime.from(f.parse(dateString)); + if (earliest.isBefore(candidate)) { + DateTimeFormatter dateformat = DateTimeFormatter.ofPattern("MM-dd-yyyy"); + date = candidate.format(dateformat); + return Triple.of(true, date, message); + } + } + + } + } + + message = "I'm sorry, please enter a date at least an hour out."; + } + catch (Throwable th) { + message = "I'm sorry, I could not interpret that as an appropriate date. Please enter a date at least an hour out."; + } + + return Triple.of(false, date, message); + } +} diff --git a/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/DialogBot.java b/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/DialogBot.java deleted file mode 100644 index d71d53ed6..000000000 --- a/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/DialogBot.java +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.microsoft.bot.sample.multiturnprompt; - -import com.microsoft.bot.builder.ActivityHandler; -import com.microsoft.bot.builder.BotState; -import com.microsoft.bot.builder.ConversationState; -import com.microsoft.bot.dialogs.Dialog; -import com.microsoft.bot.builder.TurnContext; -import com.microsoft.bot.builder.UserState; -import java.util.concurrent.CompletableFuture; -import org.springframework.stereotype.Component; - -/** - * This IBot implementation can run any type of Dialog. The use of type parameterization is to - * allows multiple different bots to be run at different endpoints within the same project. This - * can be achieved by defining distinct Controller types each with dependency on distinct IBot - * types, this way ASP Dependency Injection can glue everything together without ambiguity. The - * ConversationState is used by the Dialog system. The UserState isn't, however, it might have - * been used in a Dialog implementation, and the requirement is that all BotState objects are - * saved at the end of a turn. - */ -@Component -public class DialogBot extends ActivityHandler { - protected Dialog dialog; - protected BotState conversationState; - protected BotState userState; - - public DialogBot( - ConversationState withConversationState, - UserState withUserState, - Dialog withDialog - ) { - dialog = withDialog; - conversationState = withConversationState; - userState = withUserState; - } - - @Override - public CompletableFuture onTurn( - TurnContext turnContext - ) { - return super.onTurn(turnContext) - .thenCompose(result -> conversationState.saveChanges(turnContext)) - .thenCompose(result -> userState.saveChanges(turnContext)); - } - - @Override - protected CompletableFuture onMessageActivity( - TurnContext turnContext - ) { - return Dialog.run(dialog, turnContext, conversationState.createProperty("DialogState")); - } -} diff --git a/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/UserProfile.java b/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/UserProfile.java index a04f2f72b..2f5df5b91 100644 --- a/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/UserProfile.java +++ b/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/UserProfile.java @@ -1,13 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.microsoft.bot.sample.multiturnprompt; - -import com.microsoft.bot.schema.Attachment; +package com.microsoft.bot.sample.promptusersforinput; public class UserProfile { - public String transport; public String name; public Integer age; - public Attachment picture; + public String date; } diff --git a/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/UserProfileDialog.java b/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/UserProfileDialog.java deleted file mode 100644 index 302fe5d3a..000000000 --- a/samples/44.prompt-users-for-input/src/main/java/com/microsoft/bot/sample/promptusersforinput/UserProfileDialog.java +++ /dev/null @@ -1,224 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.microsoft.bot.sample.multiturnprompt; - -import com.microsoft.bot.builder.MessageFactory; -import com.microsoft.bot.builder.StatePropertyAccessor; -import com.microsoft.bot.builder.UserState; -import com.microsoft.bot.connector.Channels; -import com.microsoft.bot.dialogs.ComponentDialog; -import com.microsoft.bot.dialogs.DialogTurnResult; -import com.microsoft.bot.dialogs.WaterfallDialog; -import com.microsoft.bot.dialogs.WaterfallStep; -import com.microsoft.bot.dialogs.WaterfallStepContext; -import com.microsoft.bot.dialogs.choices.ChoiceFactory; -import com.microsoft.bot.dialogs.choices.FoundChoice; -import com.microsoft.bot.dialogs.prompts.AttachmentPrompt; -import com.microsoft.bot.dialogs.prompts.ChoicePrompt; -import com.microsoft.bot.dialogs.prompts.ConfirmPrompt; -import com.microsoft.bot.dialogs.prompts.NumberPrompt; -import com.microsoft.bot.dialogs.prompts.PromptOptions; -import com.microsoft.bot.dialogs.prompts.PromptValidatorContext; -import com.microsoft.bot.dialogs.prompts.TextPrompt; -import com.microsoft.bot.schema.Attachment; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.CompletableFuture; -import org.apache.commons.lang3.StringUtils; -import org.springframework.stereotype.Component; - -@Component -public class UserProfileDialog extends ComponentDialog { - private StatePropertyAccessor userProfileAccessor; - - public UserProfileDialog(UserState withUserState) { - super("UserProfileDialog"); - - userProfileAccessor = withUserState.createProperty("UserProfile"); - - WaterfallStep[] waterfallSteps = { - UserProfileDialog::transportStep, - UserProfileDialog::nameStep, - UserProfileDialog::nameConfirmStep, - UserProfileDialog::ageStep, - UserProfileDialog::pictureStep, - UserProfileDialog::confirmStep, - this::summaryStep - }; - - // Add named dialogs to the DialogSet. These names are saved in the dialog state. - addDialog(new WaterfallDialog("WaterfallDialog", Arrays.asList(waterfallSteps))); - addDialog(new TextPrompt("TextPrompt")); - addDialog(new NumberPrompt("NumberPrompt", UserProfileDialog::agePromptValidator, Integer.class)); - addDialog(new ChoicePrompt("ChoicePrompt")); - addDialog(new ConfirmPrompt("ConfirmPrompt")); - addDialog(new AttachmentPrompt("AttachmentPrompt", UserProfileDialog::picturePromptValidator)); - - // The initial child Dialog to run. - setInitialDialogId("WaterfallDialog"); - } - - private static CompletableFuture transportStep(WaterfallStepContext stepContext) { - // WaterfallStep always finishes with the end of the Waterfall or with another dialog; here it is a Prompt Dialog. - // Running a prompt here means the next WaterfallStep will be run when the user's response is received. - PromptOptions promptOptions = new PromptOptions(); - promptOptions.setPrompt(MessageFactory.text("Please enter your mode of transport.")); - promptOptions.setChoices(ChoiceFactory.toChoices("Car", "Bus", "Bicycle")); - - return stepContext.prompt("ChoicePrompt", promptOptions); - } - - private static CompletableFuture nameStep(WaterfallStepContext stepContext) { - stepContext.getValues().put("transport", ((FoundChoice) stepContext.getResult()).getValue()); - - PromptOptions promptOptions = new PromptOptions(); - promptOptions.setPrompt(MessageFactory.text("Please enter your name.")); - return stepContext.prompt("TextPrompt", promptOptions); - } - - private static CompletableFuture nameConfirmStep(WaterfallStepContext stepContext) { - stepContext.getValues().put("name", stepContext.getResult()); - - // We can send messages to the user at any point in the WaterfallStep. - return stepContext.getContext().sendActivity(MessageFactory.text(String.format("Thanks %s", stepContext.getResult()))) - .thenCompose(resourceResponse -> { - // WaterfallStep always finishes with the end of the Waterfall or with another dialog; here it is a Prompt Dialog. - PromptOptions promptOptions = new PromptOptions(); - promptOptions.setPrompt(MessageFactory.text("Would you like to give your age?")); - return stepContext.prompt("ConfirmPrompt", promptOptions); - }); - } - - private static CompletableFuture ageStep(WaterfallStepContext stepContext) { - if ((Boolean)stepContext.getResult()) { - // User said "yes" so we will be prompting for the age. - // WaterfallStep always finishes with the end of the Waterfall or with another dialog; here it is a Prompt Dialog. - PromptOptions promptOptions = new PromptOptions(); - promptOptions.setPrompt(MessageFactory.text("Please enter your age.")); - promptOptions.setRetryPrompt(MessageFactory.text("The value entered must be greater than 0 and less than 150.")); - - return stepContext.prompt("NumberPrompt", promptOptions); - } - - // User said "no" so we will skip the next step. Give -1 as the age. - return stepContext.next(-1); - } - - private static CompletableFuture pictureStep(WaterfallStepContext stepContext) { - stepContext.getValues().put("age", (Integer) stepContext.getResult()); - - String msg = (Integer)stepContext.getValues().get("age") == -1 - ? "No age given." - : String.format("I have your age as %d.", (Integer)stepContext.getValues().get("age")); - - // We can send messages to the user at any point in the WaterfallStep. - return stepContext.getContext().sendActivity(MessageFactory.text(msg)) - .thenCompose(resourceResponse -> { - if (StringUtils.equals(stepContext.getContext().getActivity().getChannelId(), Channels.MSTEAMS)) { - // This attachment prompt example is not designed to work for Teams attachments, so skip it in this case - return stepContext.getContext().sendActivity(MessageFactory.text("Skipping attachment prompt in Teams channel...")) - .thenCompose(resourceResponse1 -> stepContext.next(null)); - } - - // WaterfallStep always finishes with the end of the Waterfall or with another dialog; here it is a Prompt Dialog. - PromptOptions promptOptions = new PromptOptions(); - promptOptions.setPrompt(MessageFactory.text("Please attach a profile picture (or type any message to skip).")); - promptOptions.setRetryPrompt(MessageFactory.text("The attachment must be a jpeg/png image file.")); - - return stepContext.prompt("AttachmentPrompt", promptOptions); - }); - } - - private static CompletableFuture confirmStep(WaterfallStepContext stepContext) { - List attachments = (List)stepContext.getResult(); - stepContext.getValues().put("picture", attachments == null ? null : attachments.get(0)); - - // WaterfallStep always finishes with the end of the Waterfall or with another dialog; here it is a Prompt Dialog. - PromptOptions promptOptions = new PromptOptions(); - promptOptions.setPrompt(MessageFactory.text("Is this ok?")); - return stepContext.prompt("ConfirmPrompt", promptOptions); - } - - private CompletableFuture summaryStep(WaterfallStepContext stepContext) { - if ((Boolean)stepContext.getResult()) { - // Get the current profile object from user state. - return userProfileAccessor.get(stepContext.getContext(), () -> new UserProfile()) - .thenCompose(userProfile -> { - userProfile.transport = (String) stepContext.getValues().get("transport"); - userProfile.name = (String) stepContext.getValues().get("name"); - userProfile.age = (Integer) stepContext.getValues().get("age"); - userProfile.picture = (Attachment) stepContext.getValues().get("picture"); - - String msg = String.format( - "I have your mode of transport as %s and your name as %s", - userProfile.transport, userProfile.name - ); - - if (userProfile.age != -1) { - msg += String.format(" and your age as %s", userProfile.age); - } - - msg += "."; - - return stepContext.getContext().sendActivity(MessageFactory.text(msg)) - .thenApply(resourceResponse -> userProfile); - }) - .thenCompose(userProfile -> { - if (userProfile.picture != null) { - return stepContext.getContext().sendActivity( - MessageFactory.attachment(userProfile.picture, - "This is your profile picture." - )); - } - - return stepContext.getContext().sendActivity( - MessageFactory.text("A profile picture wasn't attached.") - ); - }) - .thenCompose(resourceResponse -> stepContext.endDialog()); - } - - // WaterfallStep always finishes with the end of the Waterfall or with another dialog; here it is the end. - return stepContext.getContext().sendActivity(MessageFactory.text("Thanks. Your profile will not be kept.")) - .thenCompose(resourceResponse -> stepContext.endDialog()); - } - - private static CompletableFuture picturePromptValidator( - PromptValidatorContext> promptContext - ) { - if (promptContext.getRecognized().getSucceeded()) { - List attachments = promptContext.getRecognized().getValue(); - List validImages = new ArrayList<>(); - - for (Attachment attachment : attachments) { - if (StringUtils.equals( - attachment.getContentType(), "image/jpeg") || StringUtils.equals(attachment.getContentType(), "image/png") - ) { - validImages.add(attachment); - } - } - - promptContext.getRecognized().setValue(validImages); - - // If none of the attachments are valid images, the retry prompt should be sent. - return CompletableFuture.completedFuture(!validImages.isEmpty()); - } - else { - // We can return true from a validator function even if Recognized.Succeeded is false. - return promptContext.getContext().sendActivity("No attachments received. Proceeding without a profile picture...") - .thenApply(resourceResponse -> true); - } - } - - private static CompletableFuture agePromptValidator( - PromptValidatorContext promptContext - ) { - // This condition is our validation rule. You can also change the value at this point. - return CompletableFuture.completedFuture( - promptContext.getRecognized().getSucceeded() - && promptContext.getRecognized().getValue() > 0 - && promptContext.getRecognized().getValue() < 150); - } -} diff --git a/samples/44.prompt-users-for-input/src/test/java/com/microsoft/bot/sample/promptusersforinput/ApplicationTest.java b/samples/44.prompt-users-for-input/src/test/java/com/microsoft/bot/sample/promptusersforinput/ApplicationTest.java index ced035bd3..df4f92a57 100644 --- a/samples/44.prompt-users-for-input/src/test/java/com/microsoft/bot/sample/promptusersforinput/ApplicationTest.java +++ b/samples/44.prompt-users-for-input/src/test/java/com/microsoft/bot/sample/promptusersforinput/ApplicationTest.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.microsoft.bot.sample.multiturnprompt; +package com.microsoft.bot.sample.promptusersforinput; import org.junit.Test; import org.junit.runner.RunWith; From 27fd1743a4867782a863777de870afd6f1e237b0 Mon Sep 17 00:00:00 2001 From: Lee Parrish <30470292+LeeParrishMSFT@users.noreply.github.com> Date: Mon, 1 Feb 2021 14:36:33 -0600 Subject: [PATCH 3/5] Correct readme and pom files. --- samples/44.prompt-users-for-input/README.md | 6 +++--- samples/44.prompt-users-for-input/pom.xml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/44.prompt-users-for-input/README.md b/samples/44.prompt-users-for-input/README.md index ec1a736ed..9aa2b418c 100644 --- a/samples/44.prompt-users-for-input/README.md +++ b/samples/44.prompt-users-for-input/README.md @@ -1,8 +1,8 @@ -# Multi-turn prompt +# Prompt users for input -Bot Framework v4 multi-turn prompt bot sample +Bot Framework v4 Prompt Users for Input bot sample -This bot has been created using [Bot Framework](https://dev.botframework.com), it shows how to use the prompts classes included in `botbuilder-dialogs`. This bot will ask for the user's name and age, then store the responses. It demonstrates a multi-turn dialog flow using a text prompt, a number prompt, and state accessors to store and retrieve values. +This bot has been created using [Bot Framework](https://dev.botframework.com), The bot maintains conversation state to track and direct the conversation and ask the user questions. The bot maintains user state to track the user's answers. ## Prerequisites diff --git a/samples/44.prompt-users-for-input/pom.xml b/samples/44.prompt-users-for-input/pom.xml index 91b260ccf..0174fbb77 100644 --- a/samples/44.prompt-users-for-input/pom.xml +++ b/samples/44.prompt-users-for-input/pom.xml @@ -11,7 +11,7 @@ jar ${project.groupId}:${project.artifactId} - This package contains the Multi-turn Prompt sample using Spring Boot. + This package contains the Prompt Users for Input sample using Spring Boot. http://maven.apache.org From a0e71415261a310e28f2f21565dc28b2abbfb4cd Mon Sep 17 00:00:00 2001 From: Lee Parrish <30470292+LeeParrishMSFT@users.noreply.github.com> Date: Mon, 1 Feb 2021 14:37:44 -0600 Subject: [PATCH 4/5] Fix readme. --- samples/44.prompt-users-for-input/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/44.prompt-users-for-input/README.md b/samples/44.prompt-users-for-input/README.md index 9aa2b418c..1a7f0a8e7 100644 --- a/samples/44.prompt-users-for-input/README.md +++ b/samples/44.prompt-users-for-input/README.md @@ -2,7 +2,7 @@ Bot Framework v4 Prompt Users for Input bot sample -This bot has been created using [Bot Framework](https://dev.botframework.com), The bot maintains conversation state to track and direct the conversation and ask the user questions. The bot maintains user state to track the user's answers. +This bot has been created using [Bot Framework](https://dev.botframework.com). The bot maintains conversation state to track and direct the conversation and ask the user questions. The bot maintains user state to track the user's answers. ## Prerequisites From 9bcdc45ec7f88dfd6db2cc7b1c1a6eeb0300f4ed Mon Sep 17 00:00:00 2001 From: Lee Parrish <30470292+LeeParrishMSFT@users.noreply.github.com> Date: Tue, 2 Feb 2021 12:17:55 -0600 Subject: [PATCH 5/5] Delete settings.json Remove as this shouldn't be part of the source tree. --- samples/44.prompt-users-for-input/.vscode/settings.json | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 samples/44.prompt-users-for-input/.vscode/settings.json diff --git a/samples/44.prompt-users-for-input/.vscode/settings.json b/samples/44.prompt-users-for-input/.vscode/settings.json deleted file mode 100644 index e0f15db2e..000000000 --- a/samples/44.prompt-users-for-input/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "java.configuration.updateBuildConfiguration": "automatic" -} \ No newline at end of file