diff --git a/samples/bot-file-upload/csharp/.gitignore b/samples/bot-file-upload/csharp/.gitignore new file mode 100644 index 0000000000..d231a7a175 --- /dev/null +++ b/samples/bot-file-upload/csharp/.gitignore @@ -0,0 +1,25 @@ +# TeamsFx files +build +AppManifest/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 \ No newline at end of file diff --git a/samples/bot-file-upload/csharp/AppManifest/manifest.json b/samples/bot-file-upload/csharp/AppManifest/manifest.json index 64928f18cb..110f07a1f7 100644 --- a/samples/bot-file-upload/csharp/AppManifest/manifest.json +++ b/samples/bot-file-upload/csharp/AppManifest/manifest.json @@ -2,7 +2,7 @@ "$schema": "https://developer.microsoft.com/json-schemas/teams/v1.16/MicrosoftTeams.schema.json", "manifestVersion": "1.16", "version": "1.0", - "id": "<>", + "id": "${{TEAMS_APP_ID}}", "packageName": "com.microsoft.teams.fileupload", "developer": { "name": "Microsoft Corp", @@ -25,7 +25,7 @@ "accentColor": "#abcdef", "bots": [ { - "botId": "<>", + "botId": "${{AAD_APP_CLIENT_ID}}", "scopes": [ "personal" ], @@ -36,6 +36,7 @@ } ], "validDomains": [ - "*.azurewebsites.net" + "${{BOT_DOMAIN}}", + "*.ngrok-free.app" ] } \ No newline at end of file diff --git a/samples/bot-file-upload/csharp/Properties/launchSettings.json b/samples/bot-file-upload/csharp/Properties/launchSettings.json index ad1eb2c923..068eff82a9 100644 --- a/samples/bot-file-upload/csharp/Properties/launchSettings.json +++ b/samples/bot-file-upload/csharp/Properties/launchSettings.json @@ -1,27 +1,28 @@ { - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:3978/", - "sslPort": 0 - } - }, - "profiles": { - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - ".NET Core": { - "commandName": "Project", - "launchBrowser": true, - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "applicationUrl": "http://localhost:3978/" - } - } + "profiles": { + // Debug project within Teams + "Microsoft Teams (browser)": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "https://teams.microsoft.com/l/app/%TEAMSAPPID%?installAppPackage=true&webjoin=true&appTenantId=%TENANTID%&login_hint=%USERNAME%", + "applicationUrl": "http://localhost:5130", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "hotReloadProfile": "aspnetcore" + } + //// Uncomment following profile to debug project only (without launching Teams) + //, + //"Start Project (not in Teams)": { + // "commandName": "Project", + // "dotnetRunMessages": true, + // "launchBrowser": true, + // "applicationUrl": "https://localhost:7130;http://localhost:5130", + // "environmentVariables": { + // "ASPNETCORE_ENVIRONMENT": "Development" + // }, + // "hotReloadProfile": "aspnetcore" + //} + } } \ No newline at end of file diff --git a/samples/bot-file-upload/csharp/README.md b/samples/bot-file-upload/csharp/README.md index 579896ffec..44aed4cca9 100644 --- a/samples/bot-file-upload/csharp/README.md +++ b/samples/bot-file-upload/csharp/README.md @@ -37,6 +37,19 @@ Please find below demo manifest which is deployed on Microsoft Azure and you can - Microsoft Teams is installed and you have an account - [.NET SDK](https://dotnet.microsoft.com/download) version 6.0 - [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 +- [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.9 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 Visual Studio, right-click your 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. ## Setup diff --git a/samples/bot-file-upload/csharp/TeamsFileUpload.csproj b/samples/bot-file-upload/csharp/TeamsFileUpload.csproj index 8ebf7bfe85..73bb04a9ae 100644 --- a/samples/bot-file-upload/csharp/TeamsFileUpload.csproj +++ b/samples/bot-file-upload/csharp/TeamsFileUpload.csproj @@ -49,4 +49,8 @@ + + + + diff --git a/samples/bot-file-upload/csharp/env/.env.local b/samples/bot-file-upload/csharp/env/.env.local new file mode 100644 index 0000000000..f2775c4fc6 --- /dev/null +++ b/samples/bot-file-upload/csharp/env/.env.local @@ -0,0 +1,23 @@ +# 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= +TEAMSFX_M365_USER_NAME= + +BOT_ENDPOINT= +BOT_DOMAIN= + +RESOURCE_SUFFIX= +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= \ No newline at end of file diff --git a/samples/bot-file-upload/csharp/infra/azure.bicep b/samples/bot-file-upload/csharp/infra/azure.bicep new file mode 100644 index 0000000000..c3ce051b3d --- /dev/null +++ b/samples/bot-file-upload/csharp/infra/azure.bicep @@ -0,0 +1,44 @@ +@maxLength(20) +@minLength(4) +@description('Used to generate names for all resources in this file') +param resourceBaseName string + +@description('Required when create Azure Bot service') +param botAadAppClientId string + +param botAppDomain string + +@maxLength(42) +param botDisplayName string + +param botServiceName string = resourceBaseName +param botServiceSku string = 'F0' +param microsoftAppType string +param microsoftAppTenantId string + +// Register your web service as a bot with the Bot Framework +resource botService 'Microsoft.BotService/botServices@2021-03-01' = { + kind: 'azurebot' + location: 'global' + name: botServiceName + properties: { + displayName: botDisplayName + endpoint: 'https://${botAppDomain}/api/messages' + msaAppId: botAadAppClientId + msaAppType: microsoftAppType + msaAppTenantId: microsoftAppType == 'SingleTenant' ? microsoftAppTenantId : '' + } + sku: { + name: botServiceSku + } +} + +// Connect the bot service to Microsoft Teams +resource botServiceMsTeamsChannel 'Microsoft.BotService/botServices/channels@2021-03-01' = { + parent: botService + location: 'global' + name: 'MsTeamsChannel' + properties: { + channelName: 'MsTeamsChannel' + } +} diff --git a/samples/bot-file-upload/csharp/infra/azure.parameters.json b/samples/bot-file-upload/csharp/infra/azure.parameters.json new file mode 100644 index 0000000000..d8454ee752 --- /dev/null +++ b/samples/bot-file-upload/csharp/infra/azure.parameters.json @@ -0,0 +1,24 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "resourceBaseName": { + "value": "bot${{RESOURCE_SUFFIX}}" + }, + "botAadAppClientId": { + "value": "${{AAD_APP_CLIENT_ID}}" + }, + "botAppDomain": { + "value": "${{BOT_DOMAIN}}" + }, + "botDisplayName": { + "value": "TestBot" + }, + "microsoftAppType": { + "value": "${{MICROSOFT_APP_TYPE}}" + }, + "microsoftAppTenantId": { + "value": "${{MICROSOFT_APP_TENANT_ID}}" + } + } +} \ No newline at end of file diff --git a/samples/bot-file-upload/csharp/teamsapp.local.yml b/samples/bot-file-upload/csharp/teamsapp.local.yml new file mode 100644 index 0000000000..909f827a30 --- /dev/null +++ b/samples/bot-file-upload/csharp/teamsapp.local.yml @@ -0,0 +1,101 @@ +# yaml-language-server: $schema=https://aka.ms/teams-toolkit/v1.2/yaml.schema.json +# Visit https://aka.ms/teamsfx-v5.0-guide for details on this file +# Visit https://aka.ms/teamsfx-actions for details on actions +version: v1.2 + +additionalMetadata: + sampleTag: Microsoft-Teams-Samples:bot-file-upload-csharp + +provision: + - uses: aadApp/create # Creates a new Azure Active Directory (AAD) app to authenticate users if the environment variable that stores clientId is empty + with: + name: bot-file-upload-aad # Note: when you run aadApp/update, the AAD app name will be updated based on the definition in manifest. If you don't want to change the name, make sure the name in AAD manifest is the same with the name defined here. + generateClientSecret: true # If the value is false, the action will not generate client secret for you + signInAudience: "AzureADMultipleOrgs" # Multitenant + writeToEnvironmentFile: # Write the information of created resources into environment file for the specified environment variable(s). + clientId: AAD_APP_CLIENT_ID + clientSecret: SECRET_AAD_APP_CLIENT_SECRET # Environment variable that starts with `SECRET_` will be stored to the .env.{envName}.user environment file + objectId: AAD_APP_OBJECT_ID + tenantId: AAD_APP_TENANT_ID + authority: AAD_APP_OAUTH_AUTHORITY + authorityHost: AAD_APP_OAUTH_AUTHORITY_HOST + + # Creates a Teams app + - uses: teamsApp/create + with: + # Teams app name + name: bot-file-upload-${{TEAMSFX_ENV}} + # Write the information of created resources into environment file for + # the specified environment variable(s). + writeToEnvironmentFile: + teamsAppId: TEAMS_APP_ID + + - uses: script + with: + run: + # echo "::set-teamsfx-env MICROSOFT_APP_TYPE=SingleTenant"; + echo "::set-teamsfx-env MICROSOFT_APP_TYPE=MultiTenant"; + echo "::set-teamsfx-env MICROSOFT_APP_TENANT_ID=${{AAD_APP_TENANT_ID}}"; + + # Generate runtime appsettings to JSON file + - uses: file/createOrUpdateJsonFile + with: + target: ./appsettings.json + content: + MicrosoftAppId: ${{AAD_APP_CLIENT_ID}} + MicrosoftAppPassword: ${{SECRET_AAD_APP_CLIENT_SECRET}} + MicrosoftAppType: ${{MICROSOFT_APP_TYPE}} + MicrosoftAppTenantId: ${{MICROSOFT_APP_TENANT_ID}} + + - uses: arm/deploy # Deploy given ARM templates parallelly. + with: + subscriptionId: ${{AZURE_SUBSCRIPTION_ID}} # The AZURE_SUBSCRIPTION_ID is a built-in environment variable. TeamsFx will ask you select one subscription if its value is empty. You're free to reference other environment varialbe here, but TeamsFx will not ask you to select subscription if it's empty in this case. + resourceGroupName: ${{AZURE_RESOURCE_GROUP_NAME}} # The AZURE_RESOURCE_GROUP_NAME is a built-in environment variable. TeamsFx will ask you to select or create one resource group if its value is empty. You're free to reference other environment varialbe here, but TeamsFx will not ask you to select or create resource grouop if it's empty in this case. + templates: + - path: ./infra/azure.bicep + parameters: ./infra/azure.parameters.json + deploymentName: Create-resources-for-bot + bicepCliVersion: v0.9.1 # Teams Toolkit will download this bicep CLI version from github for you, will use bicep CLI in PATH if you remove this config. + + # Validate using manifest schema + - uses: teamsApp/validateManifest + with: + # Path to manifest template + manifestPath: ./AppManifest/manifest.json + + # Build Teams app package with latest env value + - uses: teamsApp/zipAppPackage + with: + # Path to manifest template + manifestPath: ./AppManifest/manifest.json + outputZipPath: ./AppManifest/build/AppManifest.${{TEAMSFX_ENV}}.zip + outputJsonPath: ./AppManifest/build/manifest.${{TEAMSFX_ENV}}.json + # Validate app package using validation rules + - uses: teamsApp/validateAppPackage + with: + # Relative path to this file. This is the path for built zip file. + appPackagePath: ./AppManifest/build/AppManifest.${{TEAMSFX_ENV}}.zip + + # Apply the Teams app manifest to an existing Teams app in + # Teams Developer Portal. + # Will use the app id in manifest file to determine which Teams app to update. + - uses: teamsApp/update + with: + # Relative path to this file. This is the path for built zip file. + appPackagePath: ./AppManifest/build/AppManifest.${{TEAMSFX_ENV}}.zip + + # Create or update debug profile in lauchsettings file + - uses: file/createOrUpdateJsonFile + with: + target: ./Properties/launchSettings.json + content: + profiles: + Microsoft Teams (browser): + commandName: "Project" + dotnetRunMessages: true + launchBrowser: true + launchUrl: "https://teams.microsoft.com/l/app/${{TEAMS_APP_ID}}?installAppPackage=true&webjoin=true&appTenantId=${{TEAMS_APP_TENANT_ID}}&login_hint=${{TEAMSFX_M365_USER_NAME}}" + applicationUrl: "http://localhost:5130" + environmentVariables: + ASPNETCORE_ENVIRONMENT: "Development" + hotReloadProfile: "aspnetcore" \ No newline at end of file diff --git a/samples/bot-file-upload/csharp/teamsapp.yml b/samples/bot-file-upload/csharp/teamsapp.yml new file mode 100644 index 0000000000..bb717a945a --- /dev/null +++ b/samples/bot-file-upload/csharp/teamsapp.yml @@ -0,0 +1,9 @@ +# yaml-language-server: $schema=https://aka.ms/teams-toolkit/v1.2/yaml.schema.json +# Visit https://aka.ms/teamsfx-v5.0-guide for details on this file +# Visit https://aka.ms/teamsfx-actions for details on actions +version: v1.2 + +additionalMetadata: + sampleTag: Microsoft-Teams-Samples:bot-file-upload-csharp + +environmentFolderPath: ./env \ No newline at end of file diff --git a/samples/bot-formatting-cards/csharp/BotFormattingCards/.gitignore b/samples/bot-formatting-cards/csharp/BotFormattingCards/.gitignore new file mode 100644 index 0000000000..d231a7a175 --- /dev/null +++ b/samples/bot-formatting-cards/csharp/BotFormattingCards/.gitignore @@ -0,0 +1,25 @@ +# TeamsFx files +build +AppManifest/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 \ No newline at end of file diff --git a/samples/bot-formatting-cards/csharp/BotFormattingCards/AppManifest/manifest.json b/samples/bot-formatting-cards/csharp/BotFormattingCards/AppManifest/manifest.json index c616f40602..b03b4775ab 100644 --- a/samples/bot-formatting-cards/csharp/BotFormattingCards/AppManifest/manifest.json +++ b/samples/bot-formatting-cards/csharp/BotFormattingCards/AppManifest/manifest.json @@ -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": "{{Microsoft-App-Id}}", + "id": "${{TEAMS_APP_ID}}", "packageName": "com.microsoft.teams.differentformattingcards", "developer": { "name": "Microsoft", @@ -25,7 +25,7 @@ "accentColor": "#60A18E", "bots": [ { - "botId": "{{Microsoft-App-Id}}", + "botId": "${{AAD_APP_CLIENT_ID}}", "scopes": [ "personal" ], @@ -33,6 +33,7 @@ } ], "validDomains": [ - "{{domain-name}}" + "${{BOT_DOMAIN}}", + "*.ngrok-free.app" ] } \ No newline at end of file diff --git a/samples/bot-formatting-cards/csharp/BotFormattingCards/AppManifest/outline.png b/samples/bot-formatting-cards/csharp/BotFormattingCards/AppManifest/outline.png index dbfa927729..2c3bf6fa65 100644 Binary files a/samples/bot-formatting-cards/csharp/BotFormattingCards/AppManifest/outline.png and b/samples/bot-formatting-cards/csharp/BotFormattingCards/AppManifest/outline.png differ diff --git a/samples/bot-formatting-cards/csharp/BotFormattingCards/BotFormattingCards.csproj b/samples/bot-formatting-cards/csharp/BotFormattingCards/BotFormattingCards.csproj index adb0218bdc..9df3c674ef 100644 --- a/samples/bot-formatting-cards/csharp/BotFormattingCards/BotFormattingCards.csproj +++ b/samples/bot-formatting-cards/csharp/BotFormattingCards/BotFormattingCards.csproj @@ -19,4 +19,8 @@ + + + + diff --git a/samples/bot-formatting-cards/csharp/BotFormattingCards/Properties/launchSettings.json b/samples/bot-formatting-cards/csharp/BotFormattingCards/Properties/launchSettings.json index 3a137dd606..068eff82a9 100644 --- a/samples/bot-formatting-cards/csharp/BotFormattingCards/Properties/launchSettings.json +++ b/samples/bot-formatting-cards/csharp/BotFormattingCards/Properties/launchSettings.json @@ -1,27 +1,28 @@ { - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:3978/", - "sslPort": 0 - } - }, - "profiles": { - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - ".NET Core": { - "commandName": "Project", - "launchBrowser": true, - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "applicationUrl": "http://localhost:3978/" - } - } -} + "profiles": { + // Debug project within Teams + "Microsoft Teams (browser)": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "https://teams.microsoft.com/l/app/%TEAMSAPPID%?installAppPackage=true&webjoin=true&appTenantId=%TENANTID%&login_hint=%USERNAME%", + "applicationUrl": "http://localhost:5130", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "hotReloadProfile": "aspnetcore" + } + //// Uncomment following profile to debug project only (without launching Teams) + //, + //"Start Project (not in Teams)": { + // "commandName": "Project", + // "dotnetRunMessages": true, + // "launchBrowser": true, + // "applicationUrl": "https://localhost:7130;http://localhost:5130", + // "environmentVariables": { + // "ASPNETCORE_ENVIRONMENT": "Development" + // }, + // "hotReloadProfile": "aspnetcore" + //} + } +} \ No newline at end of file diff --git a/samples/bot-formatting-cards/csharp/BotFormattingCards/env/.env.local b/samples/bot-formatting-cards/csharp/BotFormattingCards/env/.env.local new file mode 100644 index 0000000000..925ac446fd --- /dev/null +++ b/samples/bot-formatting-cards/csharp/BotFormattingCards/env/.env.local @@ -0,0 +1,22 @@ +# 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= +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= +TEAMSFX_M365_USER_NAME= + +BOT_ENDPOINT= +BOT_DOMAIN= \ No newline at end of file diff --git a/samples/bot-formatting-cards/csharp/BotFormattingCards/infra/azure.bicep b/samples/bot-formatting-cards/csharp/BotFormattingCards/infra/azure.bicep new file mode 100644 index 0000000000..c3ce051b3d --- /dev/null +++ b/samples/bot-formatting-cards/csharp/BotFormattingCards/infra/azure.bicep @@ -0,0 +1,44 @@ +@maxLength(20) +@minLength(4) +@description('Used to generate names for all resources in this file') +param resourceBaseName string + +@description('Required when create Azure Bot service') +param botAadAppClientId string + +param botAppDomain string + +@maxLength(42) +param botDisplayName string + +param botServiceName string = resourceBaseName +param botServiceSku string = 'F0' +param microsoftAppType string +param microsoftAppTenantId string + +// Register your web service as a bot with the Bot Framework +resource botService 'Microsoft.BotService/botServices@2021-03-01' = { + kind: 'azurebot' + location: 'global' + name: botServiceName + properties: { + displayName: botDisplayName + endpoint: 'https://${botAppDomain}/api/messages' + msaAppId: botAadAppClientId + msaAppType: microsoftAppType + msaAppTenantId: microsoftAppType == 'SingleTenant' ? microsoftAppTenantId : '' + } + sku: { + name: botServiceSku + } +} + +// Connect the bot service to Microsoft Teams +resource botServiceMsTeamsChannel 'Microsoft.BotService/botServices/channels@2021-03-01' = { + parent: botService + location: 'global' + name: 'MsTeamsChannel' + properties: { + channelName: 'MsTeamsChannel' + } +} diff --git a/samples/bot-formatting-cards/csharp/BotFormattingCards/infra/azure.parameters.json b/samples/bot-formatting-cards/csharp/BotFormattingCards/infra/azure.parameters.json new file mode 100644 index 0000000000..d8454ee752 --- /dev/null +++ b/samples/bot-formatting-cards/csharp/BotFormattingCards/infra/azure.parameters.json @@ -0,0 +1,24 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "resourceBaseName": { + "value": "bot${{RESOURCE_SUFFIX}}" + }, + "botAadAppClientId": { + "value": "${{AAD_APP_CLIENT_ID}}" + }, + "botAppDomain": { + "value": "${{BOT_DOMAIN}}" + }, + "botDisplayName": { + "value": "TestBot" + }, + "microsoftAppType": { + "value": "${{MICROSOFT_APP_TYPE}}" + }, + "microsoftAppTenantId": { + "value": "${{MICROSOFT_APP_TENANT_ID}}" + } + } +} \ No newline at end of file diff --git a/samples/bot-formatting-cards/csharp/BotFormattingCards/teamsapp.local.yml b/samples/bot-formatting-cards/csharp/BotFormattingCards/teamsapp.local.yml new file mode 100644 index 0000000000..c4e4358c90 --- /dev/null +++ b/samples/bot-formatting-cards/csharp/BotFormattingCards/teamsapp.local.yml @@ -0,0 +1,99 @@ +# yaml-language-server: $schema=https://aka.ms/teams-toolkit/v1.2/yaml.schema.json +# Visit https://aka.ms/teamsfx-v5.0-guide for details on this file +# Visit https://aka.ms/teamsfx-actions for details on actions +version: v1.2 + +additionalMetadata: + sampleTag: Microsoft-Teams-Samples:bot-formatting-cards-csharp + +provision: + - uses: aadApp/create # Creates a new Azure Active Directory (AAD) app to authenticate users if the environment variable that stores clientId is empty + with: + name: bot-formatting-cards-aad # Note: when you run aadApp/update, the AAD app name will be updated based on the definition in manifest. If you don't want to change the name, make sure the name in AAD manifest is the same with the name defined here. + generateClientSecret: true # If the value is false, the action will not generate client secret for you + signInAudience: "AzureADMultipleOrgs" # Multitenant + writeToEnvironmentFile: # Write the information of created resources into environment file for the specified environment variable(s). + clientId: AAD_APP_CLIENT_ID + clientSecret: SECRET_AAD_APP_CLIENT_SECRET # Environment variable that starts with `SECRET_` will be stored to the .env.{envName}.user environment file + objectId: AAD_APP_OBJECT_ID + tenantId: AAD_APP_TENANT_ID + authority: AAD_APP_OAUTH_AUTHORITY + authorityHost: AAD_APP_OAUTH_AUTHORITY_HOST + + # Creates a Teams app + - uses: teamsApp/create + with: + # Teams app name + name: bot-formatting-cards-${{TEAMSFX_ENV}} + # Write the information of created resources into environment file for + # the specified environment variable(s). + writeToEnvironmentFile: + teamsAppId: TEAMS_APP_ID + + - uses: script + with: + run: + # echo "::set-teamsfx-env MICROSOFT_APP_TYPE=SingleTenant"; + echo "::set-teamsfx-env MICROSOFT_APP_TYPE=MultiTenant"; + echo "::set-teamsfx-env MICROSOFT_APP_TENANT_ID=${{AAD_APP_TENANT_ID}}"; + + # Generate runtime appsettings to JSON file + - uses: file/createOrUpdateJsonFile + with: + target: ./appsettings.json + content: + MicrosoftAppId: ${{AAD_APP_CLIENT_ID}} + MicrosoftAppPassword: ${{SECRET_AAD_APP_CLIENT_SECRET}} + + - uses: arm/deploy # Deploy given ARM templates parallelly. + with: + subscriptionId: ${{AZURE_SUBSCRIPTION_ID}} # The AZURE_SUBSCRIPTION_ID is a built-in environment variable. TeamsFx will ask you select one subscription if its value is empty. You're free to reference other environment varialbe here, but TeamsFx will not ask you to select subscription if it's empty in this case. + resourceGroupName: ${{AZURE_RESOURCE_GROUP_NAME}} # The AZURE_RESOURCE_GROUP_NAME is a built-in environment variable. TeamsFx will ask you to select or create one resource group if its value is empty. You're free to reference other environment varialbe here, but TeamsFx will not ask you to select or create resource grouop if it's empty in this case. + templates: + - path: ./infra/azure.bicep + parameters: ./infra/azure.parameters.json + deploymentName: Create-resources-for-bot + bicepCliVersion: v0.9.1 # Teams Toolkit will download this bicep CLI version from github for you, will use bicep CLI in PATH if you remove this config. + + # Validate using manifest schema + - uses: teamsApp/validateManifest + with: + # Path to manifest template + manifestPath: ./AppManifest/manifest.json + + # Build Teams app package with latest env value + - uses: teamsApp/zipAppPackage + with: + # Path to manifest template + manifestPath: ./AppManifest/manifest.json + outputZipPath: ./AppManifest/build/AppManifest.${{TEAMSFX_ENV}}.zip + outputJsonPath: ./AppManifest/build/manifest.${{TEAMSFX_ENV}}.json + # Validate app package using validation rules + - uses: teamsApp/validateAppPackage + with: + # Relative path to this file. This is the path for built zip file. + appPackagePath: ./AppManifest/build/AppManifest.${{TEAMSFX_ENV}}.zip + + # Apply the Teams app manifest to an existing Teams app in + # Teams Developer Portal. + # Will use the app id in manifest file to determine which Teams app to update. + - uses: teamsApp/update + with: + # Relative path to this file. This is the path for built zip file. + appPackagePath: ./AppManifest/build/AppManifest.${{TEAMSFX_ENV}}.zip + + # Create or update debug profile in lauchsettings file + - uses: file/createOrUpdateJsonFile + with: + target: ./Properties/launchSettings.json + content: + profiles: + Microsoft Teams (browser): + commandName: "Project" + dotnetRunMessages: true + launchBrowser: true + launchUrl: "https://teams.microsoft.com/l/app/${{TEAMS_APP_ID}}?installAppPackage=true&webjoin=true&appTenantId=${{TEAMS_APP_TENANT_ID}}&login_hint=${{TEAMSFX_M365_USER_NAME}}" + applicationUrl: "http://localhost:5130" + environmentVariables: + ASPNETCORE_ENVIRONMENT: "Development" + hotReloadProfile: "aspnetcore" \ No newline at end of file diff --git a/samples/bot-formatting-cards/csharp/BotFormattingCards/teamsapp.yml b/samples/bot-formatting-cards/csharp/BotFormattingCards/teamsapp.yml new file mode 100644 index 0000000000..92aa2c6bf0 --- /dev/null +++ b/samples/bot-formatting-cards/csharp/BotFormattingCards/teamsapp.yml @@ -0,0 +1,9 @@ +# yaml-language-server: $schema=https://aka.ms/teams-toolkit/v1.2/yaml.schema.json +# Visit https://aka.ms/teamsfx-v5.0-guide for details on this file +# Visit https://aka.ms/teamsfx-actions for details on actions +version: v1.2 + +additionalMetadata: + sampleTag: Microsoft-Teams-Samples:bot-formatting-cards-csharp + +environmentFolderPath: ./env \ No newline at end of file diff --git a/samples/bot-formatting-cards/csharp/README.md b/samples/bot-formatting-cards/csharp/README.md index 5c50456b09..7704b364ba 100644 --- a/samples/bot-formatting-cards/csharp/README.md +++ b/samples/bot-formatting-cards/csharp/README.md @@ -41,6 +41,19 @@ Please find below demo manifest which is deployed on Microsoft Azure and you can dotnet --version ``` - Publicly addressable https url or tunnel such as [dev tunnel](https://learn.microsoft.com/en-us/azure/developer/dev-tunnels/get-started?tabs=windows) or [ngrok](https://ngrok.com/) latest version or [Tunnel Relay](https://github.com/OfficeDev/microsoft-teams-tunnelrelay) +- [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.9 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 Visual Studio, right-click your 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. ## Setup