-
Notifications
You must be signed in to change notification settings - Fork 809
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
Converted Sample MsgExt Search QuickStart To Python #1497
Open
Mohammed-MSFT
wants to merge
2
commits into
main
Choose a base branch
from
v-mfurquan/msgext-search-quickstart-python-conv
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# TeamsFx files | ||
env/.env.*.user | ||
env/.env.local | ||
appManifest/build/ | ||
|
||
# python virtual environment | ||
.venv/ | ||
|
||
# misc | ||
.env | ||
.deployment/ | ||
|
||
# tmp files | ||
__pycache__/ |
6 changes: 6 additions & 0 deletions
6
samples/msgext-search-quickstart/python/.vscode/extensions.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"recommendations": [ | ||
"TeamsDevApp.ms-teams-vscode-extension", | ||
"ms-python.python", | ||
] | ||
} |
69 changes: 69 additions & 0 deletions
69
samples/msgext-search-quickstart/python/.vscode/launch.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
] | ||
} |
3 changes: 3 additions & 0 deletions
3
samples/msgext-search-quickstart/python/.vscode/settings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"debug.onTaskErrors": "abort" | ||
} |
78 changes: 78 additions & 0 deletions
78
samples/msgext-search-quickstart/python/.vscode/tasks.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} | ||
] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+186 KB
samples/msgext-search-quickstart/python/Images/3.Search_Query_With_Results.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+140 KB
samples/msgext-search-quickstart/python/Images/4.Selected_Result_Card.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+703 KB
samples/msgext-search-quickstart/python/Images/msgextsearchquickstart.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
--- | ||
page_type: sample | ||
description: This sample demonstrates a simple python-based Messaging Extension that accepts search requests and returns results within Microsoft Teams. | ||
products: | ||
- office-teams | ||
- office | ||
- office-365 | ||
languages: | ||
- python | ||
extensions: | ||
contentType: samples | ||
createdDate: "26/12/2024 01:38:27 PM" | ||
urlFragment: officedev-microsoft-teams-samples-msgext-search-quickstart-python | ||
--- | ||
|
||
# Messaging Extension quick start | ||
|
||
This comprehensive python quick start sample illustrates the creation of a Messaging Extension in Microsoft Teams designed to process search requests from users. By enabling interactions through buttons and forms, it facilitates direct communication with your web service, enhancing user experience within the Teams environment. | ||
|
||
*Messaging extensions* allow users to interact with your web service through buttons and forms in the Microsoft Teams client. They can search, or initiate actions, in an external system from the compose message area, the command box, or directly from a message. | ||
|
||
## Included Features | ||
* Bots | ||
* Message Extensions | ||
* Search Commands | ||
|
||
## Interaction with app | ||
|
||
![Sample Module](Images/msgextsearchquickstart.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)). | ||
|
||
**Messaging Extension quick start:** [Manifest](/samples/msgext-search-quickstart/js/demo-manifest/msgext-search-quickstart.zip) | ||
|
||
## Prerequisites | ||
|
||
**Dependencies** | ||
- 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. | ||
|
||
## Setup | ||
|
||
1. Register a new application in the [Microsoft Entra ID – App Registrations](https://go.microsoft.com/fwlink/?linkid=2083908) portal. | ||
|
||
2. Azure Bot [Azure Bot] (https://learn.microsoft.com/azure/bot-service/abs-quickstart?view=azure-bot-service-4.0&tabs=userassigned) | ||
|
||
- For the Messaging endpoint URL, use the current `https` URL you were given by running the tunnelling application and append it with the path `/api/messages`. It should like something work `https://{subdomain}.ngrok-free.app/api/messages`. | ||
|
||
- Click on the `Bots` menu item from the toolkit and select the bot you are using for this project. Update the messaging endpoint and press enter to save the value in the Bot Framework. | ||
|
||
- Ensure that you've [enabled the Teams Channel](https://docs.microsoft.com/azure/bot-service/channel-connect-teams?view=azure-bot-service-4.0) | ||
|
||
3. Setup NGROK | ||
- 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 | ||
``` | ||
|
||
4. Setup for code | ||
- Clone the repository | ||
|
||
```bash | ||
git clone https://github.com/OfficeDev/Microsoft-Teams-Samples.git | ||
``` | ||
|
||
- In a terminal, navigate to `samples/msgext-search-quickstart/python` | ||
|
||
- Activate your desired virtual environment | ||
|
||
- Install dependencies by running ```pip install -r requirements.txt``` in the project folder. | ||
|
||
- 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.) | ||
|
||
- Run your bot with `python app.py` | ||
|
||
5) __*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") | ||
|
||
- Upload the manifest.zip to Teams (in the Apps view click "Upload a custom app") | ||
- Go to Microsoft Teams. From the lower left corner, select Apps | ||
- From the lower left corner, choose Upload a custom App | ||
- Go to your project directory, the ./appManifest folder, select the zip folder, and choose Open. | ||
- Select Add in the pop-up dialog box. Your app is uploaded to Teams. | ||
|
||
## Running the sample | ||
|
||
![MsgExt Search](Images/1.Install_App.png) | ||
|
||
![MsgExt Search](Images/2.Select_App.png) | ||
|
||
![MsgExt Search](Images/3.Search_Query_With_Results.png) | ||
|
||
![MsgExt Search](Images/4.Selected_Result_Card.png) | ||
|
||
![MsgExt Search](Images/5.Compose_Card.png) | ||
|
||
![MsgExt Search](Images/6.Search_Results_2.png) | ||
|
||
![MsgExt Search](Images/7.Outlook_App.png) | ||
|
||
|
||
## Further reading | ||
|
||
- [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) | ||
- [Search based messaging extension](https://learn.microsoft.com/microsoftteams/platform/messaging-extensions/how-to/search-commands/define-search-command) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The date format should be in the format "YYYY-MM-DD".
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We were using this format 26/12/2024 01:38:27 PM in all samples in our repo.