diff --git a/samples/app-localization/python/.env b/samples/app-localization/python/.env new file mode 100644 index 0000000000..660828e3e8 --- /dev/null +++ b/samples/app-localization/python/.env @@ -0,0 +1,2 @@ +MicrosoftAppId= +MicrosoftAppPassword= \ No newline at end of file diff --git a/samples/app-localization/python/.gitignore b/samples/app-localization/python/.gitignore new file mode 100644 index 0000000000..e8442994dd --- /dev/null +++ b/samples/app-localization/python/.gitignore @@ -0,0 +1,14 @@ +# TeamsFx files +env/.env.*.user +env/.env.local +appManifest/build/ + +# python virtual environment +.venv/ + +# misc +.env +.deployment/ + +# tmp files +__pycache__/ \ No newline at end of file diff --git a/samples/app-localization/python/.vscode/extensions.json b/samples/app-localization/python/.vscode/extensions.json new file mode 100644 index 0000000000..bf8c33db9c --- /dev/null +++ b/samples/app-localization/python/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "TeamsDevApp.ms-teams-vscode-extension", + "ms-python.python", + ] +} \ No newline at end of file diff --git a/samples/app-localization/python/.vscode/launch.json b/samples/app-localization/python/.vscode/launch.json new file mode 100644 index 0000000000..6d66d8beb8 --- /dev/null +++ b/samples/app-localization/python/.vscode/launch.json @@ -0,0 +1,69 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Launch App (Edge)", + "type": "msedge", + "request": "launch", + "url": "https://teams.microsoft.com/l/app/${{local:TEAMS_APP_ID}}?installAppPackage=true&webjoin=true&${account-hint}", + "cascadeTerminateToConfigurations": [ + "Python: Run App Locally" + ], + "presentation": { + "group": "all", + "hidden": true + }, + "internalConsoleOptions": "neverOpen" + }, + { + "name": "Launch App (Chrome)", + "type": "chrome", + "request": "launch", + "url": "https://teams.microsoft.com/l/app/${{local:TEAMS_APP_ID}}?installAppPackage=true&webjoin=true&${account-hint}", + "cascadeTerminateToConfigurations": [ + "Python: Run App Locally" + ], + "presentation": { + "group": "all", + "hidden": true + }, + "internalConsoleOptions": "neverOpen" + }, + { + "name": "Python: Run App Locally", + "type": "debugpy", + "request": "launch", + "program": "${workspaceFolder}/app.py", + "cwd": "${workspaceFolder}", + "console": "integratedTerminal" + } + ], + "compounds": [ + { + "name": "Debug (Edge)", + "configurations": [ + "Launch App (Edge)", + "Python: Run App Locally" + ], + "preLaunchTask": "Prepare Teams App Resources", + "presentation": { + "group": "all", + "order": 1 + }, + "stopAll": true + }, + { + "name": "Debug (Chrome)", + "configurations": [ + "Launch App (Chrome)", + "Python: Run App Locally" + ], + "preLaunchTask": "Prepare Teams App Resources", + "presentation": { + "group": "all", + "order": 2 + }, + "stopAll": true + } + ] +} \ No newline at end of file diff --git a/samples/app-localization/python/.vscode/settings.json b/samples/app-localization/python/.vscode/settings.json new file mode 100644 index 0000000000..3014fd9cf0 --- /dev/null +++ b/samples/app-localization/python/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "debug.onTaskErrors": "abort" +} diff --git a/samples/app-localization/python/.vscode/tasks.json b/samples/app-localization/python/.vscode/tasks.json new file mode 100644 index 0000000000..2161094dcc --- /dev/null +++ b/samples/app-localization/python/.vscode/tasks.json @@ -0,0 +1,78 @@ +// This file is automatically generated by Teams Toolkit. +// The teamsfx tasks defined in this file require Teams Toolkit version >= 5.0.0. +// See https://aka.ms/teamsfx-tasks for details on how to customize each task. +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Prepare Teams App Resources", + "dependsOn": [ + "Validate prerequisites", + "Start local tunnel", + "Provision", + "Deploy" + ], + "dependsOrder": "sequence" + }, + { + // Check all required prerequisites. + // See https://aka.ms/teamsfx-tasks/check-prerequisites to know the details and how to customize the args. + "label": "Validate prerequisites", + "type": "teamsfx", + "command": "debug-check-prerequisites", + "args": { + "prerequisites": [ + "m365Account", // Sign-in prompt for Microsoft 365 account, then validate if the account enables the sideloading permission. + "portOccupancy" // Validate available ports to ensure those debug ones are not occupied. + ], + "portOccupancy": [ + 3978, // app service port + ] + } + }, + { + // Start the local tunnel service to forward public URL to local port and inspect traffic. + // See https://aka.ms/teamsfx-tasks/local-tunnel for the detailed args definitions. + "label": "Start local tunnel", + "type": "teamsfx", + "command": "debug-start-local-tunnel", + "args": { + "type": "dev-tunnel", + "ports": [ + { + "portNumber": 3978, + "protocol": "http", + "access": "public", + "writeToEnvironmentFile": { + "endpoint": "BOT_ENDPOINT", // output tunnel endpoint as BOT_ENDPOINT + "domain": "BOT_DOMAIN" // output tunnel domain as BOT_DOMAIN + } + } + ], + "env": "local" + }, + "isBackground": true, + "problemMatcher": "$teamsfx-local-tunnel-watch" + }, + { + // Create the debug resources. + // See https://aka.ms/teamsfx-tasks/provision to know the details and how to customize the args. + "label": "Provision", + "type": "teamsfx", + "command": "provision", + "args": { + "env": "local" + } + }, + { + // Build project. + // See https://aka.ms/teamsfx-tasks/deploy to know the details and how to customize the args. + "label": "Deploy", + "type": "teamsfx", + "command": "deploy", + "args": { + "env": "local" + } + } + ] +} \ No newline at end of file diff --git a/samples/app-localization/python/Images/AppOffice.png b/samples/app-localization/python/Images/AppOffice.png new file mode 100644 index 0000000000..6b0a3c46be Binary files /dev/null and b/samples/app-localization/python/Images/AppOffice.png differ diff --git a/samples/app-localization/python/Images/AppOutlook.png b/samples/app-localization/python/Images/AppOutlook.png new file mode 100644 index 0000000000..cf24d96b11 Binary files /dev/null and b/samples/app-localization/python/Images/AppOutlook.png differ diff --git a/samples/app-localization/python/Images/InstallOffice.png b/samples/app-localization/python/Images/InstallOffice.png new file mode 100644 index 0000000000..616c0ed5b0 Binary files /dev/null and b/samples/app-localization/python/Images/InstallOffice.png differ diff --git a/samples/app-localization/python/Images/InstallOutlook.png b/samples/app-localization/python/Images/InstallOutlook.png new file mode 100644 index 0000000000..ac937651ac Binary files /dev/null and b/samples/app-localization/python/Images/InstallOutlook.png differ diff --git a/samples/app-localization/python/Images/Reply.png b/samples/app-localization/python/Images/Reply.png new file mode 100644 index 0000000000..805bfb6253 Binary files /dev/null and b/samples/app-localization/python/Images/Reply.png differ diff --git a/samples/app-localization/python/Images/Upload.png b/samples/app-localization/python/Images/Upload.png new file mode 100644 index 0000000000..0fec2db1ab Binary files /dev/null and b/samples/app-localization/python/Images/Upload.png differ diff --git a/samples/app-localization/python/Images/appLocalizationModule.gif b/samples/app-localization/python/Images/appLocalizationModule.gif new file mode 100644 index 0000000000..f343b93126 Binary files /dev/null and b/samples/app-localization/python/Images/appLocalizationModule.gif differ diff --git a/samples/app-localization/python/README.md b/samples/app-localization/python/README.md new file mode 100644 index 0000000000..19987087cf --- /dev/null +++ b/samples/app-localization/python/README.md @@ -0,0 +1,159 @@ +--- +page_type: sample +description: This sample demonstrates how to implement localization for a Microsoft Teams app using Bot and Tab functionalities. +products: +- office-teams +- office +- office-365 +languages: +- python +extensions: + contentType: samples + createdDate: "16/01/2025 01:38:25 PM" +urlFragment: officedev-microsoft-teams-samples-app-localization-python +--- + +# Microsoft Teams localization sample app. + +The Teams App Localization sample demonstrates how to implement multilingual support using Bot and Tab capabilities in Microsoft Teams. This app allows users to interact in different languages, making it easy to customize content for a diverse audience. + +This sample illustrates how to implement [Localization for Microsoft Teams apps](https://docs.microsoft.com/microsoftteams/platform/concepts/build-and-test/apps-localization). + +## Included Features +* Tabs +* Bots +* Localization + +## Interaction with app + +![image](Images/appLocalizationModule.gif) + +## Try it yourself - experience the App in your Microsoft Teams client +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](https://docs.microsoft.com/microsoftteams/platform/concepts/build-and-test/prepare-your-o365-tenant#enable-custom-teams-apps-and-turn-on-custom-app-uploading)). + +**App Localization:** [Manifest](/samples/app-localization/csharp/demo-manifest/app-localization.zip) + +## Prerequisites + +- Microsoft Teams is installed and you have an account +- [Python SDK](https://www.python.org/downloads/) min version 3.8 +- [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/microsoftteams/platform/concepts/build-and-test/prepare-your-o365-tenant) or access to a Teams account with the appropriate permissions to install an app. +- [Teams Toolkit for VS Code](https://marketplace.visualstudio.com/items?itemName=TeamsDevApp.ms-teams-vscode-extension) or [TeamsFx CLI](https://learn.microsoft.com/microsoftteams/platform/toolkit/teamsfx-cli?pivots=version-one) + +## Run the app (Using Teams Toolkit for Visual Studio Code) + +The simplest way to run this sample in Teams is to use Teams Toolkit for Visual Studio Code. + +1. Ensure you have downloaded and installed [Visual Studio Code](https://code.visualstudio.com/docs/setup/setup-overview) +1. Install the [Teams Toolkit extension](https://marketplace.visualstudio.com/items?itemName=TeamsDevApp.ms-teams-vscode-extension) and [Python Extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python) +1. Select **File > Open Folder** in VS Code and choose this samples directory from the repo +1. Press **CTRL+Shift+P** to open the command box and enter **Python: Create Environment** to create and activate your desired virtual environment. Remember to select `requirements.txt` as dependencies to install when creating the virtual environment. +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 app in a Teams web client. +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. + +## Run the app (Manually Uploading to Teams) + +> Note these instructions are for running the sample on your local machine, the tunnelling solution is required because +the Teams service needs to call into the bot. + +1) Clone the repository + + ```bash + git clone https://github.com/OfficeDev/Microsoft-Teams-Samples.git + ``` + +2) Run ngrok - point to port 3978 + + ```bash + ngrok http 3978 --host-header="localhost:3978" + ``` + + 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 + ``` + +3) Create [Azure Bot resource resource](https://docs.microsoft.com/azure/bot-service/bot-service-quickstart-registration) in Azure + - Use the current `https` URL you were given by running the tunneling application. Append with the path `/api/messages` used by this sample + - Ensure that you've [enabled the Teams Channel](https://docs.microsoft.com/azure/bot-service/channel-connect-teams?view=azure-bot-service-4.0) + - __*If you don't have an Azure account*__ you can use this [Azure free account here](https://azure.microsoft.com/free/) + +4) In a terminal, go to `samples\app-localization\python` + +5) Activate your desired virtual environment + +6) Install dependencies by running ```pip install -r requirements.txt``` in the project folder. + +7) Update the `config.py` 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.) + +8) Run your app with `python app.py` + +### 4. Setup Manifest for Teams + + - **This step is specific to Teams.** + + - **Edit** the `manifest.json` contained in the `app-localization/python/appManifest` folder to replace your Microsoft App Id (that was created when you registered your bot earlier) *everywhere* you see the place holder string `<>` (depending on the scenario the Microsoft App Id may occur multiple times in the `manifest.json`) + - **Edit** the `manifest.json` for `configurationUrl` inside `configurableTabs` and `validDomains`. Replace `{{domain-name}}` 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`. + + **Note:** If you want to test your app across multi hub like: Outlook/Office.com, please update the `manifest.json` in the `app-localization/python/appManifest_Hub` folder with the required values. + + - **Zip** up the contents of the `app-localization/python/appManifest` folder to create a `manifest.zip`(Make sure that zip file does not contains any subfolder otherwise you will get error while uploading your .zip package) + - **Upload** the `manifest.zip` to Teams (In Teams Apps/Manage your apps click "Upload an app". Browse to and Open the .zip file. At the next dialog, click the Add button.) + - Add the app to personal/team/groupChat scope (Supported scopes) + +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. +## Running the sample + +1. **Installation**: You should see your app installation screen content in selected language. +![image](Images/Upload.png) + +2. **Bot**: send any message to see localized +[image](Images/Reply.png) + +## Outlook on the web + +- To view your app in Outlook on the web. + +- Go to [Outlook on the web](https://outlook.office.com/mail/)and sign in using your dev tenant account. + +**On the side bar, select More Apps. Your sideloaded app title appears among your installed apps** + +![InstallOutlook](Images/InstallOutlook.png) + +**Select your app icon to launch and preview your app running in Outlook on the web** + +![AppOutlook](Images/AppOutlook.png) + +**Note:** Similarly, you can test your application in the Outlook desktop app as well. + +## Office on the web + +- 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** + +![InstallOffice](Images/InstallOffice.png) + +**Select your app icon to launch your app in Office on the web** + +![AppOffice](Images/AppOffice.png) + +**Note:** Similarly, you can test your application in the Office 365 desktop app as well. + + +#### To Add more languages for localization in Teams through Code. + + Add Resource files for the respective languages, Check culture fallback behaviour and how to add other cultures refer [Globalization and localization Fundamentals](https://docs.microsoft.com/aspnet/core/fundamentals/localization?view=aspnetcore-5.0). + +## Further reading + +- [Localize your app](https://learn.microsoft.com/microsoftteams/platform/concepts/build-and-test/apps-localization) + + \ No newline at end of file diff --git a/samples/app-localization/python/app.py b/samples/app-localization/python/app.py new file mode 100644 index 0000000000..63218293e3 --- /dev/null +++ b/samples/app-localization/python/app.py @@ -0,0 +1,107 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +import sys +import traceback +import uuid +from datetime import datetime +from http import HTTPStatus +from aiohttp import web +from aiohttp.web import Request, Response, json_response +from botbuilder.core import ( + BotFrameworkAdapterSettings, + TurnContext, + BotFrameworkAdapter, +) +from botbuilder.core.integration import aiohttp_error_middleware +from botbuilder.schema import Activity, ActivityTypes +from jinja2 import Environment, FileSystemLoader +from bots import BotActivityHandler +from config import DefaultConfig +from services.language_service import get_translated_res + +CONFIG = DefaultConfig() + +# Localization setup +LOCALES_DIR = "./translations" +DEFAULT_LOCALE = "en-us" +env = Environment(loader=FileSystemLoader("templates")) + +def get_translation(locale): + """Fetch the translation file for the given locale.""" + try: + with open(f"{LOCALES_DIR}/{locale}/common.json", "r") as file: + import json + return json.load(file) + except FileNotFoundError: + with open(f"{LOCALES_DIR}/{DEFAULT_LOCALE}/common.json", "r") as file: + import json + return json.load(file) + +# Create adapter. +SETTINGS = BotFrameworkAdapterSettings(CONFIG.APP_ID, CONFIG.APP_PASSWORD) +ADAPTER = BotFrameworkAdapter(SETTINGS) + +# Catch-all for errors. +async def on_error(context: TurnContext, error: Exception): + print(f"\n [on_turn_error] unhandled error: {error}", file=sys.stderr) + traceback.print_exc() + + # Send a message to the user + await context.send_activity("The bot encountered an error or bug.") + await context.send_activity( + "To continue to run this bot, please fix the bot source code." + ) + + if context.activity.channel_id == "emulator": + trace_activity = Activity( + label="TurnError", + name="on_turn_error Trace", + timestamp=datetime.utcnow(), + type=ActivityTypes.trace, + value=f"{error}", + value_type="https://www.botframework.com/schemas/error", + ) + await context.send_activity(trace_activity) + +ADAPTER.on_turn_error = on_error + +APP_ID = SETTINGS.app_id if SETTINGS.app_id else uuid.uuid4() +BOT = BotActivityHandler() + +# Main bot message handler. +async def messages(req: Request) -> Response: + if "application/json" in req.headers["Content-Type"]: + body = await req.json() + else: + return Response(status=HTTPStatus.UNSUPPORTED_MEDIA_TYPE) + + activity = Activity().deserialize(body) + auth_header = req.headers["Authorization"] if "Authorization" in req.headers else "" + + response = await ADAPTER.process_activity(activity, auth_header, BOT.on_turn) + if response: + return json_response(data=response.body, status=response.status) + return Response(status=HTTPStatus.OK) + +# Static tab route +async def static_tab(req: Request) -> Response: + # Extract culture parameter from query string + locale = req.query.get("culture", DEFAULT_LOCALE) + translations = get_translated_res(locale) + + # Render HTML with translations + template = env.get_template("static_tab.html") + content = template.render(translations=translations) + return Response(text=content, content_type="text/html") + +# Set up routes +APP = web.Application(middlewares=[aiohttp_error_middleware]) +APP.router.add_post("/api/messages", messages) +APP.router.add_get("/", static_tab) + +if __name__ == "__main__": + try: + web.run_app(APP, host="localhost", port=CONFIG.PORT) + except Exception as error: + raise error \ No newline at end of file diff --git a/samples/app-localization/python/appManifest/color.png b/samples/app-localization/python/appManifest/color.png new file mode 100644 index 0000000000..b8cf81afbe Binary files /dev/null and b/samples/app-localization/python/appManifest/color.png differ diff --git a/samples/app-localization/python/appManifest/es-mx.json b/samples/app-localization/python/appManifest/es-mx.json new file mode 100644 index 0000000000..17d4742242 --- /dev/null +++ b/samples/app-localization/python/appManifest/es-mx.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://developer.microsoft.com/en-us/json-schemas/teams/v1.16/MicrosoftTeams.Localization.schema.json", + "name.short": "Localización", + "name.full": "Aplicación de localización", + "description.short": "Aplicación de localización para Microsoft Teams", + "description.full": "Esta aplicación de muestra proporciona una aplicación de localización muy sencilla. Puede ampliar esto para agregar más contenido y capacidades.", + "staticTabs[0].name": "Spanish" +} \ No newline at end of file diff --git a/samples/app-localization/python/appManifest/hi-in.json b/samples/app-localization/python/appManifest/hi-in.json new file mode 100644 index 0000000000..5b1894ba42 --- /dev/null +++ b/samples/app-localization/python/appManifest/hi-in.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://developer.microsoft.com/en-us/json-schemas/teams/v1.16/MicrosoftTeams.Localization.schema.json", + "name.short": "स्थानीयकरण", + "name.full": "स्थानीयकरण अनुप्रयोग", + "description.short": "माइक्रोसॉफ्ट टीमों के लिए स्थानीयकरण ऐप", + "description.full": "यह नमूना ऐप एक बहुत ही सरल स्थानीयकरण ऐप प्रदान करता है। अधिक सामग्री और क्षमताओं को जोड़ने के लिए आप इसे बढ़ा सकते हैं।", + "staticTabs[0].name": "हिंदी" +} \ No newline at end of file diff --git a/samples/app-localization/python/appManifest/manifest.json b/samples/app-localization/python/appManifest/manifest.json new file mode 100644 index 0000000000..a71e645ef9 --- /dev/null +++ b/samples/app-localization/python/appManifest/manifest.json @@ -0,0 +1,79 @@ +{ + "$schema": "https://developer.microsoft.com/json-schemas/teams/v1.19/MicrosoftTeams.schema.json", + "manifestVersion": "1.19", + "version": "1.0.1", + "id": "${{TEAMS_APP_ID}}", + "localizationInfo": { + "defaultLanguageTag": "en-us", + "additionalLanguages": [ + { + "languageTag": "hi-in", + "file": "hi-in.json" + }, + { + "languageTag": "es-mx", + "file": "es-mx.json" + } + ] + }, + "developer": { + "name": "Contoso", + "websiteUrl": "https://www.microsoft.com", + "privacyUrl": "https://www.microsoft.com/privacy", + "termsOfUseUrl": "https://www.microsoft.com/termsofuse" + }, + "name": { + "short": "Localization", + "full": "Localization App" + }, + "description": { + "short": "Microsoft Teams sample app showcasing localization with Bot and Tab features.", + "full": "This sample demonstrates how to implement localization for a Microsoft Teams app using Bot and Tab functionalities." + }, + "icons": { + "outline": "outline.png", + "color": "color.png" + }, + "accentColor": "#60A18E", + "staticTabs": [ + { + "entityId": "com.contoso.localization", + "name": "English", + "contentUrl": "https://${{BOT_DOMAIN}}?culture={locale}", + "scopes": [ + "personal" + ] + }, + { + "entityId": "conversations", + "scopes": [ + "personal" + ] + }, + { + "entityId": "about", + "scopes": [ + "personal" + ] + } + ], + "bots": [ + { + "botId": "${{AAD_APP_CLIENT_ID}}", + "scopes": [ + "personal", + "team" + ], + "supportsFiles": false, + "isNotificationOnly": false + } + ], + "permissions": [ + "identity", + "messageTeamMembers" + ], + "validDomains": [ + "*.ngrok-free.app", + "${{BOT_DOMAIN}}" + ] +} \ No newline at end of file diff --git a/samples/app-localization/python/appManifest/outline.png b/samples/app-localization/python/appManifest/outline.png new file mode 100644 index 0000000000..2c3bf6fa65 Binary files /dev/null and b/samples/app-localization/python/appManifest/outline.png differ diff --git a/samples/app-localization/python/assets/sample.json b/samples/app-localization/python/assets/sample.json new file mode 100644 index 0000000000..13710b18c7 --- /dev/null +++ b/samples/app-localization/python/assets/sample.json @@ -0,0 +1,68 @@ +[ + { + "name": "officedev-microsoft-teams-samples-app-localization-nodejs", + "source": "officeDev", + "title": "Teams App Localization", + "shortDescription": "This sample demonstrates how to implement localization for a Microsoft Teams app using Bot and Tab functionalities.", + "url": "https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/app-localization/python", + "longDescription": [ + "This Microsoft Teams sample app illustrates how to implement localization using Bot and Tab features. It supports multi-language configurations, allowing seamless app interactions in multiple languages." + ], + "creationDateTime": "2025-01-16", + "updateDateTime": "2025-01-16", + "products": [ + "Teams" + ], + "metadata": [ + { + "key": "TEAMS-SAMPLE-SOURCE", + "value": "OfficeDev" + }, + { + "key": "TEAMS-SERVER-LANGUAGE", + "value": "python" + }, + { + "key": "TEAMS-SERVER-PLATFORM", + "value": "express" + }, + { + "key": "TEAMS-FEATURES", + "value": "tab,bot,msgext" + } + ], + "thumbnails": [ + { + "type": "image", + "order": 100, + "url": "https://raw.githubusercontent.com/OfficeDev/Microsoft-Teams-Samples/main/samples/app-localization/python/Images/appLocalizationModule.gif", + "alt": "Solution UX showing teams app localization" + } + ], + "authors": [ + { + "gitHubAccount": "OfficeDev", + "pictureUrl": "https://avatars.githubusercontent.com/u/6789362?s=200&v=4", + "name": "OfficeDev" + } + ], + "references": [ + { + "name": "Teams developer documentation", + "url": "https://aka.ms/TeamsPlatformDocs" + }, + { + "name": "Teams developer questions", + "url": "https://aka.ms/TeamsPlatformFeedback" + }, + { + "name": "Teams development videos from Microsoft", + "url": "https://aka.ms/sample-ref-teams-vids-from-microsoft" + }, + { + "name": "Teams development videos from the community", + "url": "https://aka.ms/community/videos/m365powerplatform" + } + ] + } +] \ No newline at end of file diff --git a/samples/app-localization/python/bots/__init__.py b/samples/app-localization/python/bots/__init__.py new file mode 100644 index 0000000000..3b16551a15 --- /dev/null +++ b/samples/app-localization/python/bots/__init__.py @@ -0,0 +1,3 @@ +from .bot import BotActivityHandler + +__all__ = ["BotActivityHandler"] \ No newline at end of file diff --git a/samples/app-localization/python/bots/bot.py b/samples/app-localization/python/bots/bot.py new file mode 100644 index 0000000000..4bfa93246d --- /dev/null +++ b/samples/app-localization/python/bots/bot.py @@ -0,0 +1,30 @@ +from botbuilder.core import TurnContext, MessageFactory +from botbuilder.core.teams import TeamsActivityHandler +from services.language_service import get_translated_res + +class BotActivityHandler(TeamsActivityHandler): + def __init__(self): + super().__init__() + # Teams bots are Microsoft Bot Framework bots. + # If a bot receives a message activity, the turn handler sees that incoming activity + # and sends it to the on_message_activity handler. + # Learn more: https://aka.ms/teams-bot-basics + + # Registers an activity event handler for the message event, emitted for every incoming message activity. + + async def on_message_activity(self, turn_context: TurnContext): + # Removes recipient mention from the activity text + TurnContext.remove_recipient_mention(turn_context.activity) + + # Get the locale from the incoming activity + locale = turn_context.activity.locale + + # Get the translated response based on the locale + text = get_translated_res(locale).get("welcome", "Welcome") + + # Reply with the translated text + await self.reply_activity_async(turn_context, text) + + async def reply_activity_async(self, turn_context: TurnContext, text: str): + reply_activity = MessageFactory.text(text) + await turn_context.send_activity(reply_activity) diff --git a/samples/app-localization/python/config.py b/samples/app-localization/python/config.py new file mode 100644 index 0000000000..c682ef8547 --- /dev/null +++ b/samples/app-localization/python/config.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +import os + +""" Bot Configuration """ + + +class DefaultConfig: + """ Bot Configuration """ + + PORT = 3978 + APP_ID = os.environ.get("MicrosoftAppId", "<>") + APP_PASSWORD = os.environ.get("MicrosoftAppPassword", "<>") diff --git a/samples/app-localization/python/env/.env.local b/samples/app-localization/python/env/.env.local new file mode 100644 index 0000000000..22987ef6bb --- /dev/null +++ b/samples/app-localization/python/env/.env.local @@ -0,0 +1,21 @@ +# 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 + +# Generated during provision, you can also add your own variables. If you're adding a secret value, add SECRET_ prefix to the name so Teams Toolkit can handle them properly +BOT_ENDPOINT= +BOT_DOMAIN= +AAD_APP_CLIENT_ID= +AAD_APP_OBJECT_ID= +AAD_APP_TENANT_ID= +AAD_APP_OAUTH_AUTHORITY= +AAD_APP_OAUTH_AUTHORITY_HOST= +TEAMS_APP_ID= +TEAMS_APP_TENANT_ID= +MICROSOFT_APP_TYPE= +MICROSOFT_APP_TENANT_ID= +RESOURCE_SUFFIX= +AZURE_SUBSCRIPTION_ID= +AZURE_RESOURCE_GROUP_NAME= +APP_NAME_SUFFIX= \ No newline at end of file diff --git a/samples/app-localization/python/infra/azure.bicep b/samples/app-localization/python/infra/azure.bicep new file mode 100644 index 0000000000..8734cb547b --- /dev/null +++ b/samples/app-localization/python/infra/azure.bicep @@ -0,0 +1,42 @@ +@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' + +// 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: 'MultiTenant' + msaAppTenantId: '' + } + 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/app-localization/python/infra/azure.parameters.json b/samples/app-localization/python/infra/azure.parameters.json new file mode 100644 index 0000000000..1368fe8cc1 --- /dev/null +++ b/samples/app-localization/python/infra/azure.parameters.json @@ -0,0 +1,18 @@ +{ + "$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": "localization" + } + } + } \ No newline at end of file diff --git a/samples/app-localization/python/requirements.txt b/samples/app-localization/python/requirements.txt new file mode 100644 index 0000000000..c6424216e6 --- /dev/null +++ b/samples/app-localization/python/requirements.txt @@ -0,0 +1,2 @@ +requests==2.31.0 +botbuilder-integration-aiohttp>=4.14.5 diff --git a/samples/app-localization/python/services/language_service.py b/samples/app-localization/python/services/language_service.py new file mode 100644 index 0000000000..8c6ab26945 --- /dev/null +++ b/samples/app-localization/python/services/language_service.py @@ -0,0 +1,18 @@ +import os +import json + +def get_translated_res(language_code: str): + """ + Returns a response in the selected Teams language. + If the language file is not found, it defaults to English (en-us). + """ + try: + # Construct the path to the translation file based on the language code + file_path = os.path.join(os.path.dirname(__file__), f"../translations/{language_code}/common.json") + with open(file_path, "r", encoding="utf-8") as file: + return json.load(file) + except (FileNotFoundError, json.JSONDecodeError): + # Default to English if the specified language file doesn't exist + default_path = os.path.join(os.path.dirname(__file__), "../translations/en-us/common.json") + with open(default_path, "r", encoding="utf-8") as file: + return json.load(file) \ No newline at end of file diff --git a/samples/app-localization/python/teamsapp.local.yml b/samples/app-localization/python/teamsapp.local.yml new file mode 100644 index 0000000000..15a2ec8a19 --- /dev/null +++ b/samples/app-localization/python/teamsapp.local.yml @@ -0,0 +1,78 @@ +# 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:app-localization-python + +provision: + # Creates a new Azure Active Directory (AAD) app to authenticate users if the environment variable that stores clientId is empty + - uses: aadApp/create + with: + name: app-localization-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: app-localization${{APP_NAME_SUFFIX}} + # Write the information of created resources into environment file for + # the specified environment variable(s). + writeToEnvironmentFile: + teamsAppId: TEAMS_APP_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 + +deploy: + # Generate runtime environment variables + - uses: file/createOrUpdateEnvironmentFile + with: + target: ./.env + envs: + MicrosoftAppId: ${{AAD_APP_CLIENT_ID}} + MicrosoftAppPassword: ${{SECRET_AAD_APP_CLIENT_SECRET}} \ No newline at end of file diff --git a/samples/app-localization/python/teamsapp.yml b/samples/app-localization/python/teamsapp.yml new file mode 100644 index 0000000000..bf582d311b --- /dev/null +++ b/samples/app-localization/python/teamsapp.yml @@ -0,0 +1,8 @@ +# 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:app-localization-python +environmentFolderPath: ./env diff --git a/samples/app-localization/python/templates/static_tab.html b/samples/app-localization/python/templates/static_tab.html new file mode 100644 index 0000000000..a51b7eefe6 --- /dev/null +++ b/samples/app-localization/python/templates/static_tab.html @@ -0,0 +1,13 @@ + + + + + + Static Tab + + +
+

{{ translations["welcome.title"] }}

+
+ + \ No newline at end of file diff --git a/samples/app-localization/python/translations/en-us/common.json b/samples/app-localization/python/translations/en-us/common.json new file mode 100644 index 0000000000..f372eb886b --- /dev/null +++ b/samples/app-localization/python/translations/en-us/common.json @@ -0,0 +1,4 @@ +{ + "welcome": "Hello", + "welcome.title": "Hello World" +} \ No newline at end of file diff --git a/samples/app-localization/python/translations/es-mx/common.json b/samples/app-localization/python/translations/es-mx/common.json new file mode 100644 index 0000000000..bb9c6cbb76 --- /dev/null +++ b/samples/app-localization/python/translations/es-mx/common.json @@ -0,0 +1,4 @@ +{ + "welcome": "Hola", + "welcome.title": "Hola Mundo" +} \ No newline at end of file diff --git a/samples/app-localization/python/translations/hi-in/common.json b/samples/app-localization/python/translations/hi-in/common.json new file mode 100644 index 0000000000..565003e396 --- /dev/null +++ b/samples/app-localization/python/translations/hi-in/common.json @@ -0,0 +1,4 @@ +{ + "welcome": "नमस्ते", + "welcome.title": "नमस्ते दुनिया" +} \ No newline at end of file diff --git a/samples/msgext-action-quickstart/python/.env b/samples/msgext-action-quickstart/python/.env new file mode 100644 index 0000000000..660828e3e8 --- /dev/null +++ b/samples/msgext-action-quickstart/python/.env @@ -0,0 +1,2 @@ +MicrosoftAppId= +MicrosoftAppPassword= \ No newline at end of file diff --git a/samples/msgext-action-quickstart/python/.gitignore b/samples/msgext-action-quickstart/python/.gitignore new file mode 100644 index 0000000000..e8442994dd --- /dev/null +++ b/samples/msgext-action-quickstart/python/.gitignore @@ -0,0 +1,14 @@ +# TeamsFx files +env/.env.*.user +env/.env.local +appManifest/build/ + +# python virtual environment +.venv/ + +# misc +.env +.deployment/ + +# tmp files +__pycache__/ \ No newline at end of file diff --git a/samples/msgext-action-quickstart/python/.vscode/extensions.json b/samples/msgext-action-quickstart/python/.vscode/extensions.json new file mode 100644 index 0000000000..bf8c33db9c --- /dev/null +++ b/samples/msgext-action-quickstart/python/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "TeamsDevApp.ms-teams-vscode-extension", + "ms-python.python", + ] +} \ No newline at end of file diff --git a/samples/msgext-action-quickstart/python/.vscode/launch.json b/samples/msgext-action-quickstart/python/.vscode/launch.json new file mode 100644 index 0000000000..6d66d8beb8 --- /dev/null +++ b/samples/msgext-action-quickstart/python/.vscode/launch.json @@ -0,0 +1,69 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Launch App (Edge)", + "type": "msedge", + "request": "launch", + "url": "https://teams.microsoft.com/l/app/${{local:TEAMS_APP_ID}}?installAppPackage=true&webjoin=true&${account-hint}", + "cascadeTerminateToConfigurations": [ + "Python: Run App Locally" + ], + "presentation": { + "group": "all", + "hidden": true + }, + "internalConsoleOptions": "neverOpen" + }, + { + "name": "Launch App (Chrome)", + "type": "chrome", + "request": "launch", + "url": "https://teams.microsoft.com/l/app/${{local:TEAMS_APP_ID}}?installAppPackage=true&webjoin=true&${account-hint}", + "cascadeTerminateToConfigurations": [ + "Python: Run App Locally" + ], + "presentation": { + "group": "all", + "hidden": true + }, + "internalConsoleOptions": "neverOpen" + }, + { + "name": "Python: Run App Locally", + "type": "debugpy", + "request": "launch", + "program": "${workspaceFolder}/app.py", + "cwd": "${workspaceFolder}", + "console": "integratedTerminal" + } + ], + "compounds": [ + { + "name": "Debug (Edge)", + "configurations": [ + "Launch App (Edge)", + "Python: Run App Locally" + ], + "preLaunchTask": "Prepare Teams App Resources", + "presentation": { + "group": "all", + "order": 1 + }, + "stopAll": true + }, + { + "name": "Debug (Chrome)", + "configurations": [ + "Launch App (Chrome)", + "Python: Run App Locally" + ], + "preLaunchTask": "Prepare Teams App Resources", + "presentation": { + "group": "all", + "order": 2 + }, + "stopAll": true + } + ] +} \ No newline at end of file diff --git a/samples/msgext-action-quickstart/python/.vscode/settings.json b/samples/msgext-action-quickstart/python/.vscode/settings.json new file mode 100644 index 0000000000..3014fd9cf0 --- /dev/null +++ b/samples/msgext-action-quickstart/python/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "debug.onTaskErrors": "abort" +} diff --git a/samples/msgext-action-quickstart/python/.vscode/tasks.json b/samples/msgext-action-quickstart/python/.vscode/tasks.json new file mode 100644 index 0000000000..2161094dcc --- /dev/null +++ b/samples/msgext-action-quickstart/python/.vscode/tasks.json @@ -0,0 +1,78 @@ +// This file is automatically generated by Teams Toolkit. +// The teamsfx tasks defined in this file require Teams Toolkit version >= 5.0.0. +// See https://aka.ms/teamsfx-tasks for details on how to customize each task. +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Prepare Teams App Resources", + "dependsOn": [ + "Validate prerequisites", + "Start local tunnel", + "Provision", + "Deploy" + ], + "dependsOrder": "sequence" + }, + { + // Check all required prerequisites. + // See https://aka.ms/teamsfx-tasks/check-prerequisites to know the details and how to customize the args. + "label": "Validate prerequisites", + "type": "teamsfx", + "command": "debug-check-prerequisites", + "args": { + "prerequisites": [ + "m365Account", // Sign-in prompt for Microsoft 365 account, then validate if the account enables the sideloading permission. + "portOccupancy" // Validate available ports to ensure those debug ones are not occupied. + ], + "portOccupancy": [ + 3978, // app service port + ] + } + }, + { + // Start the local tunnel service to forward public URL to local port and inspect traffic. + // See https://aka.ms/teamsfx-tasks/local-tunnel for the detailed args definitions. + "label": "Start local tunnel", + "type": "teamsfx", + "command": "debug-start-local-tunnel", + "args": { + "type": "dev-tunnel", + "ports": [ + { + "portNumber": 3978, + "protocol": "http", + "access": "public", + "writeToEnvironmentFile": { + "endpoint": "BOT_ENDPOINT", // output tunnel endpoint as BOT_ENDPOINT + "domain": "BOT_DOMAIN" // output tunnel domain as BOT_DOMAIN + } + } + ], + "env": "local" + }, + "isBackground": true, + "problemMatcher": "$teamsfx-local-tunnel-watch" + }, + { + // Create the debug resources. + // See https://aka.ms/teamsfx-tasks/provision to know the details and how to customize the args. + "label": "Provision", + "type": "teamsfx", + "command": "provision", + "args": { + "env": "local" + } + }, + { + // Build project. + // See https://aka.ms/teamsfx-tasks/deploy to know the details and how to customize the args. + "label": "Deploy", + "type": "teamsfx", + "command": "deploy", + "args": { + "env": "local" + } + } + ] +} \ No newline at end of file diff --git a/samples/msgext-action-quickstart/python/Images/1-AppInstallation.png b/samples/msgext-action-quickstart/python/Images/1-AppInstallation.png new file mode 100644 index 0000000000..bfccf19b26 Binary files /dev/null and b/samples/msgext-action-quickstart/python/Images/1-AppInstallation.png differ diff --git a/samples/msgext-action-quickstart/python/Images/2-InputCard.png b/samples/msgext-action-quickstart/python/Images/2-InputCard.png new file mode 100644 index 0000000000..d0eaac18af Binary files /dev/null and b/samples/msgext-action-quickstart/python/Images/2-InputCard.png differ diff --git a/samples/msgext-action-quickstart/python/Images/3-PreviewInComposeBox.png b/samples/msgext-action-quickstart/python/Images/3-PreviewInComposeBox.png new file mode 100644 index 0000000000..5b59188726 Binary files /dev/null and b/samples/msgext-action-quickstart/python/Images/3-PreviewInComposeBox.png differ diff --git a/samples/msgext-action-quickstart/python/Images/4-IncludeImageCard.png b/samples/msgext-action-quickstart/python/Images/4-IncludeImageCard.png new file mode 100644 index 0000000000..fbba5b573d Binary files /dev/null and b/samples/msgext-action-quickstart/python/Images/4-IncludeImageCard.png differ diff --git a/samples/msgext-action-quickstart/python/Images/5-ImageSent.png b/samples/msgext-action-quickstart/python/Images/5-ImageSent.png new file mode 100644 index 0000000000..374248a638 Binary files /dev/null and b/samples/msgext-action-quickstart/python/Images/5-ImageSent.png differ diff --git a/samples/msgext-action-quickstart/python/Images/msgextactionquickstartModule.gif b/samples/msgext-action-quickstart/python/Images/msgextactionquickstartModule.gif new file mode 100644 index 0000000000..ca59f0e358 Binary files /dev/null and b/samples/msgext-action-quickstart/python/Images/msgextactionquickstartModule.gif differ diff --git a/samples/msgext-action-quickstart/python/README.md b/samples/msgext-action-quickstart/python/README.md new file mode 100644 index 0000000000..fd948a5721 --- /dev/null +++ b/samples/msgext-action-quickstart/python/README.md @@ -0,0 +1,116 @@ +--- +page_type: sample +description: This sample app showcases a Hello World Messaging Extension that processes parameters and generates a card in Microsoft Teams. It also illustrates how to receive and handle forwarded messages, enhancing interaction through action commands and message extensions. +products: +- office-teams +- office +- office-365 +languages: +- python +extensions: + contentType: samples + createdDate: "31-12-2024 13:38:25" +urlFragment: officedev-microsoft-teams-samples-msgext-action-quickstart-python +--- + +# Bots/Messaging Extension + +Discover this Hello World Messaging Extension that demonstrates how to accept parameters and return interactive cards in Microsoft Teams. With features like action commands and message handling, this sample enables seamless integration with your web service, allowing users to initiate actions and interact directly within Teams. + +## Included Features +* Bots +* Message Extensions +* Action Commands + +## Interaction with app + +![message ext module](Images/msgextactionquickstartModule.gif) + +## Prerequisites + +- Microsoft Teams is installed and you have an account +- [Python SDK](https://www.python.org/downloads/) min version 3.6 +- [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 + + +## Run the app (Using Teams Toolkit for Visual Studio Code) + +The simplest way to run this sample in Teams is to use Teams Toolkit for Visual Studio Code. + +1. Ensure you have downloaded and installed [Visual Studio Code](https://code.visualstudio.com/docs/setup/setup-overview) +1. Install the [Teams Toolkit extension](https://marketplace.visualstudio.com/items?itemName=TeamsDevApp.ms-teams-vscode-extension) and [Python Extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python) +1. Select **File > Open Folder** in VS Code and choose this samples directory from the repo +1. Press **CTRL+Shift+P** to open the command box and enter **Python: Create Environment** to create and activate your desired virtual environment. Remember to select `requirements.txt` as dependencies to install when creating the virtual environment. +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 app in a Teams web client. +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. + +## Run the app (Manually Uploading to Teams) + +> Note these instructions are for running the sample on your local machine, the tunnelling solution is required because +the Teams service needs to call into the bot. + +1) Clone the repository + + ```bash + git clone https://github.com/OfficeDev/Microsoft-Teams-Samples.git + ``` + +2) Run ngrok - point to port 3978 + + ```bash + ngrok http 3978 --host-header="localhost:3978" + ``` + + 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 + ``` + +3) Create [Azure Bot resource resource](https://docs.microsoft.com/azure/bot-service/bot-service-quickstart-registration) in Azure + - Use the current `https` URL you were given by running the tunneling application. Append with the path `/api/messages` used by this sample + - Ensure that you've [enabled the Teams Channel](https://docs.microsoft.com/azure/bot-service/channel-connect-teams?view=azure-bot-service-4.0) + - __*If you don't have an Azure account*__ you can use this [Azure free account here](https://azure.microsoft.com/free/) + +4) In a terminal, go to `samples\msgext-action-quickstart` + +5) Activate your desired virtual environment + +6) Install dependencies by running ```pip install -r requirements.txt``` in the project folder. + +7) Update the `config.py` 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.) + +8) __*This step is specific to Teams.*__ + - **Edit** the `manifest.json` contained in the `appManifest` folder to replace your Microsoft App Id (that was created when you registered your bot earlier) *everywhere* you see the place holder string `${{AAD_APP_CLIENT_ID}}` and `${{TEAMS_APP_ID}}` (depending on the scenario the Microsoft App Id may occur multiple times in the `manifest.json`) + - **Zip** up the contents of the `appManifest` folder to create a `manifest.zip` + - **Upload** the `manifest.zip` to Teams (in the Apps view click "Upload a custom app") + +9) Run your bot with `python app.py` + +## Running the sample + +![Installation](Images/1-AppInstallation.png) + +![action command compose](Images/2-InputCard.png) + +![compose extension result](Images/3-PreviewInComposeBox.png) + +![action command from message](Images/4-IncludeImageCard.png) + +![compose result from message action](Images/5-ImageSent.png) + +## Deploy to Teams +Start debugging the project by hitting the `F5` key or click the debug icon in Visual Studio Code and click the `Start Debugging` green arrow button. + +## Further reading + +- [Messaging Extension](https://learn.microsoft.com/microsoftteams/platform/messaging-extensions/how-to/action-commands/define-action-command) +- [Bot Framework Documentation](https://docs.botframework.com) +- [Bot Basics](https://docs.microsoft.com/azure/bot-service/bot-builder-basics?view=azure-bot-service-4.0) +- [Azure Bot Service Introduction](https://docs.microsoft.com/azure/bot-service/bot-service-overview-introduction?view=azure-bot-service-4.0) +- [Azure Bot Service Documentation](https://docs.microsoft.com/azure/bot-service/?view=azure-bot-service-4.0) + + \ No newline at end of file diff --git a/samples/msgext-action-quickstart/python/app.py b/samples/msgext-action-quickstart/python/app.py new file mode 100644 index 0000000000..e7241d3772 --- /dev/null +++ b/samples/msgext-action-quickstart/python/app.py @@ -0,0 +1,76 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +import sys +import traceback +from http import HTTPStatus + +from aiohttp import web +from botbuilder.core import ( + BotFrameworkAdapterSettings, + TurnContext, + BotFrameworkAdapter, +) +from botbuilder.core.integration import aiohttp_error_middleware +from botbuilder.schema import Activity, ActivityTypes, InvokeResponse + +from bots import BotActivityHandler +from config import DefaultConfig + +CONFIG = DefaultConfig() + +# Create adapter. +SETTINGS = BotFrameworkAdapterSettings(CONFIG.APP_ID, CONFIG.APP_PASSWORD) +ADAPTER = BotFrameworkAdapter(SETTINGS) + + +# Catch-all for errors. +async def on_error(context: TurnContext, error: Exception): + print(f"\n [on_turn_error] unhandled error: {error}", file=sys.stderr) + traceback.print_exc() + + # Send a message to the user + try: + await context.send_activity("The bot encountered an error or bug.") + except Exception as send_error: + print(f"Failed to send error message: {send_error}", file=sys.stderr) + + # Log additional details + if context.activity: + print(f"Activity ID: {context.activity.id}") + print(f"Activity Type: {context.activity.type}") + print(f"Activity Text: {context.activity.text}") + + +ADAPTER.on_turn_error = on_error + +BOT = BotActivityHandler() + + +async def messages(request: web.Request) -> web.Response: + if "application/json" in request.headers["Content-Type"]: + body = await request.json() + else: + return web.Response(status=HTTPStatus.UNSUPPORTED_MEDIA_TYPE) + + activity = Activity().deserialize(body) + auth_header = request.headers.get("Authorization", "") + + try: + response = await ADAPTER.process_activity(activity, auth_header, BOT.on_turn) + if response: + return web.json_response(data=response.body, status=response.status) + return web.Response(status=HTTPStatus.OK) + except Exception as e: + print(f"Exception in messages: {e}", file=sys.stderr) + return web.Response(status=HTTPStatus.INTERNAL_SERVER_ERROR) + + +APP = web.Application(middlewares=[aiohttp_error_middleware]) +APP.router.add_post("/api/messages", messages) + +if __name__ == "__main__": + try: + web.run_app(APP, host="0.0.0.0", port=CONFIG.PORT) + except Exception as error: + print(f"Error starting app: {error}", file=sys.stderr) \ No newline at end of file diff --git a/samples/msgext-action-quickstart/python/appManifest/color.png b/samples/msgext-action-quickstart/python/appManifest/color.png new file mode 100644 index 0000000000..b8cf81afbe Binary files /dev/null and b/samples/msgext-action-quickstart/python/appManifest/color.png differ diff --git a/samples/msgext-action-quickstart/python/appManifest/manifest.json b/samples/msgext-action-quickstart/python/appManifest/manifest.json new file mode 100644 index 0000000000..527a97f1c1 --- /dev/null +++ b/samples/msgext-action-quickstart/python/appManifest/manifest.json @@ -0,0 +1,93 @@ +{ + "$schema": "https://developer.microsoft.com/json-schemas/teams/v1.19/MicrosoftTeams.schema.json", + "manifestVersion": "1.19", + "version": "1.0.0", + "id": "${{TEAMS_APP_ID}}", + "developer": { + "name": "Teams App, Inc.", + "websiteUrl": "https://localhost:3000", + "privacyUrl": "https://localhost:3000/privacy", + "termsOfUseUrl": "https://localhost:3000/termsofuse" + }, + "icons": { + "color": "color.png", + "outline": "outline.png" + }, + "name": { + "short": "Messaging Extension Action", + "full": "" + }, + "description": { + "short": "Hello World Messaging Extension that creates a card and accepts parameters.", + "full": "This sample app showcases a Hello World Messaging Extension that processes parameters and generates a card in Microsoft Teams. It also illustrates how to receive and handle forwarded messages, enhancing interaction through action commands and message extensions." + }, + "accentColor": "#FFFFFF", + "composeExtensions": [ + { + "botId": "${{AAD_APP_CLIENT_ID}}", + "canUpdateConfiguration": true, + "commands": [ + { + "id": "createCard", + "type": "action", + "title": "Create Card", + "description": "Command to run action to create a Card from Compose Box", + "initialRun": false, + "fetchTask": false, + "context": [ + "compose" + ], + "parameters": [ + { + "name": "title", + "title": "Card title", + "description": "Title for the card", + "inputType": "text" + }, + { + "name": "subTitle", + "title": "Subtitle", + "description": "Subtitle for the card", + "inputType": "text" + }, + { + "name": "text", + "title": "Text", + "description": "Text for the card", + "inputType": "textarea" + } + ] + }, + { + "id": "shareMessage", + "type": "action", + "title": "Share Message", + "description": "Test command to run action on message context (message sharing)", + "initialRun": false, + "fetchTask": false, + "context": [ + "message" + ], + "parameters": [ + { + "name": "includeImage", + "title": "Include Image", + "description": "Include image in Hero Card", + "inputType": "toggle" + } + ] + } + ] + } + ], + "permissions": [ + "identity", + "messageTeamMembers" + ], + "validDomains": [ + "token.botframework.com", + "{{domain-name}}", + "*.ngrok.io", + "${{BOT_DOMAIN}}" + ] +} \ No newline at end of file diff --git a/samples/msgext-action-quickstart/python/appManifest/outline.png b/samples/msgext-action-quickstart/python/appManifest/outline.png new file mode 100644 index 0000000000..2c3bf6fa65 Binary files /dev/null and b/samples/msgext-action-quickstart/python/appManifest/outline.png differ diff --git a/samples/msgext-action-quickstart/python/assets/sample.json b/samples/msgext-action-quickstart/python/assets/sample.json new file mode 100644 index 0000000000..b1cf43e115 --- /dev/null +++ b/samples/msgext-action-quickstart/python/assets/sample.json @@ -0,0 +1,68 @@ +[ + { + "name": "officedev-microsoft-teams-samples-msgext-action-quickstart-python", + "source": "officeDev", + "title": "Action messaging extension", + "shortDescription": "Hello World Messaging Extension that creates a card and accepts parameters.", + "url": "https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/msgext-action-quickstart/python", + "longDescription": [ + "This sample app showcases a Hello World Messaging Extension that processes parameters and generates a card in Microsoft Teams. It also illustrates how to receive and handle forwarded messages, enhancing interaction through action commands and message extensions." + ], + "creationDateTime": "2024-12-31", + "updateDateTime": "2024-12-31", + "products": [ + "Teams" + ], + "metadata": [ + { + "key": "TEAMS-SAMPLE-SOURCE", + "value": "OfficeDev" + }, + { + "key": "TEAMS-SERVER-LANGUAGE", + "value": "python" + }, + { + "key": "TEAMS-SERVER-PLATFORM", + "value": "python" + }, + { + "key": "TEAMS-FEATURES", + "value": "bot" + } + ], + "thumbnails": [ + { + "type": "image", + "order": 100, + "url": "https://raw.githubusercontent.com/OfficeDev/Microsoft-Teams-Samples/main/samples/msgext-action-quickstart/python/Images/msgextactionquickstartModule.gif", + "alt": "Solution UX showing action messaging extension" + } + ], + "authors": [ + { + "gitHubAccount": "OfficeDev", + "pictureUrl": "https://avatars.githubusercontent.com/u/6789362?s=200&v=4", + "name": "OfficeDev" + } + ], + "references": [ + { + "name": "Teams developer documentation", + "url": "https://aka.ms/TeamsPlatformDocs" + }, + { + "name": "Teams developer questions", + "url": "https://aka.ms/TeamsPlatformFeedback" + }, + { + "name": "Teams development videos from Microsoft", + "url": "https://aka.ms/sample-ref-teams-vids-from-microsoft" + }, + { + "name": "Teams development videos from the community", + "url": "https://aka.ms/community/videos/m365powerplatform" + } + ] + } +] \ No newline at end of file diff --git a/samples/msgext-action-quickstart/python/bots/__init__.py b/samples/msgext-action-quickstart/python/bots/__init__.py new file mode 100644 index 0000000000..c943fad04b --- /dev/null +++ b/samples/msgext-action-quickstart/python/bots/__init__.py @@ -0,0 +1,3 @@ +from .bot_configuration_auth import BotActivityHandler + +__all__ = ["BotActivityHandler"] \ No newline at end of file diff --git a/samples/msgext-action-quickstart/python/bots/bot_activity_handler.py b/samples/msgext-action-quickstart/python/bots/bot_activity_handler.py new file mode 100644 index 0000000000..9cc296fa98 --- /dev/null +++ b/samples/msgext-action-quickstart/python/bots/bot_activity_handler.py @@ -0,0 +1,120 @@ +from botbuilder.core import ActivityHandler, TurnContext, CardFactory +from botbuilder.schema import HeroCard, InvokeResponse +from botbuilder.schema._models_py3 import CardImage + + +class BotActivityHandler(ActivityHandler): + async def on_invoke_activity(self, turn_context: TurnContext): + """ + Handle invoke activities (e.g., messaging extension actions). + """ + activity = turn_context.activity + if activity.name == "composeExtension/submitAction": + action = activity.value + if action.get("commandId") == "createCard": + return await self.create_card_command(turn_context, action) + elif action.get("commandId") == "shareMessage": + return await self.share_message_command(turn_context, action) + else: + return self._create_invoke_response( + status=400, body={"error": "Command not implemented"} + ) + elif activity.name == "composeExtension/queryLink": + return await self.handle_query_link(turn_context, activity.value) + return await super().on_invoke_activity(turn_context) + + async def handle_query_link(self, turn_context: TurnContext, query): + """ + Handle unfurling links for messaging extensions. + """ + attachment = CardFactory.thumbnail_card( + title="Thumbnail Card", + images=[query["url"]], + buttons=[ + { + "type": "openUrl", + "title": "View Package", + "value": "https://www.npmjs.com/package/level-option-wrap", + } + ], + ) + result = { + "composeExtension": { + "type": "result", + "attachmentLayout": "list", + "attachments": [attachment], + } + } + return self._create_invoke_response(status=200, body=result) + + + async def create_card_command(self, context: TurnContext, action: dict) -> InvokeResponse: + """ + Create a card in response to the 'createCard' action. + """ + data = action.get("data", {}) + hero_card = HeroCard( + title=data.get("title", ""), + text=data.get("text", ""), + subtitle=data.get("subTitle", "") + ) + + # Create an attachment using CardFactory + attachment = CardFactory.hero_card(hero_card) + + # Serialize the attachment for JSON serialization + serialized_attachment = attachment.serialize() + + result = { + "composeExtension": { + "type": "result", + "attachmentLayout": "list", + "attachments": [serialized_attachment], + } + } + return self._create_invoke_response(status=200, body=result) + + async def share_message_command(self, context: TurnContext, action: dict) -> InvokeResponse: + """ + Share a message in response to the 'shareMessage' action. + """ + user_name = "unknown" + message_payload = action.get("messagePayload", {}) + if "from" in message_payload and "user" in message_payload["from"]: + user_name = message_payload["from"]["user"].get("displayName", user_name) + + images = [] + include_image = action.get("data", {}).get("includeImage", "false") + if include_image == "true": + images = [CardImage(url="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQtB3AwMUeNoq4gUBGe6Ocj8kyh3bXa9ZbV7u1fVKQoyKFHdkqU")] + + # Create the HeroCard + hero_card = HeroCard( + title=f"{user_name} originally sent this message:", + text=message_payload.get("body", {}).get("content", ""), + subtitle=f"({len(message_payload.get('attachments', []))} attachments not included)" + if "attachments" in message_payload + else None, + images=images, + ) + + # Convert HeroCard to an attachment using CardFactory + attachment = CardFactory.hero_card(hero_card) + serialized_attachment = attachment.serialize() + + result = { + "composeExtension": { + "type": "result", + "attachmentLayout": "list", + "attachments": [serialized_attachment], + } + } + + # Return InvokeResponse with the result + return InvokeResponse(status=200, body=result) + + def _create_invoke_response(self, status: int, body: dict) -> InvokeResponse: + """ + Helper to create an InvokeResponse. + """ + return InvokeResponse(status=status, body=body) \ No newline at end of file diff --git a/samples/msgext-action-quickstart/python/config.py b/samples/msgext-action-quickstart/python/config.py new file mode 100644 index 0000000000..7815d9e28d --- /dev/null +++ b/samples/msgext-action-quickstart/python/config.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +import os + +""" Bot Configuration """ + + +class DefaultConfig: + """ Bot Configuration """ + + PORT = 3978 + APP_ID = os.environ.get("MicrosoftAppId", "<>") + APP_PASSWORD = os.environ.get("MicrosoftAppPassword", "<>") + BOT_ENDPOINT = os.environ.get("BaseUrl", "<>") \ No newline at end of file diff --git a/samples/msgext-action-quickstart/python/env/.env.local b/samples/msgext-action-quickstart/python/env/.env.local new file mode 100644 index 0000000000..553698b86a --- /dev/null +++ b/samples/msgext-action-quickstart/python/env/.env.local @@ -0,0 +1,21 @@ +# 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 + +# Generated during provision, you can also add your own variables. If you're adding a secret value, add SECRET_ prefix to the name so Teams Toolkit can handle them properly +BOT_ENDPOINT= +BOT_DOMAIN= +AAD_APP_CLIENT_ID= +AAD_APP_OBJECT_ID= +AAD_APP_TENANT_ID= +AAD_APP_OAUTH_AUTHORITY= +AAD_APP_OAUTH_AUTHORITY_HOST= +TEAMS_APP_ID= +TEAMS_APP_TENANT_ID= +MICROSOFT_APP_TYPE= +MICROSOFT_APP_TENANT_ID= +RESOURCE_SUFFIX= +AZURE_SUBSCRIPTION_ID= +AZURE_RESOURCE_GROUP_NAME= +APP_NAME_SUFFIX=local \ No newline at end of file diff --git a/samples/msgext-action-quickstart/python/infra/azure.bicep b/samples/msgext-action-quickstart/python/infra/azure.bicep new file mode 100644 index 0000000000..8734cb547b --- /dev/null +++ b/samples/msgext-action-quickstart/python/infra/azure.bicep @@ -0,0 +1,42 @@ +@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' + +// 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: 'MultiTenant' + msaAppTenantId: '' + } + 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/msgext-action-quickstart/python/infra/azure.parameters.json b/samples/msgext-action-quickstart/python/infra/azure.parameters.json new file mode 100644 index 0000000000..d20987f841 --- /dev/null +++ b/samples/msgext-action-quickstart/python/infra/azure.parameters.json @@ -0,0 +1,18 @@ +{ + "$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": "msgextactionquickstart" + } + } + } \ No newline at end of file diff --git a/samples/msgext-action-quickstart/python/requirements.txt b/samples/msgext-action-quickstart/python/requirements.txt new file mode 100644 index 0000000000..c44cd874a9 --- /dev/null +++ b/samples/msgext-action-quickstart/python/requirements.txt @@ -0,0 +1,2 @@ +requests==2.31.0 +botbuilder-integration-aiohttp>=4.16.2 diff --git a/samples/msgext-action-quickstart/python/teamsapp.local.yml b/samples/msgext-action-quickstart/python/teamsapp.local.yml new file mode 100644 index 0000000000..c5bc6f549e --- /dev/null +++ b/samples/msgext-action-quickstart/python/teamsapp.local.yml @@ -0,0 +1,78 @@ +# 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:msgext-action-quickstart-python + +provision: + # Creates a new Azure Active Directory (AAD) app to authenticate users if the environment variable that stores clientId is empty + - uses: aadApp/create + with: + name: teamsConversationBot-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: teamsConversationBot${{APP_NAME_SUFFIX}} + # Write the information of created resources into environment file for + # the specified environment variable(s). + writeToEnvironmentFile: + teamsAppId: TEAMS_APP_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 + +deploy: + # Generate runtime environment variables + - uses: file/createOrUpdateEnvironmentFile + with: + target: ./.env + envs: + MicrosoftAppId: ${{AAD_APP_CLIENT_ID}} + MicrosoftAppPassword: ${{SECRET_AAD_APP_CLIENT_SECRET}} \ No newline at end of file diff --git a/samples/msgext-action-quickstart/python/teamsapp.yml b/samples/msgext-action-quickstart/python/teamsapp.yml new file mode 100644 index 0000000000..c00dcf3816 --- /dev/null +++ b/samples/msgext-action-quickstart/python/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:msgext-action-quickstart-python + +environmentFolderPath: ./env \ No newline at end of file