Proactive Installation Sample App
This sample application illustrates how to implement proactive installation of a Microsoft Teams app and send notifications using Microsoft Graph APIs. Featuring bot integration, this app allows for user interaction within Group Chats and Channels, enhancing communication and app management in Teams.
Included Features
- Bots
Interaction with bot
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. (Uploading must be enabled for your tenant, see steps here).
Proactive Installation Sample App: Manifest
Prerequisites
- Microsoft Teams is installed and you have an account
- Python SDK min version 3.8
- dev tunnel or ngrok latest version or equivalent tunnelling solution
- Microsoft 365 Agents Toolkit for VS Code or TeamsFx CLI
Run the app (Using Microsoft 365 Agents Toolkit for Visual Studio Code)
The simplest way to run this sample in Teams is to use Microsoft 365 Agents Toolkit for Visual Studio Code.
- Ensure you have downloaded and installed Visual Studio Code
- Install the Microsoft 365 Agents Toolkit extension and Python Extension
- Select File > Open Folder in VS Code and choose this samples directory from the repo
- 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. - Using the extension, sign in with your Microsoft 365 account where you have permissions to upload custom apps
- Select Debug > Start Debugging or F5 to run the app in a Teams web client.
- 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 (uploading), Microsoft 365 Agents 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.
Register Azure AD application
Register one Azure AD application in your tenant's directory for the bot and tab app authentication.
Log in to the Azure portal from your subscription, and go to the "App registrations" blade here. Ensure that you use a tenant where admin consent for API permissions can be provided.
Click on "New registration", and create an Azure AD application.
Name: The name of your Teams app - if you are following the template for a default deployment, we recommend "App catalog lifecycle".
Supported account types: Select "Accounts in any organizational directory"
Leave the "Redirect URL" field blank.
Click on the "Register" button.
When the app is registered, you'll be taken to the app's "Overview" page. Copy the Application (client) ID; we will need it later. Verify that the "Supported account types" is set to Multiple organizations.
On the side rail in the Manage section, navigate to the "Certificates & secrets" section. In the Client secrets section, click on "+ New client secret". Add a description for the secret and select Expires as "Never". Click "Add".
Once the client secret is created, copy its Value, please take a note of the secret as it will be required later.
At this point you have 3 unique values:
- Application (client) ID which will be later used during Azure bot creation
- Client secret for the bot which will be later used during Azure bot creation
- Directory (tenant) ID
We recommend that you copy these values into a text file, using an application like Notepad. We will need these values later.
- Under left menu, navigate to API Permissions, and make sure to add the following permissions of Microsoft Graph API > Application permissions:
- TeamsAppInstallation.ReadWriteForUser.All
Click on Add Permissions to commit your changes.
If you are logged in as the Global Administrator, click on the "Grant admin consent for <%tenant-name%>" button to grant admin consent else, inform your admin to do the same through the portal or follow the steps provided here to create a link and send it to your admin for consent.
Global Administrator can grant consent using following link: https://login.microsoftonline.com/common/ n b?client_id=<%appId%>
Setup Bot Service
- In Azure portal, create a Azure Bot resource
- Select Type of App as "Multi Tenant"
- Select Creation type as "Use existing app registration"
- Use the copied App Id and Client secret from above step and fill in App Id and App secret respectively.
- Click on 'Create' on the Azure bot.
- Go to the created resource, ensure that you've enabled the Teams Channel
- In Settings/Configuration/Messaging endpoint, enter the current
https
URL you have given by running the tunnelling application. Append with the path/api/messages
Run the app (Manually Uploading to Teams)
Setup for code
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.
Clone the repository
git clone https://github.com/OfficeDev/Microsoft-Teams-Samples.git
Run ngrok - point to port 3978
ngrok http 3978 --host-header="localhost:3978"
Alternatively, you can also use the
dev tunnels
. Please follow Create and host a dev tunnel and host the tunnel with anonymous user access command as shown below:devtunnel host -p 3978 --allow-anonymous
In a terminal, navigate to
samples/graph-proactive-installation/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.)This step is specific to Teams.
- Edit the
manifest.json
contained in theappManifest
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 themanifest.json
) - Update the placeholder
{{BOT_DOMAIN}}
with devtunnel or ngrok. - Zip up the contents of the
appManifest
folder to create amanifest.zip
- Upload the
manifest.zip
to Teams (in the Apps view click "Upload a custom app")
- Edit the
Run your bot with
python app.py
Running the sample
- App Installation:
- Personal Scope Interactions:
- Group Chat Scope Interactions:
- Team Scope Interactions:
Deploy the bot to Azure
To learn more about deploying a bot to Azure, see Deploy your bot to Azure for a complete list of deployment instructions.
Further reading
- Bot Framework Documentation
- Bot Basics
- Azure Bot Service Introduction
- Azure Bot Service Documentation
- Teams Message Reaction Events