| page_type | sample | ||||
|---|---|---|---|---|---|
| description | This sample illustrates how you can use Proactive installation of app for user and send proactive notification by calling Microsoft Graph APIs. | ||||
| products |
|
||||
| languages |
|
||||
| extensions |
|
||||
| urlFragment | officedev-microsoft-teams-samples-graph-proactive-installation-nodejs |
This sample app illustrates the proactive installation of app using Graph API and sending proactive notification to users from GroupChat or Channel.
-
Microsoft Teams is installed and you have an account
-
NodeJS version 10.14 or higher
# determine node version node --version -
ngrok or equivalent tunnelling solution
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/adminconsent?client_id=<%appId%>
- 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
httpsURL you have given by running ngrok. Append with the path/api/messages
- Run ngrok - point to port 3978
# ngrok http -host-header=rewrite 3978Note 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
-
In a terminal, navigate to
samples/javascript_nodejs/graph-proactive-installationcd samples/graph-proactive-installation/nodejs -
Install modules
npm install
-
Go to .env file and add
MicrosoftAppId,MicrosoftAppPasswordandAppCatalogTeamAppIdinformation.- To get
AppCatalogTeamAppIdnavigate to following link in your browser Get TeamsAppCatalogId from Microsoft Graph explorer. And then search with app name or based on Manifest App id in Graph Explorer response and copy theId[i.e teamApp.Id]
- To get
-
Run your bot at the command line
npm start
- **Edit** the `manifest.json` contained in the `TeamsAppManifest` folder to replace your Microsoft App Id (that was created when you registered your bot earlier) *everywhere* you see the place holder string `<<YOUR-MICROSOFT-APP-ID>>` (depending on the scenario the Microsoft App Id may occur multiple times in the `manifest.json`)
- **Zip** up the contents of the `TeamsAppManifest` 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 team/groupChat scope (Supported scopes)
-
Install the Proactive App Installation demo app in a Team or GroupChat.
-
Team Scope: Run 'Check and Install' to pro-actively install the App for all the users in team. After installation send 'Send message' command to send proactive message.
-
Group Chat: Run 'Check and Install' to pro-actively install the App for all the users in team. After installation send 'Send message' command to send proactive message.
To learn more about deploying a bot to Azure, see Deploy your bot to Azure for a complete list of deployment instructions.
