Skip to content

Commit

Permalink
Merge pull request #1357 from OfficeDev/v-hrajandira/CsharpNewToolkit…
Browse files Browse the repository at this point in the history
…PR14

PR 14 - Implement New toolkit version csharp samples
  • Loading branch information
Harikrishnan-MSFT authored Aug 21, 2024
2 parents bbf5371 + 337b413 commit 08c1ccf
Show file tree
Hide file tree
Showing 47 changed files with 1,194 additions and 93 deletions.
15 changes: 13 additions & 2 deletions samples/graph-change-notification/csharp/ChangeNotification.sln
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31229.75
# Visual Studio Version 17
VisualStudioVersion = 17.10.35027.167
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChangeNotification", "ChangeNotification\ChangeNotification.csproj", "{22FC914C-9E44-4D7C-A8C6-45EE48960B6D}"
EndProject
Project("{A9E3F50B-275E-4AF7-ADCE-8BE12D41E305}") = "TeamsApp", "TeamsApp\TeamsApp.ttkproj", "{F9F76B0B-73F7-4752-BC87-3ABBD6C4DA19}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{16DD3A2B-95C1-4FDA-BA24-2EFA12399411}"
ProjectSection(SolutionItems) = preProject
ChangeNotification.slnLaunch.user = ChangeNotification.slnLaunch.user
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +22,10 @@ Global
{22FC914C-9E44-4D7C-A8C6-45EE48960B6D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{22FC914C-9E44-4D7C-A8C6-45EE48960B6D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{22FC914C-9E44-4D7C-A8C6-45EE48960B6D}.Release|Any CPU.Build.0 = Release|Any CPU
{F9F76B0B-73F7-4752-BC87-3ABBD6C4DA19}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F9F76B0B-73F7-4752-BC87-3ABBD6C4DA19}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F9F76B0B-73F7-4752-BC87-3ABBD6C4DA19}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F9F76B0B-73F7-4752-BC87-3ABBD6C4DA19}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{
"Name": "Microsoft Teams (browser)",
"Projects": [
{
"Path": "ChangeNotification\\ChangeNotification.csproj",
"Action": "Start",
"DebugTarget": "Start Project"
},
{
"Path": "TeamsApp\\TeamsApp.ttkproj",
"Action": "StartWithoutDebugging",
"DebugTarget": "Microsoft Teams (Browser)"
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# TeamsFx files
build
appPackage/build
env/.env.*.user
env/.env.local
appsettings.Development.json
.deployment

# User-specific files
*.user

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/

# Notification local store
.notification.localstore.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:3978/",
"sslPort": 0
}
},
{
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"AuthenticationBot": {
"Start Project": {
"commandName": "Project",
"launchBrowser": true,
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7130;http://localhost:5130",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:3978/"
"hotReloadProfile": "aspnetcore"
}
}
}
}
30 changes: 23 additions & 7 deletions samples/graph-change-notification/csharp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,22 @@ This sample app demonstrates sending change notifications to user presence in Te
- [.NET Core SDK](https://dotnet.microsoft.com/download) version 3.1
- [dev tunnel](https://learn.microsoft.com/en-us/azure/developer/dev-tunnels/get-started?tabs=windows) or [ngrok](https://ngrok.com/) latest version or equivalent tunnelling solution
- [M365 developer account](https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/build-and-test/prepare-your-o365-tenant) or access to a Teams account with the appropriate permissions to install an app.

## Setup
- [Teams Toolkit for Visual Studio](https://learn.microsoft.com/en-us/microsoftteams/platform/toolkit/toolkit-v4/install-teams-toolkit-vs?pivots=visual-studio-v17-7)

## Run the app (Using Teams Toolkit for Visual Studio)

The simplest way to run this sample in Teams is to use Teams Toolkit for Visual Studio.
1. Install Visual Studio 2022 **Version 17.10 Preview 4 or higher** [Visual Studio](https://visualstudio.microsoft.com/downloads/)
1. Install Teams Toolkit for Visual Studio [Teams Toolkit extension](https://learn.microsoft.com/en-us/microsoftteams/platform/toolkit/toolkit-v4/install-teams-toolkit-vs?pivots=visual-studio-v17-7)
1. 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.
1. In the debug dropdown menu of Visual Studio, select default startup project > **Microsoft Teams (browser)**
1. In Visual Studio, right-click your **TeamsApp** project and **Select Teams Toolkit > Prepare Teams App Dependencies**
1. Using the extension, sign in with your Microsoft 365 account where you have permissions to upload custom apps.
1. Select **Debug > Start Debugging** or **F5** to run the menu in Visual Studio.
1. 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.
## Manually Setup and use the sample locally.
### Register you app with Azure AD.

1. Register a new application in the [Microsoft Entra ID – App Registrations](https://go.microsoft.com/fwlink/?linkid=2083908) portal.
Expand Down Expand Up @@ -117,16 +131,16 @@ This sample app demonstrates sending change notifications to user presence in Te
git clone https://github.com/OfficeDev/Microsoft-Teams-Samples.git
```

2) Run ngrok - point to port 3978
2) Run ngrok - point to port 5130

```bash
ngrok http 3978 --host-header="localhost:3978"
ngrok http 5130 --host-header="localhost:5130"
```

Alternatively, you can also use the `dev tunnels`. Please follow [Create and host a dev tunnel](https://learn.microsoft.com/en-us/azure/developer/dev-tunnels/get-started?tabs=windows) and host the tunnel with anonymous user access command as shown below:

```bash
devtunnel host -p 3978 --allow-anonymous
devtunnel host -p 5130 --allow-anonymous
```

3) Open the code in Visual Studio
Expand All @@ -135,6 +149,8 @@ This sample app demonstrates sending change notifications to user presence in Te
- File -> Open Folder
- Navigate to `samples/graph-change-notification/csharp` folder
- Select `ChangeNotification.sln` and open it in Visual Studio

**Note:** In the debug dropdown menu of Visual Studio, select default startup project > **ChangeNotification**

4) Setup and run the bot from Visual Studio:
Modify the `appsettings.json` file with the following details:
Expand All @@ -144,9 +160,9 @@ Modify the `appsettings.json` file with the following details:
- Press `F5` to run the project

5) __*This step is specific to Teams.*__
- **Edit** the `manifest.json`file contained in the `AppManifest` folder to replace your Microsoft App Id (that was created when you registered your Microsoft Entra ID app registration earlier) *everywhere* you see the place holder string `<<app id>>` (depending on the scenario the Microsoft App Id may occur multiple times in the `manifest.json`)
- **Edit** the `manifest.json`file contained in the `appPackage` folder to replace your Microsoft App Id (that was created when you registered your Microsoft Entra ID app registration earlier) *everywhere* you see the place holder string `<<app id>>` (depending on the scenario the Microsoft App Id may occur multiple times in the `manifest.json`)
- `[Your tunnel Domain]` with base Url domain. E.g. if you are using ngrok it would be `https://1234.ngrok-free.app` then your domain-name will be `1234.ngrok-free.app` and if you are using dev tunnels then your domain will be like: `12345.devtunnels.ms`.
- **Zip** up the contents of the `AppManifest` folder to create a `manifest.zip`
- **Zip** up the contents of the `appPackage` folder to create a `manifest.zip`
- **Upload** the `manifest.zip` to Teams (in the Apps view click "Upload a custom app")
**Note**: If you are facing any issue in your app, please uncomment [this](https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/main/samples/graph-change-notification/csharp/ChangeNotification/AdapterWithErrorHandler.cs#L28) line and put your debugger for local debug.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" Sdk="Microsoft.TeamsFx.Sdk">
<PropertyGroup Label="Globals">
<ProjectGuid>f9f76b0b-73f7-4752-bc87-3abbd6c4da19</ProjectGuid>
</PropertyGroup>
<ItemGroup>
<ProjectCapability Include="ProjectConfigurationsDeclaredDimensions" />
</ItemGroup>
</Project>
111 changes: 111 additions & 0 deletions samples/graph-change-notification/csharp/TeamsApp/aad.manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{
"id": "${{AAD_APP_OBJECT_ID}}",
"appId": "${{AAD_APP_CLIENT_ID}}",
"name": "graph-change-notification-aad",
"accessTokenAcceptedVersion": 2,
"signInAudience": "AzureADMultipleOrgs",
"oauth2AllowIdTokenImplicitFlow": true,
"oauth2AllowImplicitFlow": true,
"optionalClaims": {
"idToken": [],
"accessToken": [
{
"name": "idtyp",
"source": null,
"essential": false,
"additionalProperties": []
}
],
"saml2Token": []
},
"requiredResourceAccess": [
{
"resourceAppId": "Microsoft Graph",
"resourceAccess": [
{
"id": "User.Read",
"type": "Scope"
},
{
"id": "Presence.Read",
"type": "Scope"
},
{
"id": "Presence.Read.All",
"type": "Scope"
}
]
}
],
"oauth2Permissions": [
{
"adminConsentDescription": "Allows Teams to call the app's web APIs as the current user.",
"adminConsentDisplayName": "Teams can access app's web APIs",
"id": "${{AAD_APP_ACCESS_AS_USER_PERMISSION_ID}}",
"isEnabled": true,
"type": "User",
"userConsentDescription": "Enable Teams to call this app's web APIs with the same rights that you have",
"userConsentDisplayName": "Teams can access app's web APIs and make requests on your behalf",
"value": "access_as_user"
}
],
"preAuthorizedApplications": [
{
"appId": "1fec8e78-bce4-4aaf-ab1b-5451cc387264",
"permissionIds": [
"${{AAD_APP_ACCESS_AS_USER_PERMISSION_ID}}"
]
},
{
"appId": "5e3ce6c0-2b1f-4285-8d4b-75ee78787346",
"permissionIds": [
"${{AAD_APP_ACCESS_AS_USER_PERMISSION_ID}}"
]
},
{
"appId": "d3590ed6-52b3-4102-aeff-aad2292ab01c",
"permissionIds": [
"${{AAD_APP_ACCESS_AS_USER_PERMISSION_ID}}"
]
},
{
"appId": "00000002-0000-0ff1-ce00-000000000000",
"permissionIds": [
"${{AAD_APP_ACCESS_AS_USER_PERMISSION_ID}}"
]
},
{
"appId": "bc59ab01-8403-45c6-8796-ac3ef710b3e3",
"permissionIds": [
"${{AAD_APP_ACCESS_AS_USER_PERMISSION_ID}}"
]
},
{
"appId": "0ec893e0-5785-4de6-99da-4ed124e5296c",
"permissionIds": [
"${{AAD_APP_ACCESS_AS_USER_PERMISSION_ID}}"
]
},
{
"appId": "4765445b-32c6-49b0-83e6-1d93765276ca",
"permissionIds": [
"${{AAD_APP_ACCESS_AS_USER_PERMISSION_ID}}"
]
},
{
"appId": "4345a7b9-9a63-4910-a426-35363201d503",
"permissionIds": [
"${{AAD_APP_ACCESS_AS_USER_PERMISSION_ID}}"
]
}
],
"identifierUris":[
"api://botid-${{AAD_APP_CLIENT_ID}}"
],
"replyUrlsWithType":[
{
"url": "https://token.botframework.com/.auth/web/redirect",
"type": "Web"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://developer.microsoft.com/json-schemas/teams/v1.16/MicrosoftTeams.schema.json",
"manifestVersion": "1.16",
"version": "1.0.0",
"id": "<<App Id>>",
"id": "${{TEAMS_APP_ID}}",
"packageName": "com.teams.change.notification",
"developer": {
"name": "Microsoft",
Expand All @@ -25,7 +25,7 @@
"accentColor": "#FFFFFF",
"bots": [
{
"botId": "<<App Id>>",
"botId": "${{AAD_APP_CLIENT_ID}}",
"scopes": [
"personal",
"team"
Expand All @@ -40,6 +40,6 @@
],
"validDomains": [
"token.botframework.com",
"[Your tunnel Domain]"
"${{BOT_DOMAIN}}"
]
}
26 changes: 26 additions & 0 deletions samples/graph-change-notification/csharp/TeamsApp/env/.env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This file includes environment variables that can be committed to git. It's gitignored by default because it represents your local development environment.

# Built-in environment variables
TEAMSFX_ENV=local
APP_NAME_SUFFIX=local

# Generated during provision, you can also add your own variables.
BOT_ID=
TEAMS_APP_ID=
RESOURCE_SUFFIX=
AZURE_SUBSCRIPTION_ID=
AZURE_RESOURCE_GROUP_NAME=
AAD_APP_CLIENT_ID=
AAD_APP_OBJECT_ID=
AAD_APP_TENANT_ID=
AAD_APP_OAUTH_AUTHORITY=
AAD_APP_OAUTH_AUTHORITY_HOST=
TEAMS_APP_TENANT_ID=
MICROSOFT_APP_TYPE=
MICROSOFT_APP_TENANT_ID=
CONNECTION_NAME=
AAD_APP_ACCESS_AS_USER_PERMISSION_ID=
TEAMSFX_M365_USER_NAME=

BOT_ENDPOINT=
BOT_DOMAIN=
Loading

0 comments on commit 08c1ccf

Please sign in to comment.