|
| 1 | +--- |
| 2 | +page_type: sample |
| 3 | +description: This Teams bot enables configuration and reconfiguration with dynamic search capabilities on Adaptive Cards. |
| 4 | +products: |
| 5 | +- office-teams |
| 6 | +- office |
| 7 | +- office-365 |
| 8 | +languages: |
| 9 | +- python |
| 10 | +extensions: |
| 11 | + contentType: samples |
| 12 | + createdDate: "31-12-2024 13:38:25" |
| 13 | +urlFragment: officedev-microsoft-teams-samples-bot-configuration-app-auth-nodejs |
| 14 | +--- |
| 15 | + |
| 16 | +# Create a commands menu |
| 17 | +This sample illustrates bot configuration and reconfiguration in Teams and group chats, showcasing a type-ahead search feature on Adaptive Cards. It supports both static and dynamic search options, enabling a customizable and interactive bot experience for users. |
| 18 | + |
| 19 | +## Included Features |
| 20 | +* Bots |
| 21 | + |
| 22 | +## Interaction with app |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +## Prerequisites |
| 27 | + |
| 28 | +- Microsoft Teams is installed and you have an account |
| 29 | +- [Python SDK](https://www.python.org/downloads/) min version 3.6 |
| 30 | +- [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 |
| 31 | + |
| 32 | + |
| 33 | +## Run the app (Using Teams Toolkit for Visual Studio Code) |
| 34 | + |
| 35 | +The simplest way to run this sample in Teams is to use Teams Toolkit for Visual Studio Code. |
| 36 | + |
| 37 | +1. Ensure you have downloaded and installed [Visual Studio Code](https://code.visualstudio.com/docs/setup/setup-overview) |
| 38 | +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) |
| 39 | +1. Select **File > Open Folder** in VS Code and choose this samples directory from the repo |
| 40 | +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. |
| 41 | +1. Using the extension, sign in with your Microsoft 365 account where you have permissions to upload custom apps |
| 42 | +1. Select **Debug > Start Debugging** or **F5** to run the app in a Teams web client. |
| 43 | +1. In the browser that launches, select the **Add** button to install the app to Teams. |
| 44 | + |
| 45 | +> 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. |
| 46 | +
|
| 47 | +## Run the app (Manually Uploading to Teams) |
| 48 | + |
| 49 | +> Note these instructions are for running the sample on your local machine, the tunnelling solution is required because |
| 50 | +the Teams service needs to call into the bot. |
| 51 | + |
| 52 | +1) Clone the repository |
| 53 | + |
| 54 | + ```bash |
| 55 | + git clone https://github.com/OfficeDev/Microsoft-Teams-Samples.git |
| 56 | + ``` |
| 57 | + |
| 58 | +2) Run ngrok - point to port 3978 |
| 59 | + |
| 60 | + ```bash |
| 61 | + ngrok http 3978 --host-header="localhost:3978" |
| 62 | + ``` |
| 63 | + |
| 64 | + 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: |
| 65 | + |
| 66 | + ```bash |
| 67 | + devtunnel host -p 3978 --allow-anonymous |
| 68 | + ``` |
| 69 | + |
| 70 | +3) Create [Azure Bot resource resource](https://docs.microsoft.com/azure/bot-service/bot-service-quickstart-registration) in Azure |
| 71 | + - Use the current `https` URL you were given by running the tunneling application. Append with the path `/api/messages` used by this sample |
| 72 | + - Ensure that you've [enabled the Teams Channel](https://docs.microsoft.com/azure/bot-service/channel-connect-teams?view=azure-bot-service-4.0) |
| 73 | + - __*If you don't have an Azure account*__ you can use this [Azure free account here](https://azure.microsoft.com/free/) |
| 74 | + |
| 75 | +4) In a terminal, go to `samples\bot-configuration-app-auth` |
| 76 | + |
| 77 | +5) Activate your desired virtual environment |
| 78 | + |
| 79 | +6) Install dependencies by running ```pip install -r requirements.txt``` in the project folder. |
| 80 | + |
| 81 | +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.) |
| 82 | + |
| 83 | +8) __*This step is specific to Teams.*__ |
| 84 | + - **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`) |
| 85 | + - **Zip** up the contents of the `appManifest` folder to create a `manifest.zip` |
| 86 | + - **Upload** the `manifest.zip` to Teams (in the Apps view click "Upload a custom app") |
| 87 | + |
| 88 | +9) Run your bot with `python app.py` |
| 89 | + |
| 90 | +# Running the sample |
| 91 | +You can interact with this bot in Teams by sending it a message, or selecting a command from the command list. The bot will respond to the following strings. |
| 92 | + |
| 93 | + **Configurable Card** |
| 94 | + A configurable card is used to modify data even after the bot has been installed. When the bot is added to a Teams or group chat scope, it utilizes 'config/fetch' and 'config/submit' invoke requests. |
| 95 | + |
| 96 | + - **Result:** The bot will send the configurable adaptive card |
| 97 | + - **Valid Scopes:** group chat, team chat |
| 98 | + |
| 99 | + - **Bot Interactions:** |
| 100 | + |
| 101 | + **Adding bot UI:** |
| 102 | +  |
| 103 | + |
| 104 | + **Added bot UI:** |
| 105 | +  |
| 106 | + |
| 107 | + **Option 1 : Auth card Interactions:** |
| 108 | + - Note: The `Sign-in` page displayed is currently using a dummy URL. Please update it with your authentication URL. |
| 109 | + |
| 110 | +  |
| 111 | + |
| 112 | +## Further reading |
| 113 | + |
| 114 | +- [Bot configuration](https://learn.microsoft.com/microsoftteams/platform/bots/how-to/bot-configuration-experience) |
| 115 | +- [Bot Framework Documentation](https://docs.botframework.com) |
| 116 | +- [Bot Basics](https://docs.microsoft.com/azure/bot-service/bot-builder-basics?view=azure-bot-service-4.0) |
| 117 | +- [Send Notification to User in Chat](https://docs.microsoft.com/graph/api/chat-sendactivitynotification?view=graph-rest-beta) |
| 118 | +- [Send Notification to User in Team](https://docs.microsoft.com/graph/api/team-sendactivitynotification?view=graph-rest-beta&tabs=http) |
| 119 | +- [Send Notification to User](https://docs.microsoft.com/graph/api/userteamwork-sendactivitynotification?view=graph-rest-beta&tabs=http) |
| 120 | + |
| 121 | +<img src="https://pnptelemetry.azurewebsites.net/microsoft-teams-samples/samples/bot-configuration-app-auth-python" /> |
0 commit comments