Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit a408ebe

Browse files
Sample: 44.prompt-users-for-input (#932)
* Completed sample * Sample code * Correct readme and pom files. * Fix readme. * Delete settings.json Remove as this shouldn't be part of the source tree. Co-authored-by: tracyboehrer <tracyboehrer@users.noreply.github.com>
1 parent 6eeeb16 commit a408ebe

17 files changed

Lines changed: 1571 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Microsoft Corporation. All rights reserved.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Prompt users for input
2+
3+
Bot Framework v4 Prompt Users for Input bot sample
4+
5+
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.
6+
7+
## Prerequisites
8+
9+
- Java 1.8+
10+
- Install [Maven](https://maven.apache.org/)
11+
- An account on [Azure](https://azure.microsoft.com) if you want to deploy to Azure.
12+
13+
## To try this sample locally
14+
- From the root of this project folder:
15+
- Build the sample using `mvn package`
16+
- Run it by using `java -jar .\target\bot-promptusersforinput-sample.jar`
17+
18+
- Test the bot using Bot Framework Emulator
19+
20+
[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.
21+
22+
- Install the Bot Framework Emulator version 4.3.0 or greater from [here](https://github.com/Microsoft/BotFramework-Emulator/releases)
23+
24+
- Connect to the bot using Bot Framework Emulator
25+
26+
- Launch Bot Framework Emulator
27+
- File -> Open Bot
28+
- Enter a Bot URL of `http://localhost:3978/api/messages`
29+
30+
## Deploy the bot to Azure
31+
32+
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.
33+
34+
### 1. Login to Azure
35+
From a command (or PowerShell) prompt in the root of the bot folder, execute:
36+
`az login`
37+
38+
### 2. Set the subscription
39+
`az account set --subscription "<azure-subscription>"`
40+
41+
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.
42+
43+
### 3. Create an App registration
44+
`az ad app create --display-name "<botname>" --password "<appsecret>" --available-to-other-tenants`
45+
46+
Replace `<botname>` and `<appsecret>` with your own values.
47+
48+
`<botname>` is the unique name of your bot.
49+
`<appsecret>` is a minimum 16 character password for your bot.
50+
51+
Record the `appid` from the returned JSON
52+
53+
### 4. Create the Azure resources
54+
Replace the values for `<appid>`, `<appsecret>`, `<botname>`, and `<groupname>` in the following commands:
55+
56+
#### To a new Resource Group
57+
`az deployment create --name "stateBotDeploy" --location "westus" --template-file ".\deploymentTemplates\template-with-new-rg.json" --parameters groupName="<groupname>" botId="<botname>" appId="<appid>" appSecret="<appsecret>"`
58+
59+
#### To an existing Resource Group
60+
`az group deployment create --name "stateBotDeploy" --resource-group "<groupname>" --template-file ".\deploymentTemplates\template-with-preexisting-rg.json" --parameters botId="<botname>" appId="<appid>" appSecret="<appsecret>"`
61+
62+
### 5. Update app id and password
63+
In src/main/resources/application.properties update
64+
- `MicrosoftAppPassword` with the botsecret value
65+
- `MicrosoftAppId` with the appid from the first step
66+
67+
### 6. Deploy the code
68+
- Execute `mvn clean package`
69+
- Execute `mvn azure-webapp:deploy -Dgroupname="<groupname>" -Dbotname="<botname>"`
70+
71+
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.
72+
73+
After the bot is deployed, you only need to execute #6 if you make changes to the bot.
74+
75+
76+
## Further reading
77+
78+
- [Bot Framework Documentation](https://docs.botframework.com)
79+
- [Bot Basics](https://docs.microsoft.com/azure/bot-service/bot-builder-basics?view=azure-bot-service-4.0)
80+
- [Dialogs](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-concept-dialog?view=azure-bot-service-4.0)
81+
- [Gathering Input Using Prompts](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-prompts?view=azure-bot-service-4.0&tabs=csharp)
82+
- [Activity processing](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-concept-activity-processing?view=azure-bot-service-4.0)
83+
- [Azure Bot Service Introduction](https://docs.microsoft.com/azure/bot-service/bot-service-overview-introduction?view=azure-bot-service-4.0)
84+
- [Azure Bot Service Documentation](https://docs.microsoft.com/azure/bot-service/?view=azure-bot-service-4.0)
85+
- [Azure CLI](https://docs.microsoft.com/cli/azure/?view=azure-cli-latest)
86+
- [Azure Portal](https://portal.azure.com)
87+
- [Channels and Bot Connector Service](https://docs.microsoft.com/en-us/azure/bot-service/bot-concepts?view=azure-bot-service-4.0)
88+
- [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)
89+
- [Spring Boot](https://spring.io/projects/spring-boot)
90+
- [Azure for Java cloud developers](https://docs.microsoft.com/en-us/azure/java/?view=azure-java-stable)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"groupLocation": {
6+
"value": ""
7+
},
8+
"groupName": {
9+
"value": ""
10+
},
11+
"appId": {
12+
"value": ""
13+
},
14+
"appSecret": {
15+
"value": ""
16+
},
17+
"botId": {
18+
"value": ""
19+
},
20+
"botSku": {
21+
"value": ""
22+
},
23+
"newAppServicePlanName": {
24+
"value": ""
25+
},
26+
"newAppServicePlanSku": {
27+
"value": {
28+
"name": "S1",
29+
"tier": "Standard",
30+
"size": "S1",
31+
"family": "S",
32+
"capacity": 1
33+
}
34+
},
35+
"newAppServicePlanLocation": {
36+
"value": ""
37+
},
38+
"newWebAppName": {
39+
"value": ""
40+
}
41+
}
42+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"appId": {
6+
"value": ""
7+
},
8+
"appSecret": {
9+
"value": ""
10+
},
11+
"botId": {
12+
"value": ""
13+
},
14+
"botSku": {
15+
"value": ""
16+
},
17+
"newAppServicePlanName": {
18+
"value": ""
19+
},
20+
"newAppServicePlanSku": {
21+
"value": {
22+
"name": "S1",
23+
"tier": "Standard",
24+
"size": "S1",
25+
"family": "S",
26+
"capacity": 1
27+
}
28+
},
29+
"appServicePlanLocation": {
30+
"value": ""
31+
},
32+
"existingAppServicePlan": {
33+
"value": ""
34+
},
35+
"newWebAppName": {
36+
"value": ""
37+
}
38+
}
39+
}
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"groupLocation": {
6+
"defaultValue": "",
7+
"type": "string",
8+
"metadata": {
9+
"description": "Specifies the location of the Resource Group."
10+
}
11+
},
12+
"groupName": {
13+
"type": "string",
14+
"metadata": {
15+
"description": "Specifies the name of the Resource Group."
16+
}
17+
},
18+
"appId": {
19+
"type": "string",
20+
"metadata": {
21+
"description": "Active Directory App ID, set as MicrosoftAppId in the Web App's Application Settings."
22+
}
23+
},
24+
"appSecret": {
25+
"type": "string",
26+
"metadata": {
27+
"description": "Active Directory App Password, set as MicrosoftAppPassword in the Web App's Application Settings."
28+
}
29+
},
30+
"botId": {
31+
"type": "string",
32+
"metadata": {
33+
"description": "The globally unique and immutable bot ID. Also used to configure the displayName of the bot, which is mutable."
34+
}
35+
},
36+
"botSku": {
37+
"defaultValue": "F0",
38+
"type": "string",
39+
"metadata": {
40+
"description": "The pricing tier of the Bot Service Registration. Acceptable values are F0 and S1."
41+
}
42+
},
43+
"newAppServicePlanName": {
44+
"defaultValue": "",
45+
"type": "string",
46+
"metadata": {
47+
"description": "The name of the App Service Plan."
48+
}
49+
},
50+
"newAppServicePlanSku": {
51+
"type": "object",
52+
"defaultValue": {
53+
"name": "P1v2",
54+
"tier": "PremiumV2",
55+
"size": "P1v2",
56+
"family": "Pv2",
57+
"capacity": 1
58+
},
59+
"metadata": {
60+
"description": "The SKU of the App Service Plan. Defaults to Standard values."
61+
}
62+
},
63+
"newAppServicePlanLocation": {
64+
"defaultValue": "",
65+
"type": "string",
66+
"metadata": {
67+
"description": "The location of the App Service Plan. Defaults to \"westus\"."
68+
}
69+
},
70+
"newWebAppName": {
71+
"type": "string",
72+
"defaultValue": "",
73+
"metadata": {
74+
"description": "The globally unique name of the Web App. Defaults to the value passed in for \"botId\"."
75+
}
76+
}
77+
},
78+
"variables": {
79+
"resourcesLocation": "[deployment().location]",
80+
"effectiveGroupLocation": "[if(empty(parameters('groupLocation')), variables('resourcesLocation'), parameters('groupLocation'))]",
81+
"effectivePlanLocation": "[if(empty(parameters('newAppServicePlanLocation')), variables('resourcesLocation'), parameters('newAppServicePlanLocation'))]",
82+
"appServicePlanName": "[if(empty(parameters('newAppServicePlanName')), concat(parameters('botId'), 'ServicePlan'), parameters('newAppServicePlanName'))]",
83+
"webAppName": "[if(empty(parameters('newWebAppName')), parameters('botId'), parameters('newWebAppName'))]",
84+
"siteHost": "[concat(variables('webAppName'), '.azurewebsites.net')]",
85+
"botEndpoint": "[concat('https://', variables('siteHost'), '/api/messages')]"
86+
},
87+
"resources": [
88+
{
89+
"name": "[parameters('groupName')]",
90+
"type": "Microsoft.Resources/resourceGroups",
91+
"apiVersion": "2018-05-01",
92+
"location": "[variables('effectiveGroupLocation')]",
93+
"properties": {
94+
}
95+
},
96+
{
97+
"type": "Microsoft.Resources/deployments",
98+
"apiVersion": "2018-05-01",
99+
"name": "storageDeployment",
100+
"resourceGroup": "[parameters('groupName')]",
101+
"dependsOn": [
102+
"[resourceId('Microsoft.Resources/resourceGroups/', parameters('groupName'))]"
103+
],
104+
"properties": {
105+
"mode": "Incremental",
106+
"template": {
107+
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
108+
"contentVersion": "1.0.0.0",
109+
"parameters": {},
110+
"variables": {},
111+
"resources": [
112+
{
113+
"comments": "Create a new App Service Plan",
114+
"type": "Microsoft.Web/serverfarms",
115+
"name": "[variables('appServicePlanName')]",
116+
"apiVersion": "2018-02-01",
117+
"location": "[variables('effectivePlanLocation')]",
118+
"sku": "[parameters('newAppServicePlanSku')]",
119+
"kind": "linux",
120+
"properties": {
121+
"name": "[variables('appServicePlanName')]",
122+
"reserved":true
123+
}
124+
},
125+
{
126+
"comments": "Create a Web App using the new App Service Plan",
127+
"type": "Microsoft.Web/sites",
128+
"apiVersion": "2015-08-01",
129+
"location": "[variables('resourcesLocation')]",
130+
"kind": "app",
131+
"dependsOn": [
132+
"[resourceId('Microsoft.Web/serverfarms/', variables('appServicePlanName'))]"
133+
],
134+
"name": "[variables('webAppName')]",
135+
"properties": {
136+
"name": "[variables('webAppName')]",
137+
"serverFarmId": "[variables('appServicePlanName')]",
138+
"siteConfig": {
139+
"appSettings": [
140+
{
141+
"name": "JAVA_OPTS",
142+
"value": "-Dserver.port=80"
143+
},
144+
{
145+
"name": "MicrosoftAppId",
146+
"value": "[parameters('appId')]"
147+
},
148+
{
149+
"name": "MicrosoftAppPassword",
150+
"value": "[parameters('appSecret')]"
151+
}
152+
],
153+
"cors": {
154+
"allowedOrigins": [
155+
"https://botservice.hosting.portal.azure.net",
156+
"https://hosting.onecloud.azure-test.net/"
157+
]
158+
}
159+
}
160+
}
161+
},
162+
{
163+
"apiVersion": "2017-12-01",
164+
"type": "Microsoft.BotService/botServices",
165+
"name": "[parameters('botId')]",
166+
"location": "global",
167+
"kind": "bot",
168+
"sku": {
169+
"name": "[parameters('botSku')]"
170+
},
171+
"properties": {
172+
"name": "[parameters('botId')]",
173+
"displayName": "[parameters('botId')]",
174+
"endpoint": "[variables('botEndpoint')]",
175+
"msaAppId": "[parameters('appId')]",
176+
"developerAppInsightsApplicationId": null,
177+
"developerAppInsightKey": null,
178+
"publishingCredentials": null,
179+
"storageResourceId": null
180+
},
181+
"dependsOn": [
182+
"[resourceId('Microsoft.Web/sites/', variables('webAppName'))]"
183+
]
184+
}
185+
],
186+
"outputs": {}
187+
}
188+
}
189+
}
190+
]
191+
}

0 commit comments

Comments
 (0)