page_type | products | languages | title | description | extensions | urlFragment | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
sample |
|
|
Microsoft Teams C# Helloworld Sample |
A Microsoft Teams Hello World sample app built with .NET/C# that demonstrates essential features like tabs, bots, and messaging extensions for seamless interaction within the Teams environment. |
|
officedev-microsoft-teams-samples-app-hello-world-csharp |
- The Microsoft Teams Hello World application, built with .NET/C#, serves as an introductory sample showcasing fundamental Microsoft Teams capabilities, including tabs, bots, and messaging extensions. This application provides a hands-on experience for developers looking to explore the Teams platform and its integration options.
- Tabs
- Bots
- Messaging Extensions
Please find below demo manifest which is deployed on Microsoft Azure and you can try it yourself by uploading the app package (.zip file link below) to your teams and/or as a personal app. (Sideloading must be enabled for your tenant, see steps here).
Microsoft Teams hello world sample app: Manifest
-
.NET Core SDK version 6.0
# determine dotnet version dotnet --version
-
Publicly addressable https url or tunnel such as dev tunnel or ngrok latest version or Tunnel Relay
The simplest way to run this sample in Teams is to use Teams Toolkit for Visual Studio.
- Install Visual Studio 2022 Version 17.10 Preview 4 or higher Visual Studio
- Install Teams Toolkit for Visual Studio Teams Toolkit extension
- In the debug dropdown menu of Visual Studio, select Dev Tunnels > Create A Tunnel (set authentication type to Public) or select an existing public dev tunnel.
- In the debug dropdown menu of Visual Studio, select default startup project > Microsoft Teams (browser)
- In Visual Studio, right-click your TeamsApp project and Select Teams Toolkit > Prepare Teams App Dependencies
- Using the extension, sign in with your Microsoft 365 account where you have permissions to upload custom apps.
- Select Debug > Start Debugging or F5 to run the menu in Visual Studio.
- In the browser that launches, select the Add button to install the app to Teams.
If you do not have permission to upload custom apps (sideloading), Teams Toolkit will recommend creating and using a Microsoft 365 Developer Program account - a free program to get your own dev environment sandbox that includes Teams.
-
Register a bot with Azure Bot Service, following the instructions here.
-
Ensure that you've enabled the Teams Channel
-
While registering the bot, use
https://<your_tunnel_domain>/api/messages
as the messaging endpoint.NOTE: When you create your bot you will create an App ID and App password - make sure you keep these for later.
-
Run ngrok - point to port 5000
ngrok http 5000 --host-header="localhost:5000"
Alternatively, you can also use the
dev tunnels
. Please follow Create and host a dev tunnel and host the tunnel with anonymous user access command as shown below:devtunnel host -p 5000 --allow-anonymous
-
Clone the repository
git clone https://github.com/OfficeDev/Microsoft-Teams-Samples.git
Run the bot from a terminal or from Visual Studio:
A) From a terminal, navigate to Microsoft.Teams.Samples.HelloWorld.Web
# run the bot
dotnet run
B) Or from Visual Studio
- Launch Visual Studio
- File -> Open -> Project/Solution
- Navigate to
Microsoft.Teams.Samples.HelloWorld.Web
folder - Select
Microsoft.Teams.Samples.HelloWorld.Web.csproj
file - Press
F5
to run the project
- This step is specific to Teams.
- Modify the
manifest.json
in the/AppManifest
folder and replace the following details:
{{Microsoft-App-Id}}
with Application id generated from Step 1{{domain-name}}
with base Url domain. E.g. if you are using ngrok it would be1234.ngrok-free.app
and if you are using dev tunnels then your domain will be like:12345.devtunnels.ms
.
Note: If you want to test your app across multi hub like: Outlook/Office.com, please update the manifest.json
in the /AppManifest_Hub
folder with the required values.
-
Zip the contents of
appPackage
orAppManifest_Hub
folder into amanifest.zip
. -
Modify the
/appsettings.json
and fill in the following details:
{{Microsoft-App-Id}}
- Generated from Step 1 is the application app id{{ Microsoft-App-Password}}
- Generated from Step 1, also referred to as Client secret{{ Application Base Url }}
- Your application's base url. E.g. https://12345.ngrok-free.app if you are using ngrok and if you are using dev tunnels, your URL will be https://12345.devtunnels.ms.
- Upload the manifest.zip to Teams (in the Apps view click "Upload a custom app")
- Go to Microsoft Teams. From the lower left corner, select Apps
- From the lower left corner, choose Upload a custom App
- Go to your project directory, the ./appPackage folder, select the zip folder, and choose Open.
- Select Add in the pop-up dialog box. Your app is uploaded to Teams.
This app has a default landing capability that determines whether the opening scope is set to the Bot or a static tab. Without configuring this, Microsoft Teams defaults to landing on the bot in desktop clients and tab in mobile clients.
To set the Bot as the default landing capability, configure the 'staticTabs' section in the manifest as follows:
"staticTabs": [
{
"entityId": "conversations",
"scopes": [
"personal"
]
},
{
"entityId": "com.contoso.helloworld.hellotab",
"name": "Hello Tab",
"contentUrl": "https://${{BOT_DOMAIN}}/hello",
"scopes": [
"personal"
]
}
],
To set the Tab as the default landing capability, configure the 'staticTabs' section in the manifest as follows:
"staticTabs": [
{
"entityId": "com.contoso.helloworld.hellotab",
"name": "Hello Tab",
"contentUrl": "https://${{BOT_DOMAIN}}/hello",
"scopes": [
"personal"
]
},
{
"entityId": "conversations",
"scopes": [
"personal"
]
}
],
Note: If you are facing any issue in your app, please uncomment this line and put your debugger for local debug.
Install App:
Welcome Bot:
Welcome UI:
-
To view your app in Outlook on the web.
-
Go to Outlook on the weband sign in using your dev tenant account.
On the side bar, select More Apps. Your sideloaded app title appears among your installed apps
Select your app icon to launch and preview your app running in Outlook on the web
Note: Similarly, you can test your application in the Outlook desktop app as well.
-
To preview your app running in Office on the web.
-
Log into office.com with test tenant credentials
Select the Apps icon on the side bar. Your sideloaded app title appears among your installed apps
Select your app icon to launch your app in Office on the web
Note: Similarly, you can test your application in the Office 365 desktop app as well.
To learn more about deploying a bot to Azure, see Deploy your bot to Azure for a complete list of deployment instructions.