Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Journeyman/python msi #1395

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions templates/user-assigned-managed-identity-python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# TeamsFx files
env/.env.*.user
env/.env.local
.localConfigs.testTool
.localConfigs
.notification.localstore.json
.notification.testtoolstore.json
appPackage/build

# dependencies
node_modules/

# misc
.env
.deployment
.DS_Store

# Dev tool directories
/devTools/
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"TeamsDevApp.ms-teams-vscode-extension"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Remote (Edge)",
"type": "msedge",
"request": "launch",
"url": "https://teams.microsoft.com/l/app/${{TEAMS_APP_ID}}?installAppPackage=true&webjoin=true&${account-hint}",
"presentation": {
"group": "3-remote",
"order": 1
},
"internalConsoleOptions": "neverOpen"
},
{
"name": "Launch Remote (Chrome)",
"type": "chrome",
"request": "launch",
"url": "https://teams.microsoft.com/l/app/${{TEAMS_APP_ID}}?installAppPackage=true&webjoin=true&${account-hint}",
"presentation": {
"group": "3-remote",
"order": 2
},
"internalConsoleOptions": "neverOpen"
},
{
"name": "Attach to Local Service",
"type": "node",
"request": "attach",
"port": 9239,
"restart": true,
"presentation": {
"group": "all",
"hidden": true
},
"internalConsoleOptions": "neverOpen"
},
{
"name": "Launch Remote (Desktop)",
"type": "node",
"request": "launch",
"preLaunchTask": "Start Teams App in Desktop Client (Remote)",
"presentation": {
"group": "3-remote",
"order": 3
},
"internalConsoleOptions": "neverOpen",
}
],
"compounds": [
{
"name": "Debug in Test Tool",
"configurations": [
"Attach to Local Service"
],
"preLaunchTask": "Start Teams App (Test Tool)",
"presentation": {
"group": "1-local",
"order": 1
},
"stopAll": true
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"debug.onTaskErrors": "abort",
"json.schemas": [
{
"fileMatch": [
"/aad.*.json"
],
"schema": {}
}
]
}
56 changes: 56 additions & 0 deletions templates/user-assigned-managed-identity-python/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// 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": [
{
// 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"
}
},
{
"label": "Start Teams App in Desktop Client",
"dependsOn": [
"Validate prerequisites",
"Start local tunnel",
"Provision",
"Deploy",
"Start application",
"Start desktop client"
],
"dependsOrder": "sequence"
},
{
"label": "Start desktop client",
"type": "teamsfx",
"command": "launch-desktop-client",
"args": {
"url": "teams.microsoft.com/l/app/${{local:TEAMS_APP_ID}}?installAppPackage=true"
}
},
{
"label": "Start Teams App in Desktop Client (Remote)",
"type": "teamsfx",
"command": "launch-desktop-client",
"args": {
"url": "teams.microsoft.com/l/app/${{TEAMS_APP_ID}}?installAppPackage=true"
}
}
]
}
28 changes: 28 additions & 0 deletions templates/user-assigned-managed-identity-python/.webappignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.webappignore
.fx
.deployment
.localConfigs.testTool
.localConfigs
.notification.localstore.json
.notification.testtoolstore.json
.vscode
*.js.map
*.ts.map
*.ts
.git*
.tsbuildinfo
CHANGELOG.md
readme.md
local.settings.json
test
tsconfig.json
.DS_Store
teamsapp.yml
teamsapp.*.yml
/env/
/node_modules/.bin
/node_modules/ts-node
/node_modules/typescript
/appPackage/
/infra/
/devTools/
75 changes: 75 additions & 0 deletions templates/user-assigned-managed-identity-python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Overview of the EchoBot User Assigned Managed Identity in Python

Bot Framework v4 echo bot sample user assigned managed identity in Python, deployed with Teams Toolkit.

This bot has been created using [Bot Framework](https://dev.botframework.com), it shows how to create a simple bot that accepts input from the user and echoes it back. Follow this link for [User Assigned Managed Identity](https://learn.microsoft.com/en-us/azure/bot-service/provision-and-publish-a-bot?view=azure-bot-service-4.0&tabs=userassigned%2Cpython)

| Property | Value |
| - | - |
| MicrosoftAppType | UserAssignedMSI |
| MicrosoftAppId | The client ID of the user-assigned managed identity. |
| MicrosoftAppPassword | Not applicable. Leave this blank for a user-assigned managed identity bot. |
| MicrosoftAppTenantId | The tenant ID of the user-assigned managed identity. |

> NOTE: User Assigned Managed Identity's eliminate the possibility of testing locally with Teams Toolkit

## Get started with the EchoBot User Assigned Managed Identity template

> **Prerequisites**
>
> To run the template in your local dev machine, you will need:
>
> - [Python](https://www.python.org/), version 3.8 to 3.11.
> - [Python extension](https://code.visualstudio.com/docs/languages/python), version v2024.0.1 or higher.
> - [Teams Toolkit Visual Studio Code Extension](https://aka.ms/teams-toolkit) latest version or [Teams Toolkit CLI](https://aka.ms/teams-toolkit-cli).

1. First, select the Teams Toolkit icon on the left in the VS Code toolbar.
2. Click Provision under Lifecycle
3. Click Deploy under Lifecycle
4. In the environment, tab select dev and click to add to Teams
4. You will receive a welcome message from the bot, and you can send anything to the bot to get an echoed response.

**Congratulations**! You are running an application that can now interact with users in Teams App Test Tool:

![basic bot](https://github.com/OfficeDev/TeamsFx/assets/9698542/bdf87809-7dd7-4926-bff0-4546ada25e4b)

## What's included in the template

| Folder | Contents |
| - | - |
| `.vscode` | VSCode files for debugging |
| `appPackage` | Templates for the Teams application manifest |
| `env` | Environment files |
| `infra` | Templates for provisioning Azure resources |

The following files can be customized and demonstrate an example implementation to get you started.

| File | Contents |
| - | - |
|`app.py`| Hosts an aiohttp api server and exports an app module.|
|`bots/echo_bot.py`| Handles business logics for the Basic AI Chatbot.|
|`config.py`| Defines the environment variables.|
|`requirements.txt`| Defines the packages to install.|

The following are Teams Toolkit specific project files. You can [visit a complete guide on Github](https://github.com/OfficeDev/TeamsFx/wiki/Teams-Toolkit-Visual-Studio-Code-v5-Guide#overview) to understand how Teams Toolkit works.

| File | Contents |
| - | - |
|`teamsapp.yml`|This is the main Teams Toolkit project file. The project file defines two primary things: Properties and configuration Stage definitions. |

## Extend the Basic Bot template

Following documentation will help you to extend the Basic Bot template.

- [Add or manage the environment](https://learn.microsoft.com/microsoftteams/platform/toolkit/teamsfx-multi-env)
- [Create multi-capability app](https://learn.microsoft.com/microsoftteams/platform/toolkit/add-capability)
- [Add single sign on to your app](https://learn.microsoft.com/microsoftteams/platform/toolkit/add-single-sign-on)
- [Access data in Microsoft Graph](https://learn.microsoft.com/microsoftteams/platform/toolkit/teamsfx-sdk#microsoft-graph-scenarios)
- [Use an existing Microsoft Entra application](https://learn.microsoft.com/microsoftteams/platform/toolkit/use-existing-aad-app)
- [Customize the Teams app manifest](https://learn.microsoft.com/microsoftteams/platform/toolkit/teamsfx-preview-and-customize-app-manifest)
- Host your app in Azure by [provision cloud resources](https://learn.microsoft.com/microsoftteams/platform/toolkit/provision) and [deploy the code to cloud](https://learn.microsoft.com/microsoftteams/platform/toolkit/deploy)
- [Collaborate on app development](https://learn.microsoft.com/microsoftteams/platform/toolkit/teamsfx-collaboration)
- [Set up the CI/CD pipeline](https://learn.microsoft.com/microsoftteams/platform/toolkit/use-cicd-template)
- [Publish the app to your organization or the Microsoft Teams app store](https://learn.microsoft.com/microsoftteams/platform/toolkit/publish)
- [Develop with Teams Toolkit CLI](https://aka.ms/teams-toolkit-cli/debug)
- [Preview the app on mobile clients](https://aka.ms/teamsfx-mobile)
74 changes: 74 additions & 0 deletions templates/user-assigned-managed-identity-python/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import sys
import traceback
from datetime import datetime
from http import HTTPStatus

from aiohttp import web
from aiohttp.web import Request, Response, json_response
from botbuilder.core import (
TurnContext,
)
from botbuilder.core.integration import aiohttp_error_middleware
from botbuilder.integration.aiohttp import CloudAdapter, ConfigurationBotFrameworkAuthentication
from botbuilder.schema import Activity, ActivityTypes

from bots import EchoBot
from config import DefaultConfig

CONFIG = DefaultConfig()

# Create adapter.
# See https://aka.ms/about-bot-adapter to learn more about how bots work.
ADAPTER = CloudAdapter(ConfigurationBotFrameworkAuthentication(CONFIG))


# Catch-all for errors.
async def on_error(context: TurnContext, error: Exception):
# This check writes out errors to console log .vs. app insights.
# NOTE: In production environment, you should consider logging this to Azure
# application insights.
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."
)
# Send a trace activity if we're talking to the Bot Framework Emulator
if context.activity.channel_id == "emulator":
# Create a trace activity that contains the error object
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",
)
# Send a trace activity, which will be displayed in Bot Framework Emulator
await context.send_activity(trace_activity)


ADAPTER.on_turn_error = on_error

# Create the Bot
BOT = EchoBot()


# Listen for incoming requests on /api/messages
async def messages(req: Request) -> Response:
return await ADAPTER.process(req, BOT)


APP = web.Application(middlewares=[aiohttp_error_middleware])
APP.router.add_post("/api/messages", messages)

if __name__ == "__main__":
try:
web.run_app(APP, host="localhost", port=CONFIG.PORT)
except Exception as error:
raise error
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading