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

Commit c601450

Browse files
authored
Merge pull request #490 from microsoft/emimunoz/58-teams-start-thread
58- Teams start thread in Channel
2 parents 2968c3a + c45b1ce commit c601450

File tree

18 files changed

+1473
-0
lines changed

18 files changed

+1473
-0
lines changed
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: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Teams Start Thread In A Team
2+
3+
Bot Framework v4 Conversation Bot sample for Teams.
4+
5+
This bot has been created using [Bot Framework](https://dev.botframework.com). This sample shows
6+
how to incorporate basic conversational flow into a Teams application. It also illustrates a few of the Teams specific calls you can make from your bot.
7+
8+
## Prerequisites
9+
10+
- Microsoft Teams is installed and you have an account
11+
- [ngrok](https://ngrok.com/) or equivalent tunnelling solution
12+
13+
## To try this sample
14+
15+
> Note these instructions are for running the sample on your local machine, the tunnelling solution is required because
16+
the Teams service needs to call into the bot.
17+
18+
1) Clone the repository
19+
20+
```bash
21+
git clone https://github.com/Microsoft/botbuilder-java.git
22+
```
23+
24+
1) Run ngrok - point to port 8080
25+
26+
```bash
27+
ngrok http -host-header=rewrite 8080
28+
```
29+
30+
1) Create [Bot Framework registration resource](https://docs.microsoft.com/en-us/azure/bot-service/bot-service-quickstart-registration) in Azure
31+
- Use the current `https` URL you were given by running ngrok. Append with the path `/api/messages` used by this sample
32+
- 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)
33+
- __*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)
34+
35+
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.)
36+
37+
1) __*This step is specific to Teams.*__
38+
- **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 `<<YOUR-MICROSOFT-APP-ID>>` (depending on the scenario the Microsoft App Id may occur multiple times in the `manifest.json`)
39+
- **Zip** up the contents of the `teamsAppManifest` folder to create a `manifest.zip`
40+
- **Upload** the `manifest.zip` to Teams (in the Apps view click "Upload a custom app")
41+
42+
1) From the root of this project folder:
43+
- Build the sample using `mvn package`
44+
- Unless done previously, install the packages in the local cache by using `mvn install`
45+
- Run it by using `java -jar .\target\bot-teams-start-new-thread-sample-.jar`
46+
47+
48+
## Interacting with the bot in Teams
49+
50+
> Note this `manifest.json` specified that the bot will be installed in "personal", "team" and "groupchat" scope which is why you immediately entered a one on one chat conversation with the bot. You can at mention the bot in a group chat or in a Channel in the Team you installed it in. Please refer to Teams documentation for more details.
51+
52+
You can interact with this bot by sending it a message. The bot will respond by creating a new thread in the channel and replying to that new thread.
53+
54+
## Deploy the bot to Azure
55+
56+
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.
57+
58+
## Further reading
59+
60+
- [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)
61+
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)