Skip to content

Latest commit

 

History

History
page_type description urlFragment products languages extensions
sample
This sample app demonstrates sending change notifications to user presence in Teams based on user presence status.
officedev-microsoft-teams-samples-graph-change-notification-nodejs
office-teams
office
office-365
nodejs
contentType createdDate
samples
07-07-2021 13:38:26

Change Notification sample using nodejs

Bot Framework v4 ChangeNotification sample.

This sample app demonstrates sending notifications to users when presence status is changed.

Prerequisites

  • Microsoft Teams is installed and you have an account

  • Node.js version 10.14 or higher

    #determine node version
    node --version
  • ngrok or equivalent tunnelling solution

  1. Clone the repository

    git clone https://github.com/OfficeDev/Microsoft-Teams-Samples.git
  2. Open from Visual Studio code

    • Launch Visual Studio code
    • File -> Open Folder
    • Navigate to samples/graph-change-notification/nodejs folder
    • Run npm command in the terminal
      npm install
    • Press F5 to run the project
  3. Run ngrok - point to port 3978

      ngrok http -host-header=rewrite 3978

Instruction on setting connection string for bot authentication on the behalf of user

  1. In the Azure portal, select your resource group from the dashboard.

  2. Select your bot channel registration link.

  3. Open the resource page and select Configuration under Settings.

  4. Select Add OAuth Connection Settings.

    image

  5. Complete the form as follows:

    image

a. Enter a name for the connection. You'll use this name in your bot in the appsettings.json file. For example BotTeamsAuthADv1.

b. Service Provider. Select Azure Active Directory. Once you select this, the Azure AD-specific fields will be displayed.

c. Client id. Enter the Application (client) ID that you recorded for your Azure identity provider app in the steps above.

d. Client secret. Enter the secret that you recorded for your Azure identity provider app in the steps above.

e. Grant Type. Enter authorization_code.

f. Login URL. Enter https://login.microsoftonline.com.

g. Tenant ID, enter the Directory (tenant) ID that you recorded earlier for your Azure identity app or common depending on the supported account type selected when you created the identity provider app. h. For Resource URL, enter https://graph.microsoft.com/ i. Provide Scopes like "Presence.Read, Presence.Read.All" image

Update the appsetting

  1. Update MicrosoftAppId and MicrosoftAppPassword in the .env that is created in Azure.
  2. Add connectionName created in step 5.
  3. Update notificationUrl as {NgrokBaseURL}/api/notifications

Concepts introduced in this sample

  • After sucessfully installation of app you will get a sign in button. When sign in is complete then you get your current status in adapative card image image

  • After that when the user status chagnes you will get notify about their status:

  • Change user status from available to busy like image

  • Change user status from busy to busy offline image

Further reading